Making irregular forms with Borland C # Builder

zhaozj2021-02-08  228

Xu Changyou travels online as an irregular form involves an API call and a lot of programming, it is a very complicated thing. Below we can use Borland C # Builder to easily implement an irregular form, with an example to describe its production process below. I. Prepare an irregular form bit Figure 2. The setting of the form is 3. The completion of the code. Prepare an irregular form bitmap For convenience, we will find a few other Skin. Here, Skins / Ocean / KingDVD_Disable.bmp under the installation directory of Jinshan Pilot 2003 is of course you can use the drawing tool, making a shape-shaped bitmap, a special color, such as white. This color will be used later.

[Related map]

II. Setting of the form 1. New C # Application

[Related map]

2. Check the new form to set its corresponding attribute: (1). Set the FormBorderstyle property to None. (2). Set the form's BackgroundImage property to the first bitmap file. (3). Set the TRANSPARENCYKEY attribute to the background color of the bitmap file, in this case. (This property tells which parts in the application form need to be set to transparency.) (4). Add a PictureBox1, just turn off the bitmap and turn off the application when clicking. (5). Add a contextMenu1 to add a menu item "Exit", set the winform's ContextMenu to ContextMenu1. Press F9 to run your program, you can see your irregular form.

[Related map]

3. The window that does not move before the code is completed.

Add the following code to move it, post the complete sample code: use system; using system.drawing; use system.collections; using system.componentmodel; using system.windows.forms; using system.data; namespace sform { ///

/// summary description for winform. /// public class winform: system.windows.Forms.form {/// /// Required Designer variable. /// < / summary> private System.ComponentModel.Container components = null; private System.Windows.Forms.ContextMenu contextMenu1; private System.Windows.Forms.MenuItem menuItem1; private Point mouseOffset; // record the coordinates of the mouse pointer private bool isMouseDown = false; private System.Windows.Forms.PictureBox pictureBox1; // record mouse button is pressed or public WinForm () {// // Required for Windows Form Designer support // InitializeComponent (); // // TODO: Add any constructor code after InitializeComponent Call ///} /// /// clean up any resources being used. /// protected Override Void Dispose (Bool Disposing) {if (disposing) { IF (Components! = null) {Components.dispose ();}} Base.dispose (4);} #region windows form designer generated code /// /// Required Method for Designer Support - Do Not Modify / // the contents of this method with the code editor /// private void InitializeComponent () {System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof (WinForm));. this.contextMenu1 = new System.windows.forms.contextMenu (); this.Menuitem1 = new system.windows.forms.MenuItem (); this.picturebox1 = new system.windows.forms.picturebox (); this.suspendlayout ();

// // contextMenu1 // this.contextMenu1.Menuitems.addrange (new system.windows.Forms.Menuitem [] {this.Menuitem1}); // // Menuitem1 // this.Menuitem1.index = 0; this.Menuitem1 .Text = "Exit"; this.Menuitem1.click = new system.EventHandler (this.Menuitem1_click); // // PictureBox1 // this.PictureBox1.image = ((System.drawing.Image) (Resources.GetObject "pictureBox1.Image"))); this.pictureBox1.Location = new System.Drawing.Point (290, 8); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size ( 14, 13); this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; this.pictureBox1.Click = new System.EventHandler (this .pictureBox1_Click); // // WinForm // this.AutoScaleBaseSize = new System.Drawing.Size (6, 14); this.BackgroundImage = ((System.Drawing.Image) (resources.GetObject ( "$ this.BackgroundImage" )))))); This.clientsize = new System.Drawing.Size (365, 235); this.ContextMenu = this.contextMenu1; this.Controls.Add (this.pictureBox1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.MaximizeBox = false ; this.MinimizeBox = false; this.Name = "WinForm"; this.Text = "WinForm"; this.TransparencyKey = System.Drawing.Color.White; this.MouseDown = new System.Windows.Forms.MouseEventHandler (this .Winform_mousedown; this.mouseup = new system.windows.Forms.MouseEventHandler (this.mousemove =

New system.windows.Forms.MouseEventHandler (this.winform_mousemove); this.ResumeLayout (false);} #endregion ///

//// [stathread ] static void Main () {Application.Run (new WinForm ());} private void menuItem1_Click (object sender, System.EventArgs e) {this.Close ();} private void WinForm_MouseMove (object sender, System.Windows.Forms .MouseEventArgs e) {if (isMouseDown) {Point mousePos = Control.MousePosition; mousePos.Offset (mouseOffset.X, mouseOffset.Y); Location = mousePos;}} private void WinForm_MouseDown (object sender, System.Windows.Forms.MouseEventArgs e) {int xOffset; int yOffset; if (e.Button == MouseButtons.Left) {xOffset = -eX - SystemInformation.FrameBorderSize.Width; yOffset = -eY - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height; mouseOffset = new Point (Xoffset, Y Offset; ismousdown = true;}}} private message IF (E.Button == MouseButtons.Left) {ismousedown = false;}} private void picturebox1_click (object sender, system.eventargs e) {this.close ();}}} Note: If the color depth setting of the monitor More than 24 digits, TransparencyKey is set to white, and the non-transparent part of the form will still be displayed, do not know why. Interested friends exchange, home page: http://yousoft.hi.com.cn

转载请注明原文地址:https://www.9cbs.com/read-2717.html

New Post(0)