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 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"); // initialize the Bitmap object from the specified Image
23 bit. MakeTransparent (Color. Blue); // use the default transparent Color to make the 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 the form
28}
29
30 private void label1_Click (object sender, EventArgs e)
31 {
32 this. Close (); // Close the 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"> true if managed resources should be released; otherwise, 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 code generated by Windows Form Designer
24
25 /// <summary>
26 // The designer supports the required methods-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. label1_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 = "Creating 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}

 

From Mo Mingqi Miao

Related Article

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.