Create a non-rectangular form

Source: Internet
Author: User
Tags transparent color

Frm_main.cs

View code

 1   Using System;
2 Using System. Collections. Generic;
3 Using System. componentmodel;
4 Using System. Data;
5 Using System. drawing;
6 Using System. text;
7 Using System. Windows. forms;
8 Using System. runtime. interopservices;
9
10 Namespace Rectangleform
11 {
12 Public Partial Class Frm_main: Form
13 {
14 Bitmap bit; // Declare a Bitmap bitmap object
15 Public Frm_main ()
16 {
17 Initializecomponent ();
18 }
19
20 Private Void Form1_load ( Object Sender, eventargs E)
21 {
22 Bit = New Bitmap ( " Bccd.png " ); // Initializes a bitmap object from a specified image.
23 Bit. maketransparent (color. Blue );// Use the default transparent color to make the Bitmap bitmap transparent
24 }
25 Protected Override Void Onpaint (painteventargs E)
26 {
27 E. Graphics. drawimage (image) bit, New Point ( 0 , 0 ));// Draw an image on a form
28 }
29
30 Private Void Labelease click ( Object Sender, eventargs E)
31 {
32 This . Close (); // Close form
33 }
34 }
35 }

Frm_main.designer.cs

View code

 1   Namespace Rectangleform
2 {
3 Partial Class Frm_main
4 {
5 /// <Summary>
6 /// Required designer variables.
7 /// </Summary>
8 Private System. componentmodel. icontainer components = Null ;
9
10 /// <Summary>
11 /// Clear all resources in use.
12 /// </Summary>
13 /// <Param name = "disposing"> If the managed resources should be released, the value is true; otherwise, the value is false. </Param>
14 Protected Override Void Dispose ( Bool Disposing)
15 {
16 If (Disposing & (components! = Null ))
17 {
18 Components. Dispose ();
19 }
20 Base . Dispose (disposing );
21 }
22
23 # Region The Code
24
25 /// <Summary>
26 /// Required methods supported by the designer-do not
27 /// Use the code editor to modify the content of this method.
28 /// </Summary>
29 Private Void Initializecomponent ()
30 {
31 This . Label1 =New System. Windows. Forms. Label ();
32 This . Suspendlayout ();
33 //
34 // Label1
35 //
36 This . Label1.backcolor = system. Drawing. color. transparent;
37 This . Label1.location = New System. Drawing. Point ( 280 , 42 );
38 This . Label1.name = " Label1 " ;
39 This . Label1.size = New System. Drawing. Size (17 , 16 );
40 This . Label1.tabindex = 0 ;
41 This . Label1.click + = New System. eventhandler ( This . Labelease click );
42 //
43 // Frm_main
44 //
45 This . Autoscaledimensions = New System. Drawing. sizef (6f, 12f );
46 This . Autoscalemode = system. Windows. Forms. autoscalemode. Font;
47 This . Backcolor = system. Drawing. systemcolors. Control;
48 This . Clientsize = New System. Drawing. Size ( 300 , 300 );
49 This . Controls. Add ( This . Label1 );
50 This . Formborderstyle = system. Windows. Forms. formborderstyle. None;
51 This . Name = " Frm_main " ;
52 This . Startposition = system. Windows. Forms. formstartposition. centerscreen;
53 This . Text = " Create a non-rectangular form " ;
54 This . Transparencykey = system. Drawing. systemcolors. Control;
55 This . Load + =New System. eventhandler ( This . Form1_load );
56 This . Resumelayout ( False );
57
58 }
59
60 # Endregion
61
62 Private System. Windows. Forms. Label label1;
63
64 }
65 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.