2012年2月29日星期三

建立字体形状窗体

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 FontForm
11 {
12 public partial class Frm_Main : Form
13 {
14 Bitmap bit;//声明位图对象
15 public Frm_Main()
16 {
17 InitializeComponent();
18 }
19
20 private void Form1_Load(object sender, EventArgs e)
21 {
22 bit = new Bitmap("font.jpg");//从指定的图像初始化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 FontForm
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(261, 56);
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 // Form1
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(346, 204);
49 this.Controls.Add(this.label1);
50 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
51 this.Name = "Form1";
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 }

作者:王雄飞(当冬夜渐暖)
出处:http://www.cnblogs.com/ynbt/
关于作者:专注于.Net、Windows Phone 7和移动互联网开发。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过ynbt_wang@163.com联系我,非常感谢。 。
建立字体形状窗体

TAG: