C如何绘制不规则窗体.doc
文本预览下载声明
1 新建windows应用程序
2 选中新建的窗体,设置其相应属性: (1)。将 FormBorderStyle 属性设置为 None。 (2)。将窗体的 BackgroundImage 属性设置为先前创建的位图文件。不必将文件添加到项目系统中;这将在指定该文件作为背景图像时自动完成。 (3)。将 TransparencyKey 属性设置为位图文件的背景色,本例中为黄色。(此属性告诉应用程序窗体中的哪些部分需要设置为透明。 ) 这时你就可以按F5测试你的程序,可以看到如图所示的窗体。现在窗体还不能拖动,只能通过结束程序,或者alt+F4关闭。下面我们编写相应的代码来实现标题栏的相应功能。 3.编写窗体相关代码 (要实现窗口的关闭,移动等操作) (1)。实现窗口关闭 从工具栏中拖进一个按钮,设置其按钮文字为“×”,设置其大小为合适大小。双击该按钮进入其触发时间函数。 写入如下代码: this.Close ; //关闭本窗体 (2)。设置窗体的移动操作,我们要用到两个全局的变量 private Point mouseOffset; //记录鼠标指针的坐标 private bool isMouseDown false; //记录鼠标按键是否按下 创建该窗体 MouseDown事件的相应处理程序。 private void Form1_MouseDown object sender, System.Windows.Forms.MouseEventArgs e int xOffset; int yOffset; if e.Button MouseButtons.Left xOffset -e.X - SystemInformation.FrameBorderSize.Width; yOffset -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height; mouseOffset new Point xOffset, yOffset ; isMouseDown true; 创建该窗体的 MouseMove事件的相应处理程序 private void Form1_MouseMove object sender, System.Windows.Forms.MouseEventArgs e if isMouseDown Point mousePos Control.MousePosition; mousePos.Offset mouseOffset.X, mouseOffset.Y ; Location mousePos; 创建该窗体的MouseUp事件的相应处理程序 private void Form1_MouseUp object sender, System.Windows.Forms.MouseEventArgs e // 修改鼠标状态isMouseDown的值 // 确保只有鼠标左键按下并移动时,才移动窗体 if e.Button MouseButtons.Left isMouseDown false; (3)。加入相应的其他的控件 其他的就是看你自己的需要,来添加控件,实现自己想要实现的功能。本例中添加了一文本框,设置其背景为黄色,所以显示时也成了透明的。别忘了把事件绑定到窗体 !!! 现在,我们就可以生成程序,看一下最后的效果了。
回答者: 再世神隆 - 六级?? 2009-5-30 16:55
private void Form1_Load object sender, EventArgs e GraphicsPath FormPath new GraphicsPath ;
FormPath.AddLine 5, 230, 5, 200 ;
FormPath.AddLine 5, 200, 95, 200 ;
FormPath.AddLine 95, 200, 95, 30 ;
FormPath.AddLine 95, 30, 250, 30 ;
FormPath.AddLine 250, 30, 250, 200 ;
FormPath.AddLine 250, 200, 340, 200 ;
FormPath.AddLine 340, 200, 340, 230 ;
FormPath.AddLine 340, 230, 5, 230 ;
//闭合当前图形并开始新的图形
FormPath.CloseFigure ;
this.Region new Region FormPath ; 画圆角一样的
用这个FormPath.AddArc(
显示全部