欢迎来到天天文库
浏览记录
ID:35938285
大小:779.72 KB
页数:47页
时间:2019-04-26
《c#winform练习》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、实用文案//1.添加两个按钮一个文本框如下图:当用户点击爱时弹出“我也爱你哟”,点击不爱时弹出“还是被你给点到了”并退出程序usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceLove_and_notLove{pu
2、blicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidLovebtn_Click(objectsender,EventArgse){MessageBox.Show("我也爱你哟!");this.Close();}//触发点击事件privatevoidNotLovebtn_Click(objectsender,EventArgse){MessageBox.Show("还是被你给点到了");//关闭主程序this.Clo
3、se();}//针对鼠标移动至按钮所属区域时触发事件privatevoidNotLovebtn_MouseEnter(objectsender,EventArgse){//声明一个变量用于存放按钮的X轴坐标intx=this.ClientSize.Width-NotLovebtn.Width;//声明一个变量用于存放按钮的Y轴坐标inty=this.ClientSize.Height-NotLovebtn.Height;标准文档实用文案//声明一个随机数实例Randomr=newRandom();//声明按钮的
4、移动范围NotLovebtn.Location=newPoint(r.Next(0,x+1),r.Next(0,y+1));}}}//2.在窗口中放置两个控件如下图:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespa
5、ceLable控件和TextBox控件{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidtxtBox_TextChanged(objectsender,EventArgse){lblTxt.Text=txtBox.Text;//使lable控件的值等于textbox的值}}}//3.做一个跑马灯的练习控件如下图:在窗体中放入label和Timer两个控件并分别设置两个控件的属性Label控件:Text:☆★
6、Timer控件:Enable:trueTick:事件标准文档实用文案usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespace跑马灯{publicpartialclassForm1:Form{publicForm1(){
7、InitializeComponent();}privatevoidtimer1_Tick(objectsender,EventArgse){label1.Text=label1.Text.Substring(1)+label1.Text.Substring(0,1);}}}//4.小闹钟在窗体中放一个label和timer两个控件并修改其属性Timer控件:Interval:1000Enable:TrueLabel控件:Name:labtimeusingSystem;usingSystem.Collectio
8、ns.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;标准文档实用文案usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Media;namespace小闹钟{publicpartialclassFo
此文档下载收益归作者所有