欢迎来到天天文库
浏览记录
ID:44819047
大小:148.00 KB
页数:27页
时间:2019-10-30
《清华大学C#教程》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、目录第1篇基础窗体开发篇第1章窗体设置(教学视频:55分钟)21.1常规窗体设置2实例001控制窗体大小2this.MaximumSize=newSize(width,height);实例002最前端显示窗体3this.topmost=true;实例003设置窗体相对起始位置3Form1form=newForm1();form.Location=newPoint(400,200);form.StartPosition=FormStartPosition.Manual;location只有当startposition为manual时才起作用实例004设置窗体透明度4Opacity=x
2、x%;实例005设置窗体颜色5This.BackColor=Color.BlueViolet;或者直接设置颜色代码;This.BackColor=Color.FromArgb(255,34,234);实例006在多窗体间移动控件6窗体中添加控件this.Control.Add(this.label1);label1.text=””;实例007右对齐窗体标题文字7RighttoLeft=true;实例008改变无边框窗体大小7ControlText=false;实例009移动无边框窗体8boolbeginMove=false;//初?始º?化¡¥intcurrentXPosition
3、;intcurrentYPosition;//鼠º¨®标À¨º移°?动¡¥事º?件tprivatevoidForm1_MouseMove(objectsender,MouseEventArgse){if(beginMove){this.Left+=MousePosition.X-currentXPosition;//根¨´据Y鼠º¨®标À¨ºx坐Á?标À¨º确¨¡¤定¡§窗ä¡ã体¬?的Ì?左Á¨®边À?坐Á?标À¨ºxthis.Top+=MousePosition.Y-currentYPosition;//根¨´据Y鼠º¨®标À¨º的Ì?y坐Á?标À¨º窗ä¡ã体¬?的Ì?顶£¤
4、部?,ê?即¡äY坐Á?标À¨ºcurrentXPosition=MousePosition.X;currentYPosition=MousePosition.Y;}}privatevoidForm1_MouseDown(objectsender,MouseEventArgse){beginMove=true;currentXPosition=MousePosition.X;//鼠º¨®标À¨º的Ì?x坐Á?标À¨º为a当Ì¡À前¡ã窗ä¡ã体¬?左Á¨®上¦?角?x坐Á?标À¨ºcurrentYPosition=MousePosition.Y;//鼠º¨®标À¨º的Ì?y坐Á?标
5、À¨º为a当Ì¡À前¡ã窗ä¡ã体¬?左Á¨®上¦?角?y坐Á?标À¨º}privatevoidForm1_MouseUp(objectsender,MouseEventArgse){beginMove=false;//停ª¡ê止1移°?动¡¥}privatevoidForm1_MouseLeave(objectsender,EventArgse){currentXPosition=0;//设¦¨¨置?初?始º?状Á¡ä态¬?currentYPosition=0;beginMove=false;}实例010禁止关闭窗体9在主e.Cancel=true;实例011通过控件拖动窗体10
6、privatevoidbutton1_MouseDown(objectsender,MouseEventArgse){if(e.Button==MouseButtons.Left)//如¨?果?事º?件t是º?由®¨¦鼠º¨®标À¨º左Á¨®键¨¹激¡è发¤¡é;ê?button1.leftbutton1距¨¤离¤?容¨Y器¡Â的Ì?左Á¨®边À?距¨¤离¤?{startX=e.X;startY=e.Y;}}privatevoidbutton1_MouseMove(objectsender,MouseEventArgse){if(e.Button==MouseButtons.Lef
7、t){this.Left+=e.X-startX;this.Top+=e.Y-startY;}}实例012根据窗体自动调整控件111.2特殊窗体设置13实例013设计不规则窗体13this.TransparencyKey=Color.Yellow实例014设计带分隔栏的窗体14Splitcontainer;实例015在窗体中滚动字幕14添加timer组件增加timer的tick事件实例016设计闪烁的窗体15实例017设计动画显示窗体16实例018设计运动的窗体18添
此文档下载收益归作者所有