C#winform练习

2018-12-20 15:13

//1.添加两个按钮一个文本框如下图:当用户点击爱时弹出“我也爱你哟”,点击不爱时弹出“还是被你给点到了”并退出程序

using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Windows.Forms;

namespace Love_and_notLove {

public partial class Form1 : Form {

public Form1() {

InitializeComponent(); }

private void Lovebtn_Click(object sender, EventArgs e) {

MessageBox.Show(\我也爱你哟!\); this.Close(); }

//触发点击事件

private void NotLovebtn_Click(object sender, EventArgs e) {

MessageBox.Show(\还是被你给点到了\); //关闭主程序 this.Close(); }

//针对鼠标移动至按钮所属区域时触发事件

private void NotLovebtn_MouseEnter(object sender, EventArgs e) {

//声明一个变量用于存放按钮的X轴坐标

int x = this.ClientSize.Width-NotLovebtn.Width; //声明一个变量用于存放按钮的Y轴坐标

int y = this.ClientSize.Height-NotLovebtn.Height;

//声明一个随机数实例 Random r = new Random(); //声明按钮的移动范围

NotLovebtn.Location = new Point(r.Next(0, x + 1), r.Next(0, y + 1)); } } }

//2.在窗口中放置两个控件如下图:

using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Windows.Forms;

namespace Lable控件和TextBox控件 {

public partial class Form1 : Form {

public Form1() {

InitializeComponent(); }

private void txtBox_TextChanged(object sender, EventArgs e) {

lblTxt.Text = txtBox.Text; //使lable控件的值等于textbox的值 } } }

//3.做一个跑马灯的练习控件如下图:在窗体中放入label和Timer两个控件并分别设置两个控件的属性 Label控件:Text:☆★ Timer控件:Enable:true

Tick:事件

using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Windows.Forms;

namespace 跑马灯 {

public partial class Form1 : Form {

public Form1() {

InitializeComponent(); }

private void timer1_Tick(object sender, EventArgs e) {

label1.Text = label1.Text.Substring(1) + label1.Text.Substring(0, 1); } } } //4.小闹钟

在窗体中放一个label和timer两个控件并修改其属性 Timer控件:Interval:1000

Enable:True

Label 控件:Name:labtime using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq;

using System.Text;

using System.Windows.Forms; using System.Media;

namespace 小闹钟 {

public partial class Form1 : Form {

public Form1() {

InitializeComponent(); }

private void timer2_Tick(object sender, EventArgs e) {

labTime.Text = DateTime.Now.ToString();

if (DateTime.Now.Hour == 12 && DateTime.Now.Minute == 02 && DateTime.Now.Second == 00) {

SoundPlayer sp = new SoundPlayer();

sp.SoundLocation = @\; sp.Play(); } }

private void Form1_Load(object sender, EventArgs e) {

labTime.Text = DateTime.Now.ToString(); } } }

//5.需要输入用户名“admin”和密码“admin”才能登陆到使用介面的记事本程序: //在窗体中需要拖入2 个label控件4个button控件3个textBox控件并修改其相应属性 Label控件:label1:

Text: 用户名:

Label2: Text: 密码:

textBox控件:textBox2:

passwrodChar:*

textBox3: MultiLine(多行) WordWrap:False

Button控件:button1:

Name:btnLogin Text:登陆 Button2:

Name:btnReset Text:重置 Button3: Name:butWords Text:自动换行 Button4: Name:butSave Text:保存

using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Windows.Forms; using System.IO;

namespace 记事本程序 {

public partial class Form1 : Form {

public Form1() {

InitializeComponent(); }

///

/// 程序运行时隐藏文本编程器 ///

///

private void Form1_Load(object sender, EventArgs e) {

//txtWords.WordWrap = false; btnWords.Visible = false; btnSave.Visible = false;


C#winform练习.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:英语图表作文常用句型和结构

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: