Previously, irregularities involved the call of API and a lot of programming, not anyone. Many programmers are looking forward.
Now we can use C # .NET to easily create an irregular form. Below I use a simple example to tell the production process.
1. Draw an irregular form bitmap 2. Set the basic property of the form 3. Write the form related code (to implement the window's shutdown, mobile, etc.) 1. Draw an irregular form bitmap, you can use any one you like Matter tool, making a shaped bitmap, background uses a different color. This color is used in programming, so it is best to use a color that is easy to remember. As shown below, the background color used in this example is yellow (# fff00 / yellow), the file name is bk.bmp
2. Create a Windows Form and Set Form Basic Properties 1> New Windows Application
2> Select a newly created form and set its corresponding attribute: (1). Set the FormBorderstyle property to None. (2). Set the form's BackgroundImage property to a previously created bitmap file. You do not have to add files to the project system; this will be automatically completed when specifying the file as a background image. (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 transparent.) At this point you can press F5 to test your program, you can see the form as shown. Now the form cannot be dragged, only by ending the program, or Alt F4 close. Below we write the corresponding code to implement the corresponding functions of the title bar.
3. Write the form related code (to implement the window to close, move, etc.) (1). Implementing the window closing from the toolbar to a button, set its button text to "×", set the size of its size. Double-click this button to enter its trigger time function. Write as follows: this.close (); // Close this form
(2). Set the mobile operation of the form, we have to use two global variables private point mouseoffset; // Record the coordinate of the mouse pointer private bool ismousedown = false; // Record whether the mouse button is pressed
Create a corresponding handler for the form mousedown event. Private void form1_mousedown (object sender, system.windows 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, yOffset); isMouseDown = true;}} corresponding MouseMove event handler creates the form of private void Form1_MouseMove (object sender, System.Windows.Forms.MouseEventArgs e) {if (isMouseDown) {Point mousePos = Control.MousePosition; mousePos.Offset (mouseOffset. X, mouseoffset.y); location = mousepos;}} Create the corresponding handler P for the MouseUp event of the form Rivate void form1_mouseup (object sender, system.windows e) {// Modify the value of the mouse status ismousedown // Make sure that only the left mouse button is pressed and moved, only the form IF (E.Button == Mousebuttons {Ismousedown = false;}}
(3). Adding other other controls is to see your own needs, to add controls to implement the features you want to implement. In this example, a text box is added, and its background is yellow, so it is also transparent. Now, we can generate a program and look at the last effect.