您的位置:首页 > 编程语言 > C#

c#之圆形无标题栏椭圆窗体的实现详解

2013-06-08 15:28 906 查看

步骤如下:

1.新建窗体,并隐藏标题栏。

2.导入图片为窗体BackgroundImage。适当将BackgroundImageLayout属性设置为Strech.

3.导入命名空间以便可以绘制二维图形:


using System.Drawing.Drawing2D;

4.为窗体加载事件添加如下代码:

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Left = (SystemInformation.PrimaryMonitorMaximizedWindowSize.Width - this.Width) / 2;
            this.Top = (SystemInformation.PrimaryMonitorMaximizedWindowSize.Height - this.Height) / 2;
        }

5.同时为Paint事件添加如下代码:

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            GraphicsPath Myformpath = new GraphicsPath();
            Myformpath.AddEllipse(0,0,this.Width-30,this.Height-30);
            this.Region = new Region(Myformpath);
        }

6.最后为窗体的DoubleClick事件添加如下代码,以便双击可以退出程序:

        private void Form1_DoubleClick(object sender, EventArgs e)
        {
            Application.Exit();
        }

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息