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 }
摘自 墨明棋妙