1.winform应用程序是一种智能客户端技术,帮助我们获得信息或者传输信息。

2.当后台需要获取前台控件属性,需要使用Name属性。

visible:指示一个空间是否可见

enabled:指示一个空间是否可用

3.事件:发生一件事情

注册事件:双击空间注册的都是控件默认控件被选中的那个事件。

触发事件:

4.在Main函数中创建的窗体对象,我们称之为这个窗体应用程序的主窗体

意味,当将主窗体关闭后,整个应用程序都关闭。

5.TextBox控件

WordWrap:指示文本框是否换行

PasswordChar:让文本框显示一个单一的字符

ScollBars:是否显示滚动条

时间:TextChanged 当文本框中的内容发生改变时触发这个事件

6,跑马灯

private void timer1_Tick(object sender, EventArgs e){label1.Text = label1.Text.Substring(1) + label1.Text.Substring(0, 1);}

7.实时时间

 /// <summary>/// 每间隔一秒将当前的时间赋值给label2/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void timer2_Tick(object sender, EventArgs e){label2.Text = DateTime.Now.ToString();//当时间在15:32分钟的时候叫我起床if(DateTime.Now.Hour==15&&DateTime.Now.Minute==32&&DateTime.Now.Second==32){SoundPlayer sp = new SoundPlayer();sp.SoundLocation = @" ";sp.Play();}}/// <summary>/// 当窗体加载的时候 将当前系统时间赋值给Label2/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void Form1_Load(object sender, EventArgs e){label2.Text = DateTime.Now.ToString();}

8.简答记事本程序

1)在程序加载的时候,取消文本框的自动换行,以及让两个和文本框隐藏

2)点击登录,判断师傅登录成功

3)自动换行功能

4)保存文本到一个指定目录下

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;namespace WinFormsApp1
{public partial class Form2 : Form{public Form2(){InitializeComponent();}private void Form2_Load(object sender, EventArgs e){txtWords.WordWrap = false;btnWordWrap.Visible = false;btnSave.Visible = false;txtWords.Visible = false;}private void btnLogin_Click(object sender, EventArgs e){string name = txtName.Text.Trim();string pwd = txtPwd.Text;if (name =="admin"&&pwd=="admin"){MessageBox.Show("欢迎进入记事本应用程序");btnWordWrap.Visible = true;btnSave.Visible = true;txtWords.Visible = true;label1.Visible = false;label2.Visible = false;txtName.Visible = false;txtPwd.Visible = false;btnLogin.Visible = false;//btnRest.Visible = false;}else{MessageBox.Show("用户名或者密码错误,请重新输入");txtName.Clear();txtPwd.Clear();//为空间设置焦点txtName.Focus();}}private void txtName_TextChanged(object sender, EventArgs e){}/// <summary>/// 自动换行/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void btnWordWrap_Click(object sender, EventArgs e){//当前是否是自动换行if(btnWordWrap.Text=="自动换行"){//取消自动换行txtWords.WordWrap = true;btnWordWrap.Text = "取消自动换行";}else if(btnWordWrap.Text=="取消自动换行"){txtWords.WordWrap = false;btnWordWrap.Text = "自动换行";}}private void btnSave_Click(object sender, EventArgs e){using (FileStream fsWrite=new FileStream(@"",FileMode.OpenOrCreate,FileAccess.Write)){string str = txtWords.Text.Trim();byte[] buffer = System.Text.Encoding.Default.GetBytes(str);fsWrite.Write(buffer, 0, buffer.Length);}MessageBox.Show("保存成功");}}
}

9.单选和多选

checked:指示这个控件是否处于选中状态

默认情况下,在一个窗体中,所有的单选按钮只允许选中一个,可以使用groupbox进行分组。

10.窗体

1)首先确定一个父窗体,将IsMdiContainer设置为true。

2)创建子窗体,并且设置他们的父窗体

11.音乐播放

using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Media;
using System.Windows.Forms;
namespace Picture
{public partial class Form1 : Form{public Form1(){InitializeComponent();}//用来存储音乐文件的全路径List<string> listSongs = new List<string>();SoundPlayer sp = new SoundPlayer();private void Form1_Load(object sender, EventArgs e){//播放音乐sp.SoundLocation = @"";sp.Play();pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage;pictureBox4.SizeMode = PictureBoxSizeMode.StretchImage;//pictureBox5.SizeMode = PictureBoxSizeMode.StretchImage;//pictureBox6.SizeMode = PictureBoxSizeMode.StretchImage;//在窗体加载的时候 给每一个PictureBox赋值一张图片路径pictureBox1.Image = Image.FromFile(@"");pictureBox2.Image = Image.FromFile(@"");pictureBox3.Image = Image.FromFile(@"");pictureBox4.Image = Image.FromFile(@"");//pictureBox5.Image = Image.FromFile(@"");//pictureBox6.Image = Image.FromFile(@"");}string[] path = System.IO.Directory.GetFiles(@"");int i = 0;Random r = new Random();/// <summary>/// 每间隔一秒切换一张图片/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void timer1_Tick(object sender, EventArgs e){i++;if(i==path.Length){i = 0;}pictureBox1.Image = Image.FromFile(path[r.Next(0, path.Length)]);pictureBox2.Image = Image.FromFile(path[r.Next(0, path.Length)]);pictureBox3.Image = Image.FromFile(path[r.Next(0, path.Length)]);pictureBox4.Image = Image.FromFile(path[r.Next(0, path.Length)]);//pictureBox5.Image = Image.FromFile(path[r.Next(0, path.Length)]);//pictureBox6.Image = Image.FromFile(path[r.Next(0, path.Length)]);}private void button1_Click(object sender, EventArgs e){OpenFileDialog ofd = new OpenFileDialog();ofd.Title = "请选择音乐文件";ofd.InitialDirectory = @" ";ofd.Multiselect = true;ofd.Filter = "音乐文件|*.wav|所有文件|*.*";ofd.ShowDialog();//获得我们在文件夹中选择则所有文件的全路径string[] path = ofd.FileNames;for(int i=0;i<path.Length;i++){//将音乐文件的文件名加载到listbox中listBox1.Items.Add(Path.GetFileName(path[i]));//将音乐文件的文件名加载到ListBox中listSongs.Add(path[i]);}}/// <summary>/// 双击播放音乐/// </summary>s/// <param name="sender"></param>/// <param name="e"></param>private void listBox1_DoubleClick(object sender, EventArgs e){sp.SoundLocation = listSongs[listBox1.SelectedIndex];sp.Play();}/// <summary>/// 点击下一首/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void button3_Click(object sender, EventArgs e){//获得当前选中歌曲的索引int index = listBox1.SelectedIndex;index++;if(index==listBox1.Items.Count){index = 0;}//将改变后的索引重新的赋值给当前选中项的索引listBox1.SelectedIndex = index;sp.SoundLocation = listSongs[index];sp.Play();}private void button2_Click(object sender, EventArgs e){int index = listBox1.SelectedIndex;index--;if(index<0){index = listBox1.Items.Count - 1;}//将重新改变后的索引重新赋值给当前选中项listBox1.SelectedIndex = index;sp.SoundLocation = listSongs[index];sp.Play();}}
}

winform基础 C#编程相关推荐

  1. 嵌入式C程序基础与编程结构

    嵌入式C程序基础与编程结构 Basics of Embedded C Program and Programming Structure 嵌入式C编程是处理器在我们日常生活中遇到的每一个嵌入式系统(如 ...

  2. 异步委托实现多线程winform控件编程

            private void button1_Click(object sender, EventArgs e)         {             ThreadStart ts  ...

  3. PTA 基础程序编程集 7-2 然后是几点 C语言

    PTA 基础程序编程集 7-2 然后是几点 C语言 有时候人们用四位数字表示一个时间,比如1106表示11点零6分.现在,你的程序要根据起始时间和流逝的时间计算出终止时间. 读入两个数字,第一个数字以 ...

  4. C# WinForm基础

    1. WinForm基础 Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; u ...

  5. python资料包-5个G的Python学习资料包:让你从零基础成编程大神!

    原标题:5个G的Python学习资料包:让你从零基础成编程大神! 这年头不会点编程 都不好意思说自己是大学生 那些玩转Python的大牛们 几乎成了全民崇拜的偶像 但对于我们这种毫无基础的小白 自学编 ...

  6. 零基础是学java还是python-零基础学编程java和python哪个好

    零基础学编程java和python哪个好 更新时间:2019年02月17日18时56分 来源:传智播客java培训 浏览次数: 如今人工智能行业的蓬勃发展让很多想要学习编程的人会犹豫Java和Pyth ...

  7. java 初级编程题_java基础经典编程题

    java基础经典编程题 Monkey_peach代码 package com.sailor.game; /** * 题目:猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个 第 ...

  8. [見好就收]NET 2.0 - WinForm Control - DataGridView 编程36计

    原文:http://blog.csdn.net/fangxinggood/archive/2007/04/11/1561011.aspx#A1 NET 2.0 - WinForm Control - ...

  9. Java零基础并发编程入门

    Java零基础并发编程入门 并发编程主要包括: 线程,同步,future,锁,fork/join, volatile,信号量,cas(原子性,可见性,顺序一致性),临界性,分布式 了解基础: JMM: ...

  10. plc维修入门与故障处理实例_电气控制基础+PLC编程入门+工程应用实例

    以S7-300/400PLC为主线 电气控制基础+PLC编程入门+工程应用实例 点击图片  购买 编辑推荐1.西门子S7300/400PLC应用广.市场占有率高 2.本书通过大量的实验案例和真实的工程 ...

最新文章

  1. 中山大学提出新型行人重识别方法和史上最大最新评测基准
  2. Python代码高亮显示工具
  3. MIT机器狗再进化,碎石冰面上跑也不打滑,这次真的稳如狗了
  4. OVS ofproto(二十三)
  5. 前端学习(1301):gulp建立任务csso和less
  6. vue-router配置介绍和使用方法(二)
  7. 面试官系统精讲Java源码及大厂真题 - 10 Map源码会问哪些面试题
  8. 洛谷 P4549 【模板】裴蜀定理
  9. iphone越狱 -- 红雪越狱工具
  10. 金庸群侠传苍龙逐日1.2-szlzw手机移植版攻略
  11. 兰州中川机场停车费一天多少钱,中川机场附近停车便宜
  12. 《数学之友》期刊简介及投稿要求
  13. 【C语言】数组名地址与数组首元素地址区别(实例分析)
  14. 高斯列主消元法 求非齐次线性方程组 C语言实现代码
  15. 中介者(Mediator)模式实例
  16. php开发路由器界面,PHP制作简单仿路由器登录界面
  17. 斜线“\”与反斜线“/”应用场景的整理
  18. nginx 使用详细解
  19. OpenGL(十四)——Qt OpenGL纹理
  20. list添加元素_如何给List集合的每个元素添加index序号

热门文章

  1. 简练软考知识点整理-中国制造2025
  2. 《企业架构的数字化转型》10000字有感
  3. 数据化、信息化、数字化和智能化之间联系和区别解析(建设收藏)
  4. 易软门诊管理软件php,易软门诊管理系统最新下载
  5. 怎么删除内网计算机IP地址,如何能在局域网中隐藏电脑及IP地址
  6. 【Java 学习笔记】《Head First Java》——基本概念
  7. CorelDRAW2021版本下载 百度网盘
  8. linux内核线程详解,Linux内核线程
  9. pp助手苹果版_PP助手下线iOS版,曾首发iOS 9完美越狱工具,再见~
  10. 动易html编辑器漏洞,动易2006_SP6最新漏洞得到管理员密码