77范文网 - 专业文章范例文档资料分享平台

C#winform练习

来源:网络收集 时间:2018-12-20 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

//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;

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库C#winform练习在线全文阅读。

C#winform练习.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/378537.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: