创建非矩形窗体
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;//声明一个Bitmap位图对象
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");//从指定的图像初始化Bitmap对象
23 bit.MakeTransparent(Color.Blue);//使用默认的透明颜色对Bitmap位图透明
24 }
25 protected override void OnPaint(PaintEventArgs e)
26 {
27 e.Graphics.DrawImage((Image)bit, new Point(0, 0));//在窗体上绘制图片
28 }
29
30 private void label1_Click(object sender, EventArgs e)
31 {
32 this.Close();//关闭窗体
33 }
34 }
35 }
Frm_Main.designer.cs
View Code
1 namespace RectangleForm
2 {
3 partial class Frm_Main
4 {
5 /// <summary>
6 /// 必需的设计器变量。
7 /// </summary>
8 private System.ComponentModel.IContainer components = null;
9
10 /// <summary>
11 /// 清理所有正在使用的资源。
12 /// </summary>
13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 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 Windows 窗体设计器生成的代码
24
25 /// <summary>
26 /// 设计器支持所需的方法 - 不要
27 /// 使用代码编辑器修改此方法的内容。
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 = "创建非矩形窗体";
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 }
摘自 墨明棋妙
补充:软件开发 , C# ,