标签:
1、Directory 操作文件夹 CreateDirectory 创建文件夹 Delete 删除文件夹 Move 剪切文件夹 Exist 判断是否存在 GetFiles 获得指定的目录下所有文件的全路径 GetDirectory 获得指定目录下所有文件夹的全路径
2、WebBrowser浏览器控件 url
3、ComboBox下拉框控件 DropDownStyle:控制下拉框的外观样式 名字:cbo+.... 案例:日期选择器
4、点击更换图片 1)、在程序加载的时候,将指定图片文件夹中所有的图片文件名读取到ListBox中
5、石头剪刀布 石头 1 剪刀 2 布 3 玩家赢了: 1 2=-1 2 3=-1 3 1=2 平手: 相减 =0 另外一种情况 :电脑赢了
6、对话框
7、进程 我们可以把计算机中每一个运行的应用程序都当做是一个进程。 而一个进程又是由多个线程组成的。
8、单线程给我们带来的问题
9、在.Net下,是不允许跨线程的访问。
MessageBox.Show()的各种用法
【函数】 <整型> MessageBox(<字符串> Text, <字符串> Title, <整型> nType,MessageBoxIcon);
【函数说明】 弹出一个消息框。
【语法】
参数:
Text <字符串>,消息框的正文;
Title <字符串>,消息框的标题;
nType <整型>,消息框的类型。
返回值:<整型>,用户在消息框上点击关闭时的选择的按钮。 MessageBoxIcon:对话框上显示的图标样式。
【说明】
MessageBox("消息内容", "返回值 确定1",MessageBoxButtons.OK,MessageBoxIcon.Question);
MessageBox("消息内容",, "返回值 确定1 取消2",MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
MessageBox("消息内容", "返回值 终止3 重试4 忽略5",MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
MessageBox("消息内容", "返回值 是6 否7 取消2",MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
MessageBox("消息内容", "返回值 是6 否7",MessageBoxButtons.YesNo, MessageBoxIcon.Hand);
MessageBox("消息内容", "返回值 重试4 取消2",MessageBoxButtons.RetryCancel, MessageBoxIcon.Information);
MessageBoxIcon: 所有图标样式
MessageBoxIcon.Question
MessageBoxIcon.Asterisk
MessageBoxIcon.Information
MessageBoxIcon.Error
MessageBoxIcon.Stop
MessageBoxIcon.Hand
MessageBoxIcon.Exclamation
MessageBoxIcon.Warning
MessageBoxIcon.None
01、Directory类
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 11 namespace _01_Directory类 12 { 13 public partial class Form1 : Form 14 { 15 public Form1() 16 { 17 InitializeComponent(); 18 } 19 } 20 }
1 namespace _01_Directory类 2 { 3 partial class Form1 4 { 5 /// <summary> 6 /// 必需的设计器变量。 7 /// </summary> 8 private System.ComponentModel.IContainer components = null; 9 10 /// <summary> 11 /// 清理所有正在使用的资源。 12 /// </summary> 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> 14 protected override void Dispose(bool disposing) 15 { 16 if (disposing && (components != null)) 17 { 18 components.Dispose(); 19 } 20 base.Dispose(disposing); 21 } 22 23 #region Windows 窗体设计器生成的代码 24 25 /// <summary> 26 /// 设计器支持所需的方法 - 不要 27 /// 使用代码编辑器修改此方法的内容。 28 /// </summary> 29 private void InitializeComponent() 30 { 31 this.components = new System.ComponentModel.Container(); 32 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 33 this.Text = "Form1"; 34 } 35 36 #endregion 37 } 38 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using System.Windows.Forms; 6 7 namespace _01_Directory类 8 { 9 static class Program 10 { 11 /// <summary> 12 /// 应用程序的主入口点。 13 /// </summary> 14 [STAThread] 15 static void Main() 16 { 17 Application.EnableVisualStyles(); 18 Application.SetCompatibleTextRenderingDefault(false); 19 Application.Run(new Form1()); 20 } 21 } 22 }
02、Directory
1 using System; 2 using System.Collections.Generic; 3 using System.IO; 4 using System.Linq; 5 using System.Text; 6 using System.Threading.Tasks; 7 8 namespace _02_Directory 9 { 10 class Program 11 { 12 static void Main(string[] args) 13 { 14 //File Path FileStream StreamReader StreamWriter 15 //Directory 文件夹 目录 16 //创建文件夹 17 //Directory.CreateDirectory(@"C:\a"); 18 //Console.WriteLine("创建成功"); 19 //Console.ReadKey(); 20 21 //删除文件夹 22 //Directory.Delete(@"C:\a",true); 23 //Console.WriteLine("删除成功"); 24 //Console.ReadKey(); 25 26 27 //剪切文件夹 28 //Directory.Move(@"c:\a", @"C:\Users\SpringRain\Desktop\new"); 29 //Console.WriteLine("剪切成功"); 30 //Console.ReadKey(); 31 32 33 //获得指定文件夹下所有文件的全路径 34 //string[] path = Directory.GetFiles(@"C:\Users\SpringRain\Desktop\Picture","*.jpg"); 35 //for (int i = 0; i < path.Length; i++) 36 //{ 37 // Console.WriteLine(path[i]); 38 //} 39 //Console.ReadKey(); 40 41 42 //获得指定目录下所有文件夹的全路径 43 //string[] path = Directory.GetDirectories(@"C:\Users\SpringRain\Desktop\new"); 44 //for (int i = 0; i < path.Length; i++) 45 //{ 46 // Console.WriteLine(path[i]); 47 //} 48 //Console.ReadKey(); 49 50 51 //判断指定的文件夹是否存在 52 //if (Directory.Exists(@"C:\a\b")) 53 //{ 54 // for (int i = 0; i < 100; i++) 55 // { 56 // Directory.CreateDirectory(@"C:\a\b\" + i); 57 // } 58 //} 59 //Console.WriteLine("OK"); 60 //Console.ReadKey(); 61 62 63 //Directory.Delete(@"C:\a\b", true); 64 //Console.ReadKey(); 65 } 66 } 67 }
03、浏览器控件
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 11 namespace _03_浏览器控件 12 { 13 public partial class Form1 : Form 14 { 15 public Form1() 16 { 17 InitializeComponent(); 18 } 19 20 private void button1_Click(object sender, EventArgs e) 21 { 22 23 string text = textBox1.Text; 24 Uri uri = new Uri("http://"+text); 25 webBrowser1.Url = uri; 26 } 27 } 28 }
1 namespace _03_浏览器控件 2 { 3 partial class Form1 4 { 5 /// <summary> 6 /// 必需的设计器变量。 7 /// </summary> 8 private System.ComponentModel.IContainer components = null; 9 10 /// <summary> 11 /// 清理所有正在使用的资源。 12 /// </summary> 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> 14 protected override void Dispose(bool disposing) 15 { 16 if (disposing && (components != null)) 17 { 18 components.Dispose(); 19 } 20 base.Dispose(disposing); 21 } 22 23 #region Windows 窗体设计器生成的代码 24 25 /// <summary> 26 /// 设计器支持所需的方法 - 不要 27 /// 使用代码编辑器修改此方法的内容。 28 /// </summary> 29 private void InitializeComponent() 30 { 31 this.webBrowser1 = new System.Windows.Forms.WebBrowser(); 32 this.textBox1 = new System.Windows.Forms.TextBox(); 33 this.button1 = new System.Windows.Forms.Button(); 34 this.SuspendLayout(); 35 // 36 // webBrowser1 37 // 38 this.webBrowser1.Location = new System.Drawing.Point(38, 40); 39 this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20); 40 this.webBrowser1.Name = "webBrowser1"; 41 this.webBrowser1.Size = new System.Drawing.Size(670, 334); 42 this.webBrowser1.TabIndex = 0; 43 this.webBrowser1.Url = new System.Uri("", System.UriKind.Relative); 44 // 45 // textBox1 46 // 47 this.textBox1.Location = new System.Drawing.Point(38, 13); 48 this.textBox1.Name = "textBox1"; 49 this.textBox1.Size = new System.Drawing.Size(557, 21); 50 this.textBox1.TabIndex = 1; 51 // 52 // button1 53 // 54 this.button1.Location = new System.Drawing.Point(619, 13); 55 this.button1.Name = "button1"; 56 this.button1.Size = new System.Drawing.Size(75, 23); 57 this.button1.TabIndex = 2; 58 this.button1.Text = "去往"; 59 this.button1.UseVisualStyleBackColor = true; 60 this.button1.Click += new System.EventHandler(this.button1_Click); 61 // 62 // Form1 63 // 64 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 65 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 66 this.ClientSize = new System.Drawing.Size(777, 419); 67 this.Controls.Add(this.button1); 68 this.Controls.Add(this.textBox1); 69 this.Controls.Add(this.webBrowser1); 70 this.Name = "Form1"; 71 this.Text = "Form1"; 72 this.ResumeLayout(false); 73 this.PerformLayout(); 74 75 } 76 77 #endregion 78 79 private System.Windows.Forms.WebBrowser webBrowser1; 80 private System.Windows.Forms.TextBox textBox1; 81 private System.Windows.Forms.Button button1; 82 } 83 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using System.Windows.Forms; 6 7 namespace _03_浏览器控件 8 { 9 static class Program 10 { 11 /// <summary> 12 /// 应用程序的主入口点。 13 /// </summary> 14 [STAThread] 15 static void Main() 16 { 17 Application.EnableVisualStyles(); 18 Application.SetCompatibleTextRenderingDefault(false); 19 Application.Run(new Form1()); 20 } 21 } 22 }
04ComboBox
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 11 namespace _04ComboBox 12 { 13 public partial class Form1 : Form 14 { 15 public Form1() 16 { 17 InitializeComponent(); 18 } 19 20 private void button1_Click(object sender, EventArgs e) 21 { 22 //通过代码给下拉框添加数据 23 comboBox2.Items.Add("张三"); 24 comboBox2.Items.Add("李四"); 25 comboBox2.Items.Add("王五"); 26 } 27 28 private void button2_Click(object sender, EventArgs e) 29 { 30 comboBox2.Items.Clear(); 31 } 32 } 33 }
1 namespace _04ComboBox 2 { 3 partial class Form1 4 { 5 /// <summary> 6 /// 必需的设计器变量。 7 /// </summary> 8 private System.ComponentModel.IContainer components = null; 9 10 /// <summary> 11 /// 清理所有正在使用的资源。 12 /// </summary> 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> 14 protected override void Dispose(bool disposing) 15 { 16 if (disposing && (components != null)) 17 { 18 components.Dispose(); 19 } 20 base.Dispose(disposing); 21 } 22 23 #region Windows 窗体设计器生成的代码 24 25 /// <summary> 26 /// 设计器支持所需的方法 - 不要 27 /// 使用代码编辑器修改此方法的内容。 28 /// </summary> 29 private void InitializeComponent() 30 { 31 this.comboBox1 = new System.Windows.Forms.ComboBox(); 32 this.comboBox2 = new System.Windows.Forms.ComboBox(); 33 this.comboBox3 = new System.Windows.Forms.ComboBox(); 34 this.button1 = new System.Windows.Forms.Button(); 35 this.button2 = new System.Windows.Forms.Button(); 36 this.SuspendLayout(); 37 // 38 // comboBox1 39 // 40 this.comboBox1.FormattingEnabled = true; 41 this.comboBox1.Items.AddRange(new object[] { 42 "Monday", 43 "TuesDay", 44 "WednesDay", 45 "ThursDay", 46 "Friday", 47 "SaturDay", 48 "SunDay"}); 49 this.comboBox1.Location = new System.Drawing.Point(23, 96); 50 this.comboBox1.Name = "comboBox1"; 51 this.comboBox1.Size = new System.Drawing.Size(147, 20); 52 this.comboBox1.TabIndex = 0; 53 // 54 // comboBox2 55 // 56 this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.Simple; 57 this.comboBox2.FormattingEnabled = true; 58 this.comboBox2.Items.AddRange(new object[] { 59 "Monday", 60 "TuesDay", 61 "WednesDay", 62 "ThursDay", 63 "Friday", 64 "SaturDay", 65 "SunDay"}); 66 this.comboBox2.Location = new System.Drawing.Point(212, 96); 67 this.comboBox2.Name = "comboBox2"; 68 this.comboBox2.Size = new System.Drawing.Size(121, 150); 69 this.comboBox2.TabIndex = 1; 70 // 71 // comboBox3 72 // 73 this.comboBox3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 74 this.comboBox3.FormattingEnabled = true; 75 this.comboBox3.Items.AddRange(new object[] { 76 "Monday", 77 "TuesDay", 78 "WednesDay", 79 "ThursDay", 80 "Friday", 81 "SaturDay", 82 "SunDay"}); 83 this.comboBox3.Location = new System.Drawing.Point(395, 96); 84 this.comboBox3.Name = "comboBox3"; 85 this.comboBox3.Size = new System.Drawing.Size(121, 20); 86 this.comboBox3.TabIndex = 2; 87 // 88 // button1 89 // 90 this.button1.Location = new System.Drawing.Point(212, 41); 91 this.button1.Name = "button1"; 92 this.button1.Size = new System.Drawing.Size(75, 23); 93 this.button1.TabIndex = 3; 94 this.button1.Text = "button1"; 95 this.button1.UseVisualStyleBackColor = true; 96 this.button1.Click += new System.EventHandler(this.button1_Click); 97 // 98 // button2 99 // 100 this.button2.Location = new System.Drawing.Point(293, 41); 101 this.button2.Name = "button2"; 102 this.button2.Size = new System.Drawing.Size(75, 23); 103 this.button2.TabIndex = 4; 104 this.button2.Text = "button2"; 105 this.button2.UseVisualStyleBackColor = true; 106 this.button2.Click += new System.EventHandler(this.button2_Click); 107 // 108 // Form1 109 // 110 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 111 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 112 this.ClientSize = new System.Drawing.Size(694, 449); 113 this.Controls.Add(this.button2); 114 this.Controls.Add(this.button1); 115 this.Controls.Add(this.comboBox3); 116 this.Controls.Add(this.comboBox2); 117 this.Controls.Add(this.comboBox1); 118 this.Name = "Form1"; 119 this.Text = "Form1"; 120 this.ResumeLayout(false); 121 122 } 123 124 #endregion 125 126 private System.Windows.Forms.ComboBox comboBox1; 127 private System.Windows.Forms.ComboBox comboBox2; 128 private System.Windows.Forms.ComboBox comboBox3; 129 private System.Windows.Forms.Button button1; 130 private System.Windows.Forms.Button button2; 131 } 132 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using System.Windows.Forms; 6 7 namespace _04ComboBox 8 { 9 static class Program 10 { 11 /// <summary> 12 /// 应用程序的主入口点。 13 /// </summary> 14 [STAThread] 15 static void Main() 16 { 17 Application.EnableVisualStyles(); 18 Application.SetCompatibleTextRenderingDefault(false); 19 Application.Run(new Form1()); 20 } 21 } 22 }
05日期选择器
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 11 namespace _05日期选择器 12 { 13 public partial class Form1 : Form 14 { 15 public Form1() 16 { 17 InitializeComponent(); 18 } 19 20 private void Form1_Load(object sender, EventArgs e) 21 { 22 //程序加载的时候 将年份添加到下拉框中 23 //获得当前的年份 24 int year = DateTime.Now.Year; 25 26 for (int i = year; i >= 1949; i--) 27 { 28 cboYear.Items.Add(i + "年"); 29 } 30 } 31 32 33 34 /// <summary> 35 /// 当年份发生改变的时候 加载月份 36 /// </summary> 37 /// <param name="sender"></param> 38 /// <param name="e"></param> 39 private void cboYear_SelectedIndexChanged(object sender, EventArgs e) 40 { 41 42 //添加之前应该清空之前的内容 43 cboMonth.Items.Clear(); 44 for (int i = 1; i <= 12; i++) 45 { 46 cboMonth.Items.Add(i + "月"); 47 } 48 } 49 50 51 52 /// <summary> 53 /// 当月份发生改变的时候 加载天 54 /// </summary> 55 /// <param name="sender"></param> 56 /// <param name="e"></param> 57 private void cboMonth_SelectedIndexChanged(object sender, EventArgs e) 58 { 59 cboDays.Items.Clear(); 60 int day = 0;//定义一个变量来存储天数 61 62 //获得月份 7月 12 63 string strMonth = cboMonth.SelectedItem.ToString().Split(new char[] { ‘月‘ }, StringSplitOptions.RemoveEmptyEntries)[0]; 64 string strYear = cboYear.SelectedItem.ToString().Split(new char[] { ‘年‘ }, StringSplitOptions.RemoveEmptyEntries)[0]; 65 // MessageBox.Show(cboMonth.SelectedItem.ToString()); 66 int year = Convert.ToInt32(strYear); 67 int month = Convert.ToInt32(strMonth); 68 switch (month) 69 { 70 case 1: 71 case 3: 72 case 5: 73 case 7: 74 case 8: 75 case 10: 76 case 12: day = 31; 77 break; 78 case 2: 79 if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) 80 { 81 day = 29; 82 } 83 else 84 { 85 day = 28; 86 } 87 break; 88 default: day = 30; 89 break; 90 } 91 92 for (int i = 1; i <= day; i++) 93 { 94 cboDays.Items.Add(i + "日"); 95 } 96 } 97 } 98 }
1 namespace _05日期选择器 2 { 3 partial class Form1 4 { 5 /// <summary> 6 /// 必需的设计器变量。 7 /// </summary> 8 private System.ComponentModel.IContainer components = null; 9 10 /// <summary> 11 /// 清理所有正在使用的资源。 12 /// </summary> 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> 14 protected override void Dispose(bool disposing) 15 { 16 if (disposing && (components != null)) 17 { 18 components.Dispose(); 19 } 20 base.Dispose(disposing); 21 } 22 23 #region Windows 窗体设计器生成的代码 24 25 /// <summary> 26 /// 设计器支持所需的方法 - 不要 27 /// 使用代码编辑器修改此方法的内容。 28 /// </summary> 29 private void InitializeComponent() 30 { 31 this.cboYear = new System.Windows.Forms.ComboBox(); 32 this.cboMonth = new System.Windows.Forms.ComboBox(); 33 this.cboDays = new System.Windows.Forms.ComboBox(); 34 this.SuspendLayout(); 35 // 36 // cboYear 37 // 38 this.cboYear.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 39 this.cboYear.FormattingEnabled = true; 40 this.cboYear.Location = new System.Drawing.Point(80, 84); 41 this.cboYear.Name = "cboYear"; 42 this.cboYear.Size = new System.Drawing.Size(121, 20); 43 this.cboYear.TabIndex = 0; 44 this.cboYear.SelectedIndexChanged += new System.EventHandler(this.cboYear_SelectedIndexChanged); 45 // 46 // cboMonth 47 // 48 this.cboMonth.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 49 this.cboMonth.FormattingEnabled = true; 50 this.cboMonth.Location = new System.Drawing.Point(239, 84); 51 this.cboMonth.Name = "cboMonth"; 52 this.cboMonth.Size = new System.Drawing.Size(121, 20); 53 this.cboMonth.TabIndex = 1; 54 this.cboMonth.SelectedIndexChanged += new System.EventHandler(this.cboMonth_SelectedIndexChanged); 55 // 56 // cboDays 57 // 58 this.cboDays.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 59 this.cboDays.FormattingEnabled = true; 60 this.cboDays.Location = new System.Drawing.Point(401, 84); 61 this.cboDays.Name = "cboDays"; 62 this.cboDays.Size = new System.Drawing.Size(121, 20); 63 this.cboDays.TabIndex = 2; 64 // 65 // Form1 66 // 67 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 68 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 69 this.ClientSize = new System.Drawing.Size(657, 430); 70 this.Controls.Add(this.cboDays); 71 this.Controls.Add(this.cboMonth); 72 this.Controls.Add(this.cboYear); 73 this.Name = "Form1"; 74 this.Text = "Form1"; 75 this.Load += new System.EventHandler(this.Form1_Load); 76 this.ResumeLayout(false); 77 78 } 79 80 #endregion 81 82 private System.Windows.Forms.ComboBox cboYear; 83 private System.Windows.Forms.ComboBox cboMonth; 84 private System.Windows.Forms.ComboBox cboDays; 85 } 86 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using System.Windows.Forms; 6 7 namespace _05日期选择器 8 { 9 static class Program 10 { 11 /// <summary> 12 /// 应用程序的主入口点。 13 /// </summary> 14 [STAThread] 15 static void Main() 16 { 17 Application.EnableVisualStyles(); 18 Application.SetCompatibleTextRenderingDefault(false); 19 Application.Run(new Form1()); 20 } 21 } 22 }
06ListBox控件
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 11 namespace _06ListBox控件 12 { 13 public partial class Form1 : Form 14 { 15 public Form1() 16 { 17 InitializeComponent(); 18 } 19 20 private void Form1_Load(object sender, EventArgs e) 21 { 22 listBox1.Items.Add(1); 23 listBox1.Items.Add(1); 24 listBox1.Items.Add(1); 25 listBox1.Items.Add(1); 26 listBox1.Items.Add(1); 27 } 28 } 29 }
1 namespace _06ListBox控件 2 { 3 partial class Form1 4 { 5 /// <summary> 6 /// 必需的设计器变量。 7 /// </summary> 8 private System.ComponentModel.IContainer components = null; 9 10 /// <summary> 11 /// 清理所有正在使用的资源。 12 /// </summary> 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> 14 protected override void Dispose(bool disposing) 15 { 16 if (disposing && (components != null)) 17 { 18 components.Dispose(); 19 } 20 base.Dispose(disposing); 21 } 22 23 #region Windows 窗体设计器生成的代码 24 25 /// <summary> 26 /// 设计器支持所需的方法 - 不要 27 /// 使用代码编辑器修改此方法的内容。 28 /// </summary> 29 private void InitializeComponent() 30 { 31 this.listBox1 = new System.Windows.Forms.ListBox(); 32 this.SuspendLayout(); 33 // 34 // listBox1 35 // 36 this.listBox1.FormattingEnabled = true; 37 this.listBox1.ItemHeight = 12; 38 this.listBox1.Items.AddRange(new object[] { 39 "Monday", 40 "TuesDay", 41 "WednesDay", 42 "ThursDay", 43 "Friday", 44 "SaturDay", 45 "SunDay"}); 46 this.listBox1.Location = new System.Drawing.Point(12, 55); 47 this.listBox1.Name = "listBox1"; 48 this.listBox1.Size = new System.Drawing.Size(163, 328); 49 this.listBox1.TabIndex = 0; 50 // 51 // Form1 52 // 53 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 54 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 55 this.ClientSize = new System.Drawing.Size(663, 412); 56 this.Controls.Add(this.listBox1); 57 this.Name = "Form1"; 58 this.Text = "Form1"; 59 this.Load += new System.EventHandler(this.Form1_Load); 60 this.ResumeLayout(false); 61 62 } 63 64 #endregion 65 66 private System.Windows.Forms.ListBox listBox1; 67 } 68 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using System.Windows.Forms; 6 7 namespace _06ListBox控件 8 { 9 static class Program 10 { 11 /// <summary> 12 /// 应用程序的主入口点。 13 /// </summary> 14 [STAThread] 15 static void Main() 16 { 17 Application.EnableVisualStyles(); 18 Application.SetCompatibleTextRenderingDefault(false); 19 Application.Run(new Form1()); 20 } 21 } 22 }
07实现点击更换照片
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 using System.IO; 11 namespace _07实现点击更换照片 12 { 13 public partial class Form1 : Form 14 { 15 public Form1() 16 { 17 InitializeComponent(); 18 } 19 20 21 //用来存储图片文件的全路径 22 List<string> list = new List<string>(); 23 24 private void Form1_Load(object sender, EventArgs e) 25 { 26 string[] path = Directory.GetFiles(@"C:\Users\SpringRain\Desktop\Picture", "*.jpg"); 27 for (int i = 0; i < path.Length; i++) 28 { 29 string fileName = Path.GetFileName(path[i]); 30 listBox1.Items.Add(fileName); 31 //将图片的全路径添加到List泛型集合中 32 list.Add(path[i]); 33 //listBox1.Items.Add(path[i]); 34 } 35 } 36 37 38 /// <summary> 39 /// 双击播放图片 40 /// </summary> 41 /// <param name="sender"></param> 42 /// <param name="e"></param> 43 private void listBox1_DoubleClick(object sender, EventArgs e) 44 { 45 pictureBox1.Image = Image.FromFile(list[listBox1.SelectedIndex]); 46 } 47 } 48 }
1 namespace _07实现点击更换照片 2 { 3 partial class Form1 4 { 5 /// <summary> 6 /// 必需的设计器变量。 7 /// </summary> 8 private System.ComponentModel.IContainer components = null; 9 10 /// <summary> 11 /// 清理所有正在使用的资源。 12 /// </summary> 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> 14 protected override void Dispose(bool disposing) 15 { 16 if (disposing && (components != null)) 17 { 18 components.Dispose(); 19 } 20 base.Dispose(disposing); 21 } 22 23 #region Windows 窗体设计器生成的代码 24 25 /// <summary> 26 /// 设计器支持所需的方法 - 不要 27 /// 使用代码编辑器修改此方法的内容。 28 /// </summary> 29 private void InitializeComponent() 30 { 31 this.listBox1 = new System.Windows.Forms.ListBox(); 32 this.pictureBox1 = new System.Windows.Forms.PictureBox(); 33 ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); 34 this.SuspendLayout(); 35 // 36 // listBox1 37 // 38 this.listBox1.FormattingEnabled = true; 39 this.listBox1.ItemHeight = 12; 40 this.listBox1.Location = new System.Drawing.Point(13, 13); 41 this.listBox1.Name = "listBox1"; 42 this.listBox1.Size = new System.Drawing.Size(198, 448); 43 this.listBox1.TabIndex = 0; 44 this.listBox1.DoubleClick += new System.EventHandler(this.listBox1_DoubleClick); 45 // 46 // pictureBox1 47 // 48 this.pictureBox1.Location = new System.Drawing.Point(264, 13); 49 this.pictureBox1.Name = "pictureBox1"; 50 this.pictureBox1.Size = new System.Drawing.Size(410, 443); 51 this.pictureBox1.TabIndex = 1; 52 this.pictureBox1.TabStop = false; 53 // 54 // Form1 55 // 56 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 57 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 58 this.ClientSize = new System.Drawing.Size(709, 468); 59 this.Controls.Add(this.pictureBox1); 60 this.Controls.Add(this.listBox1); 61 this.Name = "Form1"; 62 this.Text = "Form1"; 63 this.Load += new System.EventHandler(this.Form1_Load); 64 ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); 65 this.ResumeLayout(false); 66 67 } 68 69 #endregion 70 71 private System.Windows.Forms.ListBox listBox1; 72 private System.Windows.Forms.PictureBox pictureBox1; 73 } 74 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using System.Windows.Forms; 6 7 namespace _07实现点击更换照片 8 { 9 static class Program 10 { 11 /// <summary> 12 /// 应用程序的主入口点。 13 /// </summary> 14 [STAThread] 15 static void Main() 16 { 17 Application.EnableVisualStyles(); 18 Application.SetCompatibleTextRenderingDefault(false); 19 Application.Run(new Form1()); 20 } 21 } 22 }
08双击播放音乐
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 using System.IO; 11 using System.Media; 12 namespace _08双击播放音乐 13 { 14 public partial class Form1 : Form 15 { 16 public Form1() 17 { 18 InitializeComponent(); 19 } 20 //存储音乐文件的全路径 21 List<string> listSongs = new List<string>(); 22 private void Form1_Load(object sender, EventArgs e) 23 { 24 string[] path = Directory.GetFiles(@"C:\Users\SpringRain\Desktop\Music", "*.wav"); 25 for (int i = 0; i < path.Length; i++) 26 { 27 string fileName = Path.GetFileName(path[i]); 28 listBox1.Items.Add(fileName); 29 //将音乐文件的全路径存到泛型集合中 30 listSongs.Add(path[i]); 31 } 32 } 33 34 private void listBox1_DoubleClick(object sender, EventArgs e) 35 { 36 SoundPlayer sp = new SoundPlayer(); 37 sp.SoundLocation=listSongs[listBox1.SelectedIndex]; 38 sp.Play(); 39 } 40 } 41 }
1 namespace _08双击播放音乐 2 { 3 partial class Form1 4 { 5 /// <summary> 6 /// 必需的设计器变量。 7 /// </summary> 8 private System.ComponentModel.IContainer components = null; 9 10 /// <summary> 11 /// 清理所有正在使用的资源。 12 /// </summary> 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> 14 protected override void Dispose(bool disposing) 15 { 16 if (disposing && (components != null)) 17 { 18 components.Dispose(); 19 } 20 base.Dispose(disposing); 21 } 22 23 #region Windows 窗体设计器生成的代码 24 25 /// <summary> 26 /// 设计器支持所需的方法 - 不要 27 /// 使用代码编辑器修改此方法的内容。 28 /// </summary> 29 private void InitializeComponent() 30 { 31 this.listBox1 = new System.Windows.Forms.ListBox(); 32 this.SuspendLayout(); 33 // 34 // listBox1 35 // 36 this.listBox1.FormattingEnabled = true; 37 this.listBox1.ItemHeight = 12; 38 this.listBox1.Location = new System.Drawing.Point(22, 8); 39 this.listBox1.Name = "listBox1"; 40 this.listBox1.Size = new System.Drawing.Size(188, 400); 41 this.listBox1.TabIndex = 0; 42 this.listBox1.DoubleClick += new System.EventHandler(this.listBox1_DoubleClick); 43 // 44 // Form1 45 // 46 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 47 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 48 this.ClientSize = new System.Drawing.Size(703, 420); 49 this.Controls.Add(this.listBox1); 50 this.Name = "Form1"; 51 this.Text = "Form1"; 52 this.Load += new System.EventHandler(this.Form1_Load); 53 this.ResumeLayout(false); 54 55 } 56 57 #endregion 58 59 private System.Windows.Forms.ListBox listBox1; 60 } 61 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using System.Windows.Forms; 6 7 namespace _08双击播放音乐 8 { 9 static class Program 10 { 11 /// <summary> 12 /// 应用程序的主入口点。 13 /// </summary> 14 [STAThread] 15 static void Main() 16 { 17 Application.EnableVisualStyles(); 18 Application.SetCompatibleTextRenderingDefault(false); 19 Application.Run(new Form1()); 20 } 21 } 22 }
09石头剪刀布
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace _09石头剪刀布 8 { 9 public enum Result 10 { 11 玩家赢, 12 电脑赢, 13 平手 14 } 15 16 17 class CaiPan 18 { 19 public static Result Judge(int playerNumber, int cpuNumber) 20 { 21 if (playerNumber - cpuNumber == -1 || playerNumber - cpuNumber == 2) 22 { 23 return Result.玩家赢; 24 } 25 else if (playerNumber - cpuNumber == 0) 26 { 27 return Result.平手; 28 } 29 else 30 { 31 return Result.电脑赢; 32 } 33 } 34 } 35 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace _09石头剪刀布 8 { 9 class Computer 10 { 11 12 13 /// <summary> 14 /// 存储电脑出的拳头 15 /// </summary> 16 public string Fist 17 { 18 get; 19 set; 20 } 21 22 23 public int ShowFist() 24 { 25 Random r = new Random(); 26 int rNumber = r.Next(1, 4); 27 switch (rNumber) 28 { 29 case 1: this.Fist = "石头"; 30 break; 31 case 2: this.Fist = "剪刀"; 32 break; 33 case 3: this.Fist = "布"; 34 break; 35 } 36 return rNumber; 37 } 38 } 39 }
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 11 namespace _09石头剪刀布 12 { 13 public partial class lblComputer : Form 14 { 15 public lblComputer() 16 { 17 InitializeComponent(); 18 } 19 20 private void btnStone_Click(object sender, EventArgs e) 21 { 22 string str = "石头"; 23 PlayGame(str); 24 } 25 26 private void PlayGame(string str) 27 { 28 lblPlayer.Text = str; 29 30 Player player = new Player(); 31 int playerNumber = player.ShowFist(str); 32 33 Computer cpu = new Computer(); 34 int cpuNumber = cpu.ShowFist(); 35 label4.Text = cpu.Fist; 36 37 Result res = CaiPan.Judge(playerNumber, cpuNumber); 38 39 lblResult.Text = res.ToString(); 40 } 41 42 private void btnCut_Click(object sender, EventArgs e) 43 { 44 string str = "剪刀"; 45 PlayGame(str); 46 } 47 48 private void btnNo_Click(object sender, EventArgs e) 49 { 50 string str = "布"; 51 PlayGame(str); 52 } 53 } 54 }
1 namespace _09石头剪刀布 2 { 3 partial class lblComputer 4 { 5 /// <summary> 6 /// 必需的设计器变量。 7 /// </summary> 8 private System.ComponentModel.IContainer components = null; 9 10 /// <summary> 11 /// 清理所有正在使用的资源。 12 /// </summary> 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> 14 protected override void Dispose(bool disposing) 15 { 16 if (disposing && (components != null)) 17 { 18 components.Dispose(); 19 } 20 base.Dispose(disposing); 21 } 22 23 #region Windows 窗体设计器生成的代码 24 25 /// <summary> 26 /// 设计器支持所需的方法 - 不要 27 /// 使用代码编辑器修改此方法的内容。 28 /// </summary> 29 private void InitializeComponent() 30 { 31 this.label1 = new System.Windows.Forms.Label(); 32 this.lblPlayer = new System.Windows.Forms.Label(); 33 this.label3 = new System.Windows.Forms.Label(); 34 this.label4 = new System.Windows.Forms.Label(); 35 this.label5 = new System.Windows.Forms.Label(); 36 this.lblResult = new System.Windows.Forms.Label(); 37 this.btnStone = new System.Windows.Forms.Button(); 38 this.btnCut = new System.Windows.Forms.Button(); 39 this.btnNo = new System.Windows.Forms.Button(); 40 this.SuspendLayout(); 41 // 42 // label1 43 // 44 this.label1.AutoSize = true; 45 this.label1.Location = new System.Drawing.Point(31, 45); 46 this.label1.Name = "label1"; 47 this.label1.Size = new System.Drawing.Size(53, 12); 48 this.label1.TabIndex = 0; 49 this.label1.Text = "玩家出:"; 50 // 51 // lblPlayer 52 // 53 this.lblPlayer.AutoSize = true; 54 this.lblPlayer.Location = new System.Drawing.Point(125, 45); 55 this.lblPlayer.Name = "lblPlayer"; 56 this.lblPlayer.Size = new System.Drawing.Size(41, 12); 57 this.lblPlayer.TabIndex = 1; 58 this.lblPlayer.Text = "label2"; 59 // 60 // label3 61 // 62 this.label3.AutoSize = true; 63 this.label3.Location = new System.Drawing.Point(414, 44); 64 this.label3.Name = "label3"; 65 this.label3.Size = new System.Drawing.Size(53, 12); 66 this.label3.TabIndex = 2; 67 this.label3.Text = "电脑出:"; 68 // 69 // label4 70 // 71 this.label4.AutoSize = true; 72 this.label4.Location = new System.Drawing.Point(507, 44); 73 this.label4.Name = "label4"; 74 this.label4.Size = new System.Drawing.Size(41, 12); 75 this.label4.TabIndex = 3; 76 this.label4.Text = "label4"; 77 // 78 // label5 79 // 80 this.label5.AutoSize = true; 81 this.label5.Location = new System.Drawing.Point(235, 202); 82 this.label5.Name = "label5"; 83 this.label5.Size = new System.Drawing.Size(29, 12); 84 this.label5.TabIndex = 4; 85 this.label5.Text = "裁判"; 86 // 87 // lblResult 88 // 89 this.lblResult.AutoSize = true; 90 this.lblResult.Location = new System.Drawing.Point(305, 202); 91 this.lblResult.Name = "lblResult"; 92 this.lblResult.Size = new System.Drawing.Size(41, 12); 93 this.lblResult.TabIndex = 5; 94 this.lblResult.Text = "label6"; 95 // 96 // btnStone 97 // 98 this.btnStone.Location = new System.Drawing.Point(122, 283); 99 this.btnStone.Name = "btnStone"; 100 this.btnStone.Size = new System.Drawing.Size(75, 23); 101 this.btnStone.TabIndex = 6; 102 this.btnStone.Text = "石头"; 103 this.btnStone.UseVisualStyleBackColor = true; 104 this.btnStone.Click += new System.EventHandler(this.btnStone_Click); 105 // 106 // btnCut 107 // 108 this.btnCut.Location = new System.Drawing.Point(263, 283); 109 this.btnCut.Name = "btnCut"; 110 this.btnCut.Size = new System.Drawing.Size(75, 23); 111 this.btnCut.TabIndex = 7; 112 this.btnCut.Text = "剪刀"; 113 this.btnCut.UseVisualStyleBackColor = true; 114 this.btnCut.Click += new System.EventHandler(this.btnCut_Click); 115 // 116 // btnNo 117 // 118 this.btnNo.Location = new System.Drawing.Point(392, 283); 119 this.btnNo.Name = "btnNo"; 120 this.btnNo.Size = new System.Drawing.Size(75, 23); 121 this.btnNo.TabIndex = 8; 122 this.btnNo.Text = "布"; 123 this.btnNo.UseVisualStyleBackColor = true; 124 this.btnNo.Click += new System.EventHandler(this.btnNo_Click); 125 // 126 // lblComputer 127 // 128 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 129 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 130 this.ClientSize = new System.Drawing.Size(664, 435); 131 this.Controls.Add(this.btnNo); 132 this.Controls.Add(this.btnCut); 133 this.Controls.Add(this.btnStone); 134 this.Controls.Add(this.lblResult); 135 this.Controls.Add(this.label5); 136 this.Controls.Add(this.label4); 137 this.Controls.Add(this.label3); 138 this.Controls.Add(this.lblPlayer); 139 this.Controls.Add(this.label1); 140 this.Name = "lblComputer"; 141 this.Text = "Form1"; 142 this.ResumeLayout(false); 143 this.PerformLayout(); 144 145 } 146 147 #endregion 148 149 private System.Windows.Forms.Label label1; 150 private System.Windows.Forms.Label lblPlayer; 151 private System.Windows.Forms.Label label3; 152 private System.Windows.Forms.Label label4; 153 private System.Windows.Forms.Label label5; 154 private System.Windows.Forms.Label lblResult; 155 private System.Windows.Forms.Button btnStone; 156 private System.Windows.Forms.Button btnCut; 157 private System.Windows.Forms.Button btnNo; 158 } 159 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace _09石头剪刀布 8 { 9 class Player 10 { 11 public int ShowFist(string fist) 12 { 13 int num = 0; 14 switch (fist) 15 { 16 case "石头": num = 1; 17 break; 18 case "剪刀": num = 2; 19 break; 20 case "布": num = 3; 21 break; 22 } 23 return num; 24 } 25 } 26 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using System.Windows.Forms; 6 7 namespace _09石头剪刀布 8 { 9 static class Program 10 { 11 /// <summary> 12 /// 应用程序的主入口点。 13 /// </summary> 14 [STAThread] 15 static void Main() 16 { 17 Application.EnableVisualStyles(); 18 Application.SetCompatibleTextRenderingDefault(false); 19 Application.Run(new lblComputer()); 20 } 21 } 22 }
10打开对话框
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 using System.IO; 11 namespace _10打开对话框 12 { 13 public partial class Form1 : Form 14 { 15 public Form1() 16 { 17 InitializeComponent(); 18 } 19 20 private void button1_Click(object sender, EventArgs e) 21 { 22 //点击弹出对话框 23 OpenFileDialog ofd = new OpenFileDialog(); 24 //设置对话框的标题 25 ofd.Title = "请选择要打开的文本文件哟亲 O(∩_∩)O~"; 26 //设置对话框可以多选 27 ofd.Multiselect = true; 28 //设置对话框的初始目录 29 ofd.InitialDirectory = @"C:\Users\SpringRain\Desktop"; 30 //设置对话框的文件类型 31 ofd.Filter = "文本文件|*.txt|媒体文件|*.wmv|图片文件|*.jpg|所有文件|*.*"; 32 //展示对话框 33 ofd.ShowDialog(); 34 35 //获得在打开对话框中选中文件的路径 36 string path = ofd.FileName; 37 if (path == "") 38 { 39 return; 40 } 41 using (FileStream fsRead = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read)) 42 { 43 byte[] buffer = new byte[1024 * 1024 * 5]; 44 //实际读取到的字节数 45 int r = fsRead.Read(buffer, 0, buffer.Length); 46 47 textBox1.Text = Encoding.Default.GetString(buffer, 0, r); 48 } 49 } 50 } 51 }
1 namespace _10打开对话框 2 { 3 partial class Form1 4 { 5 /// <summary> 6 /// 必需的设计器变量。 7 /// </summary> 8 private System.ComponentModel.IContainer components = null; 9 10 /// <summary> 11 /// 清理所有正在使用的资源。 12 /// </summary> 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> 14 protected override void Dispose(bool disposing) 15 { 16 if (disposing && (components != null)) 17 { 18 components.Dispose(); 19 } 20 base.Dispose(disposing); 21 } 22 23 #region Windows 窗体设计器生成的代码 24 25 /// <summary> 26 /// 设计器支持所需的方法 - 不要 27 /// 使用代码编辑器修改此方法的内容。 28 /// </summary> 29 private void InitializeComponent() 30 { 31 this.button1 = new System.Windows.Forms.Button(); 32 this.textBox1 = new System.Windows.Forms.TextBox(); 33 this.SuspendLayout(); 34 // 35 // button1 36 // 37 this.button1.Location = new System.Drawing.Point(13, 13); 38 this.button1.Name = "button1"; 39 this.button1.Size = new System.Drawing.Size(75, 23); 40 this.button1.TabIndex = 0; 41 this.button1.Text = "选择文件"; 42 this.button1.UseVisualStyleBackColor = true; 43 this.button1.Click += new System.EventHandler(this.button1_Click); 44 // 45 // textBox1 46 // 47 this.textBox1.Location = new System.Drawing.Point(13, 68); 48 this.textBox1.Multiline = true; 49 this.textBox1.Name = "textBox1"; 50 this.textBox1.Size = new System.Drawing.Size(625, 314); 51 this.textBox1.TabIndex = 1; 52 // 53 // Form1 54 // 55 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 56 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 57 this.ClientSize = new System.Drawing.Size(735, 417); 58 this.Controls.Add(this.textBox1); 59 this.Controls.Add(this.button1); 60 this.Name = "Form1"; 61 this.Text = "Form1"; 62 this.ResumeLayout(false); 63 this.PerformLayout(); 64 65 } 66 67 #endregion 68 69 private System.Windows.Forms.Button button1; 70 private System.Windows.Forms.TextBox textBox1; 71 } 72 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using System.Windows.Forms; 6 7 namespace _10打开对话框 8 { 9 static class Program 10 { 11 /// <summary> 12 /// 应用程序的主入口点。 13 /// </summary> 14 [STAThread] 15 static void Main() 16 { 17 Application.EnableVisualStyles(); 18 Application.SetCompatibleTextRenderingDefault(false); 19 Application.Run(new Form1()); 20 } 21 } 22 }
11、保存文件对话框
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.IO; 7 using System.Linq; 8 using System.Text; 9 using System.Threading.Tasks; 10 using System.Windows.Forms; 11 12 namespace _11_保存文件对话框 13 { 14 public partial class Form1 : Form 15 { 16 public Form1() 17 { 18 InitializeComponent(); 19 } 20 21 private void button1_Click(object sender, EventArgs e) 22 { 23 SaveFileDialog sfd = new SaveFileDialog(); 24 sfd.Title = "请选择要保存的路径"; 25 sfd.InitialDirectory = @"C:\Users\SpringRain\Desktop"; 26 sfd.Filter = "文本文件|*.txt|所有文件|*.*"; 27 sfd.ShowDialog(); 28 //获得保存文件的路径 29 string path = sfd.FileName; 30 if (path == "") 31 { 32 return; 33 } 34 using (FileStream fsWrite = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write)) 35 { 36 byte[] buffer = Encoding.Default.GetBytes(textBox1.Text); 37 fsWrite.Write(buffer, 0, buffer.Length); 38 } 39 MessageBox.Show("保存成功"); 40 41 } 42 } 43 }
1 namespace _11_保存文件对话框 2 { 3 partial class Form1 4 { 5 /// <summary> 6 /// 必需的设计器变量。 7 /// </summary> 8 private System.ComponentModel.IContainer components = null; 9 10 /// <summary> 11 /// 清理所有正在使用的资源。 12 /// </summary> 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> 14 protected override void Dispose(bool disposing) 15 { 16 if (disposing && (components != null)) 17 { 18 components.Dispose(); 19 } 20 base.Dispose(disposing); 21 } 22 23 #region Windows 窗体设计器生成的代码 24 25 /// <summary> 26 /// 设计器支持所需的方法 - 不要 27 /// 使用代码编辑器修改此方法的内容。 28 /// </summary> 29 private void InitializeComponent() 30 { 31 this.textBox1 = new System.Windows.Forms.TextBox(); 32 this.button1 = new System.Windows.Forms.Button(); 33 this.SuspendLayout(); 34 // 35 // textBox1 36 // 37 this.textBox1.Location = new System.Drawing.Point(32, 121); 38 this.textBox1.Multiline = true; 39 this.textBox1.Name = "textBox1"; 40 this.textBox1.Size = new System.Drawing.Size(468, 302); 41 this.textBox1.TabIndex = 0; 42 // 43 // button1 44 // 45 this.button1.Location = new System.Drawing.Point(32, 41); 46 this.button1.Name = "button1"; 47 this.button1.Size = new System.Drawing.Size(75, 23); 48 this.button1.TabIndex = 1; 49 this.button1.Text = "保存"; 50 this.button1.UseVisualStyleBackColor = true; 51 this.button1.Click += new System.EventHandler(this.button1_Click); 52 // 53 // Form1 54 // 55 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 56 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 57 this.ClientSize = new System.Drawing.Size(557, 452); 58 this.Controls.Add(this.button1); 59 this.Controls.Add(this.textBox1); 60 this.Name = "Form1"; 61 this.Text = "Form1"; 62 this.ResumeLayout(false); 63 this.PerformLayout(); 64 65 } 66 67 #endregion 68 69 private System.Windows.Forms.TextBox textBox1; 70 private System.Windows.Forms.Button button1; 71 } 72 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using System.Windows.Forms; 6 7 namespace _11_保存文件对话框 8 { 9 static class Program 10 { 11 /// <summary> 12 /// 应用程序的主入口点。 13 /// </summary> 14 [STAThread] 15 static void Main() 16 { 17 Application.EnableVisualStyles(); 18 Application.SetCompatibleTextRenderingDefault(false); 19 Application.Run(new Form1()); 20 } 21 } 22 }
12、字体和颜色对话框
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 11 namespace _12_字体和颜色对话框 12 { 13 public partial class Form1 : Form 14 { 15 public Form1() 16 { 17 InitializeComponent(); 18 } 19 20 21 22 /// <summary> 23 /// 字体对话框 24 /// </summary> 25 /// <param name="sender"></param> 26 /// <param name="e"></param> 27 private void button1_Click(object sender, EventArgs e) 28 { 29 FontDialog fd = new FontDialog(); 30 fd.ShowDialog(); 31 textBox1.Font = fd.Font; 32 } 33 34 private void button2_Click(object sender, EventArgs e) 35 { 36 ColorDialog cd = new ColorDialog(); 37 cd.ShowDialog(); 38 textBox1.ForeColor = cd.Color; 39 } 40 } 41 }
1 namespace _12_字体和颜色对话框 2 { 3 partial class Form1 4 { 5 /// <summary> 6 /// 必需的设计器变量。 7 /// </summary> 8 private System.ComponentModel.IContainer components = null; 9 10 /// <summary> 11 /// 清理所有正在使用的资源。 12 /// </summary> 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> 14 protected override void Dispose(bool disposing) 15 { 16 if (disposing && (components != null)) 17 { 18 components.Dispose(); 19 } 20 base.Dispose(disposing); 21 } 22 23 #region Windows 窗体设计器生成的代码 24 25 /// <summary> 26 /// 设计器支持所需的方法 - 不要 27 /// 使用代码编辑器修改此方法的内容。 28 /// </summary> 29 private void InitializeComponent() 30 { 31 this.button1 = new System.Windows.Forms.Button(); 32 this.button2 = new System.Windows.Forms.Button(); 33 this.textBox1 = new System.Windows.Forms.TextBox(); 34 this.SuspendLayout(); 35 // 36 // button1 37 // 38 this.button1.Location = new System.Drawing.Point(88, 36); 39 this.button1.Name = "button1"; 40 this.button1.Size = new System.Drawing.Size(75, 23); 41 this.button1.TabIndex = 0; 42 this.button1.Text = "字体"; 43 this.button1.UseVisualStyleBackColor = true; 44 this.button1.Click += new System.EventHandler(this.button1_Click); 45 // 46 // button2 47 // 48 this.button2.Location = new System.Drawing.Point(204, 35); 49 this.button2.Name = "button2"; 50 this.button2.Size = new System.Drawing.Size(75, 23); 51 this.button2.TabIndex = 1; 52 this.button2.Text = "颜色"; 53 this.button2.UseVisualStyleBackColor = true; 54 this.button2.Click += new System.EventHandler(this.button2_Click); 55 // 56 // textBox1 57 // 58 this.textBox1.Location = new System.Drawing.Point(31, 123); 59 this.textBox1.Multiline = true; 60 this.textBox1.Name = "textBox1"; 61 this.textBox1.Size = new System.Drawing.Size(437, 288); 62 this.textBox1.TabIndex = 2; 63 // 64 // Form1 65 // 66 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 67 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 68 this.ClientSize = new System.Drawing.Size(555, 455); 69 this.Controls.Add(this.textBox1); 70 this.Controls.Add(this.button2); 71 this.Controls.Add(this.button1); 72 this.Name = "Form1"; 73 this.Text = "Form1"; 74 this.ResumeLayout(false); 75 this.PerformLayout(); 76 77 } 78 79 #endregion 80 81 private System.Windows.Forms.Button button1; 82 private System.Windows.Forms.Button button2; 83 private System.Windows.Forms.TextBox textBox1; 84 } 85 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using System.Windows.Forms; 6 7 namespace _12_字体和颜色对话框 8 { 9 static class Program 10 { 11 /// <summary> 12 /// 应用程序的主入口点。 13 /// </summary> 14 [STAThread] 15 static void Main() 16 { 17 Application.EnableVisualStyles(); 18 Application.SetCompatibleTextRenderingDefault(false); 19 Application.Run(new Form1()); 20 } 21 } 22 }
13、Panel
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 11 namespace _13_Panel 12 { 13 public partial class Form1 : Form 14 { 15 public Form1() 16 { 17 InitializeComponent(); 18 } 19 20 private void button1_Click(object sender, EventArgs e) 21 { 22 panel1.Visible = true; 23 } 24 25 private void button2_Click(object sender, EventArgs e) 26 { 27 panel1.Visible = false; 28 } 29 } 30 }
1 namespace _13_Panel 2 { 3 partial class Form1 4 { 5 /// <summary> 6 /// 必需的设计器变量。 7 /// </summary> 8 private System.ComponentModel.IContainer components = null; 9 10 /// <summary> 11 /// 清理所有正在使用的资源。 12 /// </summary> 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> 14 protected override void Dispose(bool disposing) 15 { 16 if (disposing && (components != null)) 17 { 18 components.Dispose(); 19 } 20 base.Dispose(disposing); 21 } 22 23 #region Windows 窗体设计器生成的代码 24 25 /// <summary> 26 /// 设计器支持所需的方法 - 不要 27 /// 使用代码编辑器修改此方法的内容。 28 /// </summary> 29 private void InitializeComponent() 30 { 31 this.panel1 = new System.Windows.Forms.Panel(); 32 this.button1 = new System.Windows.Forms.Button(); 33 this.button2 = new System.Windows.Forms.Button(); 34 this.button3 = new System.Windows.Forms.Button(); 35 this.checkedListBox1 = new System.Windows.Forms.CheckedListBox(); 36 this.label1 = new System.Windows.Forms.Label(); 37 this.listBox1 = new System.Windows.Forms.ListBox(); 38 this.linkLabel1 = new System.Windows.Forms.LinkLabel(); 39 this.monthCalendar1 = new System.Windows.Forms.MonthCalendar(); 40 this.panel1.SuspendLayout(); 41 this.SuspendLayout(); 42 // 43 // panel1 44 // 45 this.panel1.Controls.Add(this.monthCalendar1); 46 this.panel1.Controls.Add(this.linkLabel1); 47 this.panel1.Controls.Add(this.listBox1); 48 this.panel1.Controls.Add(this.label1); 49 this.panel1.Controls.Add(this.checkedListBox1); 50 this.panel1.Controls.Add(this.button3); 51 this.panel1.Location = new System.Drawing.Point(26, 29); 52 this.panel1.Name = "panel1"; 53 this.panel1.Size = new System.Drawing.Size(344, 400); 54 this.panel1.TabIndex = 0; 55 // 56 // button1 57 // 58 this.button1.Location = new System.Drawing.Point(377, 29); 59 this.button1.Name = "button1"; 60 this.button1.Size = new System.Drawing.Size(75, 23); 61 this.button1.TabIndex = 1; 62 this.button1.Text = "显示"; 63 this.button1.UseVisualStyleBackColor = true; 64 this.button1.Click += new System.EventHandler(this.button1_Click); 65 // 66 // button2 67 // 68 this.button2.Location = new System.Drawing.Point(377, 85); 69 this.button2.Name = "button2"; 70 this.button2.Size = new System.Drawing.Size(75, 23); 71 this.button2.TabIndex = 2; 72 this.button2.Text = "隐藏"; 73 this.button2.UseVisualStyleBackColor = true; 74 this.button2.Click += new System.EventHandler(this.button2_Click); 75 // 76 // button3 77 // 78 this.button3.Location = new System.Drawing.Point(61, 3); 79 this.button3.Name = "button3"; 80 this.button3.Size = new System.Drawing.Size(75, 23); 81 this.button3.TabIndex = 0; 82 this.button3.Text = "button3"; 83 this.button3.UseVisualStyleBackColor = true; 84 // 85 // checkedListBox1 86 // 87 this.checkedListBox1.FormattingEnabled = true; 88 this.checkedListBox1.Location = new System.Drawing.Point(16, 32); 89 this.checkedListBox1.Name = "checkedListBox1"; 90 this.checkedListBox1.Size = new System.Drawing.Size(120, 84); 91 this.checkedListBox1.TabIndex = 1; 92 // 93 // label1 94 // 95 this.label1.AutoSize = true; 96 this.label1.Location = new System.Drawing.Point(164, 61); 97 this.label1.Name = "label1"; 98 this.label1.Size = new System.Drawing.Size(41, 12); 99 this.label1.TabIndex = 2; 100 this.label1.Text = "label1"; 101 // 102 // listBox1 103 // 104 this.listBox1.FormattingEnabled = true; 105 this.listBox1.ItemHeight = 12; 106 this.listBox1.Location = new System.Drawing.Point(16, 145); 107 this.listBox1.Name = "listBox1"; 108 this.listBox1.Size = new System.Drawing.Size(120, 88); 109 this.listBox1.TabIndex = 3; 110 // 111 // linkLabel1 112 // 113 this.linkLabel1.AutoSize = true; 114 this.linkLabel1.Location = new System.Drawing.Point(222, 81); 115 this.linkLabel1.Name = "linkLabel1"; 116 this.linkLabel1.Size = new System.Drawing.Size(65, 12); 117 this.linkLabel1.TabIndex = 4; 118 this.linkLabel1.TabStop = true; 119 this.linkLabel1.Text = "linkLabel1"; 120 // 121 // monthCalendar1 122 // 123 this.monthCalendar1.Location = new System.Drawing.Point(96, 183); 124 this.monthCalendar1.Name = "monthCalendar1"; 125 this.monthCalendar1.TabIndex = 5; 126 // 127 // Form1 128 // 129 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 130 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 131 this.ClientSize = new System.Drawing.Size(567, 453); 132 this.Controls.Add(this.button2); 133 this.Controls.Add(this.button1); 134 this.Controls.Add(this.panel1); 135 this.Name = "Form1"; 136 this.Text = "Form1"; 137 this.panel1.ResumeLayout(false); 138 this.panel1.PerformLayout(); 139 this.ResumeLayout(false); 140 141 } 142 143 #endregion 144 145 private System.Windows.Forms.Panel panel1; 146 private System.Windows.Forms.Button button1; 147 private System.Windows.Forms.Button button2; 148 private System.Windows.Forms.MonthCalendar monthCalendar1; 149 private System.Windows.Forms.LinkLabel linkLabel1; 150 private System.Windows.Forms.ListBox listBox1; 151 private System.Windows.Forms.Label label1; 152 private System.Windows.Forms.CheckedListBox checkedListBox1; 153 private System.Windows.Forms.Button button3; 154 } 155 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using System.Windows.Forms; 6 7 namespace _13_Panel 8 { 9 static class Program 10 { 11 /// <summary> 12 /// 应用程序的主入口点。 13 /// </summary> 14 [STAThread] 15 static void Main() 16 { 17 Application.EnableVisualStyles(); 18 Application.SetCompatibleTextRenderingDefault(false); 19 Application.Run(new Form1()); 20 } 21 } 22 }
14、记事儿本应用程序
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.IO; 7 using System.Linq; 8 using System.Text; 9 using System.Threading.Tasks; 10 using System.Windows.Forms; 11 12 namespace _14_记事儿本应用程序 13 { 14 public partial class Form1 : Form 15 { 16 public Form1() 17 { 18 InitializeComponent(); 19 } 20 21 private void Form1_Load(object sender, EventArgs e) 22 { 23 //加载程序的时候 隐藏panel 24 panel1.Visible = false; 25 //取消文本框的自动换行功能 26 textBox1.WordWrap = false; 27 } 28 29 30 /// <summary> 31 /// 点击按钮的时候 隐藏panel 32 /// </summary> 33 /// <param name="sender"></param> 34 /// <param name="e"></param> 35 private void button1_Click(object sender, EventArgs e) 36 { 37 panel1.Visible = false; 38 } 39 40 private void 显示ToolStripMenuItem_Click(object sender, EventArgs e) 41 { 42 panel1.Visible = true; 43 } 44 45 private void 影藏ToolStripMenuItem_Click(object sender, EventArgs e) 46 { 47 panel1.Visible = false; 48 } 49 50 List<string> list = new List<string>(); 51 /// <summary> 52 /// 打开对话框 53 /// </summary> 54 /// <param name="sender"></param> 55 /// <param name="e"></param> 56 private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) 57 { 58 OpenFileDialog ofd = new OpenFileDialog(); 59 ofd.Title = "请选择要打开的文本文件"; 60 ofd.InitialDirectory = @"C:\Users\SpringRain\Desktop"; 61 ofd.Multiselect = true; 62 ofd.Filter = "文本文件|*.txt|所有文件|*.*"; 63 ofd.ShowDialog(); 64 65 //获得用户选中的文件的路径 66 string path = ofd.FileName; 67 //将文件的全路径存储到泛型集合中 68 list.Add(path); 69 //获得了用户打开文件的文件名 70 string fileName = Path.GetFileName(path); 71 //将文件名放到ListBox中 72 listBox1.Items.Add(fileName); 73 if (path == "") 74 { 75 return; 76 } 77 using (FileStream fsRead = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read)) 78 { 79 byte[] buffer = new byte[1024 * 1024 * 5]; 80 int r = fsRead.Read(buffer, 0, buffer.Length); 81 textBox1.Text = Encoding.Default.GetString(buffer, 0, r); 82 } 83 } 84 85 86 87 /// <summary> 88 /// 保存对话框 89 /// </summary> 90 /// <param name="sender"></param> 91 /// <param name="e"></param> 92 private void 保存ToolStripMenuItem_Click(object sender, EventArgs e) 93 { 94 SaveFileDialog sfd = new SaveFileDialog(); 95 sfd.InitialDirectory = @"C:\Users\SpringRain\Desktop"; 96 sfd.Title = "请选择要保存的文件路径"; 97 sfd.Filter = "文本文件|*.txt|所有文件|*.*"; 98 sfd.ShowDialog(); 99 100 //获得用户要保存的文件的路径 101 string path = sfd.FileName; 102 if (path == "") 103 { 104 return; 105 } 106 using (FileStream fsWrite = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write)) 107 { 108 byte[] buffer = Encoding.Default.GetBytes(textBox1.Text); 109 fsWrite.Write(buffer, 0, buffer.Length); 110 } 111 MessageBox.Show("保存成功"); 112 } 113 114 private void 自动换行ToolStripMenuItem_Click(object sender, EventArgs e) 115 { 116 if (自动换行ToolStripMenuItem.Text == "☆自动换行") 117 { 118 textBox1.WordWrap = true; 119 自动换行ToolStripMenuItem.Text = "★取消自动换行"; 120 } 121 else if (自动换行ToolStripMenuItem.Text == "★取消自动换行") 122 { 123 textBox1.WordWrap = false; 124 自动换行ToolStripMenuItem.Text = "☆自动换行"; 125 } 126 } 127 128 private void 字体ToolStripMenuItem_Click(object sender, EventArgs e) 129 { 130 131 FontDialog fd = new FontDialog(); 132 fd.ShowDialog(); 133 textBox1.Font = fd.Font; 134 } 135 136 private void 颜色ToolStripMenuItem_Click(object sender, EventArgs e) 137 { 138 ColorDialog cd = new ColorDialog(); 139 cd.ShowDialog(); 140 textBox1.ForeColor = cd.Color; 141 } 142 143 144 145 /// <summary> 146 /// 双击打开对应的文件 147 /// </summary> 148 /// <param name="sender"></param> 149 /// <param name="e"></param> 150 private void listBox1_DoubleClick(object sender, EventArgs e) 151 { 152 //要获得双击的文件所对应的全路径 153 string path = list[listBox1.SelectedIndex]; 154 using (FileStream fsRead = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read)) 155 { 156 byte[] buffer = new byte[1024 * 1024 * 5]; 157 int r = fsRead.Read(buffer, 0, buffer.Length); 158 159 textBox1.Text = Encoding.Default.GetString(buffer, 0, r); 160 } 161 } 162 } 163 }
1 namespace _14_记事儿本应用程序 2 { 3 partial class Form1 4 { 5 /// <summary> 6 /// 必需的设计器变量。 7 /// </summary> 8 private System.ComponentModel.IContainer components = null; 9 10 /// <summary> 11 /// 清理所有正在使用的资源。 12 /// </summary> 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> 14 protected override void Dispose(bool disposing) 15 { 16 if (disposing && (components != null)) 17 { 18 components.Dispose(); 19 } 20 base.Dispose(disposing); 21 } 22 23 #region Windows 窗体设计器生成的代码 24 25 /// <summary> 26 /// 设计器支持所需的方法 - 不要 27 /// 使用代码编辑器修改此方法的内容。 28 /// </summary> 29 private void InitializeComponent() 30 { 31 this.menuStrip1 = new System.Windows.Forms.MenuStrip(); 32 this.文件ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 33 this.打开ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 34 this.保存ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 35 this.格式ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 36 this.自动换行ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 37 this.样式ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 38 this.字体ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 39 this.颜色ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 40 this.打开记录ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 41 this.显示ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 42 this.影藏ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 43 this.textBox1 = new System.Windows.Forms.TextBox(); 44 this.listBox1 = new System.Windows.Forms.ListBox(); 45 this.panel1 = new System.Windows.Forms.Panel(); 46 this.button1 = new System.Windows.Forms.Button(); 47 this.menuStrip1.SuspendLayout(); 48 this.panel1.SuspendLayout(); 49 this.SuspendLayout(); 50 // 51 // menuStrip1 52 // 53 this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 54 this.文件ToolStripMenuItem, 55 this.格式ToolStripMenuItem, 56 this.样式ToolStripMenuItem, 57 this.打开记录ToolStripMenuItem}); 58 this.menuStrip1.Location = new System.Drawing.Point(0, 0); 59 this.menuStrip1.Name = "menuStrip1"; 60 this.menuStrip1.Size = new System.Drawing.Size(588, 25); 61 this.menuStrip1.TabIndex = 0; 62 this.menuStrip1.Text = "menuStrip1"; 63 // 64 // 文件ToolStripMenuItem 65 // 66 this.文件ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 67 this.打开ToolStripMenuItem, 68 this.保存ToolStripMenuItem}); 69 this.文件ToolStripMenuItem.Name = "文件ToolStripMenuItem"; 70 this.文件ToolStripMenuItem.Size = new System.Drawing.Size(44, 21); 71 this.文件ToolStripMenuItem.Text = "文件"; 72 // 73 // 打开ToolStripMenuItem 74 // 75 this.打开ToolStripMenuItem.Name = "打开ToolStripMenuItem"; 76 this.打开ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); 77 this.打开ToolStripMenuItem.Text = "打开"; 78 this.打开ToolStripMenuItem.Click += new System.EventHandler(this.打开ToolStripMenuItem_Click); 79 // 80 // 保存ToolStripMenuItem 81 // 82 this.保存ToolStripMenuItem.Name = "保存ToolStripMenuItem"; 83 this.保存ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); 84 this.保存ToolStripMenuItem.Text = "保存"; 85 this.保存ToolStripMenuItem.Click += new System.EventHandler(this.保存ToolStripMenuItem_Click); 86 // 87 // 格式ToolStripMenuItem 88 // 89 this.格式ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 90 this.自动换行ToolStripMenuItem}); 91 this.格式ToolStripMenuItem.Name = "格式ToolStripMenuItem"; 92 this.格式ToolStripMenuItem.Size = new System.Drawing.Size(44, 21); 93 this.格式ToolStripMenuItem.Text = "格式"; 94 // 95 // 自动换行ToolStripMenuItem 96 // 97 this.自动换行ToolStripMenuItem.Name = "自动换行ToolStripMenuItem"; 98 this.自动换行ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); 99 this.自动换行ToolStripMenuItem.Text = "☆自动换行"; 100 this.自动换行ToolStripMenuItem.Click += new System.EventHandler(this.自动换行ToolStripMenuItem_Click); 101 // 102 // 样式ToolStripMenuItem 103 // 104 this.样式ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 105 this.字体ToolStripMenuItem, 106 this.颜色ToolStripMenuItem}); 107 this.样式ToolStripMenuItem.Name = "样式ToolStripMenuItem"; 108 this.样式ToolStripMenuItem.Size = new System.Drawing.Size(44, 21); 109 this.样式ToolStripMenuItem.Text = "样式"; 110 // 111 // 字体ToolStripMenuItem 112 // 113 this.字体ToolStripMenuItem.Name = "字体ToolStripMenuItem"; 114 this.字体ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); 115 this.字体ToolStripMenuItem.Text = "字体"; 116 this.字体ToolStripMenuItem.Click += new System.EventHandler(this.字体ToolStripMenuItem_Click); 117 // 118 // 颜色ToolStripMenuItem 119 // 120 this.颜色ToolStripMenuItem.Name = "颜色ToolStripMenuItem"; 121 this.颜色ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); 122 this.颜色ToolStripMenuItem.Text = "颜色"; 123 this.颜色ToolStripMenuItem.Click += new System.EventHandler(this.颜色ToolStripMenuItem_Click); 124 // 125 // 打开记录ToolStripMenuItem 126 // 127 this.打开记录ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 128 this.显示ToolStripMenuItem, 129 this.影藏ToolStripMenuItem}); 130 this.打开记录ToolStripMenuItem.Name = "打开记录ToolStripMenuItem"; 131 this.打开记录ToolStripMenuItem.Size = new System.Drawing.Size(68, 21); 132 this.打开记录ToolStripMenuItem.Text = "打开记录"; 133 // 134 // 显示ToolStripMenuItem 135 // 136 this.显示ToolStripMenuItem.Name = "显示ToolStripMenuItem"; 137 this.显示ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); 138 this.显示ToolStripMenuItem.Text = "显示"; 139 this.显示ToolStripMenuItem.Click += new System.EventHandler(this.显示ToolStripMenuItem_Click); 140 // 141 // 影藏ToolStripMenuItem 142 // 143 this.影藏ToolStripMenuItem.Name = "影藏ToolStripMenuItem"; 144 this.影藏ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); 145 this.影藏ToolStripMenuItem.Text = "隐藏"; 146 this.影藏ToolStripMenuItem.Click += new System.EventHandler(this.影藏ToolStripMenuItem_Click); 147 // 148 // textBox1 149 // 150 this.textBox1.Location = new System.Drawing.Point(0, 29); 151 this.textBox1.Multiline = true; 152 this.textBox1.Name = "textBox1"; 153 this.textBox1.Size = new System.Drawing.Size(588, 443); 154 this.textBox1.TabIndex = 1; 155 // 156 // listBox1 157 // 158 this.listBox1.FormattingEnabled = true; 159 this.listBox1.ItemHeight = 12; 160 this.listBox1.Location = new System.Drawing.Point(3, 7); 161 this.listBox1.Name = "listBox1"; 162 this.listBox1.Size = new System.Drawing.Size(133, 436); 163 this.listBox1.TabIndex = 2; 164 this.listBox1.DoubleClick += new System.EventHandler(this.listBox1_DoubleClick); 165 // 166 // panel1 167 // 168 this.panel1.Controls.Add(this.button1); 169 this.panel1.Controls.Add(this.listBox1); 170 this.panel1.Location = new System.Drawing.Point(0, 29); 171 this.panel1.Name = "panel1"; 172 this.panel1.Size = new System.Drawing.Size(196, 443); 173 this.panel1.TabIndex = 3; 174 // 175 // button1 176 // 177 this.button1.Location = new System.Drawing.Point(143, 98); 178 this.button1.Name = "button1"; 179 this.button1.Size = new System.Drawing.Size(37, 123); 180 this.button1.TabIndex = 3; 181 this.button1.Text = "<<"; 182 this.button1.UseVisualStyleBackColor = true; 183 this.button1.Click += new System.EventHandler(this.button1_Click); 184 // 185 // Form1 186 // 187 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 188 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 189 this.ClientSize = new System.Drawing.Size(588, 472); 190 this.Controls.Add(this.panel1); 191 this.Controls.Add(this.textBox1); 192 this.Controls.Add(this.menuStrip1); 193 this.MainMenuStrip = this.menuStrip1; 194 this.Name = "Form1"; 195 this.Text = "Form1"; 196 this.Load += new System.EventHandler(this.Form1_Load); 197 this.menuStrip1.ResumeLayout(false); 198 this.menuStrip1.PerformLayout(); 199 this.panel1.ResumeLayout(false); 200 this.ResumeLayout(false); 201 this.PerformLayout(); 202 203 } 204 205 #endregion 206 207 private System.Windows.Forms.MenuStrip menuStrip1; 208 private System.Windows.Forms.ToolStripMenuItem 文件ToolStripMenuItem; 209 private System.Windows.Forms.ToolStripMenuItem 打开ToolStripMenuItem; 210 private System.Windows.Forms.ToolStripMenuItem 保存ToolStripMenuItem; 211 private System.Windows.Forms.ToolStripMenuItem 格式ToolStripMenuItem; 212 private System.Windows.Forms.ToolStripMenuItem 自动换行ToolStripMenuItem; 213 private System.Windows.Forms.ToolStripMenuItem 样式ToolStripMenuItem; 214 private System.Windows.Forms.ToolStripMenuItem 字体ToolStripMenuItem; 215 private System.Windows.Forms.ToolStripMenuItem 颜色ToolStripMenuItem; 216 private System.Windows.Forms.ToolStripMenuItem 打开记录ToolStripMenuItem; 217 private System.Windows.Forms.ToolStripMenuItem 显示ToolStripMenuItem; 218 private System.Windows.Forms.ToolStripMenuItem 影藏ToolStripMenuItem; 219 private System.Windows.Forms.TextBox textBox1; 220 private System.Windows.Forms.ListBox listBox1; 221 private System.Windows.Forms.Panel panel1; 222 private System.Windows.Forms.Button button1; 223 } 224 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using System.Windows.Forms; 6 7 namespace _14_记事儿本应用程序 8 { 9 static class Program 10 { 11 /// <summary> 12 /// 应用程序的主入口点。 13 /// </summary> 14 [STAThread] 15 static void Main() 16 { 17 Application.EnableVisualStyles(); 18 Application.SetCompatibleTextRenderingDefault(false); 19 Application.Run(new Form1()); 20 } 21 } 22 }
15进程
1 using System; 2 using System.Collections.Generic; 3 using System.Diagnostics; 4 using System.Linq; 5 using System.Text; 6 using System.Threading.Tasks; 7 8 namespace _15进程 9 { 10 class Program 11 { 12 static void Main(string[] args) 13 { 14 //获得当前程序中所有正在运行的进程 15 //Process[] pros = Process.GetProcesses(); 16 //foreach (var item in pros) 17 //{ 18 // //不试的不是爷们 19 // //item.Kill(); 20 // Console.WriteLine(item); 21 //} 22 23 //通过进程打开一些应用程序 24 //Process.Start("calc"); 25 //Process.Start("mspaint"); 26 //Process.Start("notepad"); 27 //Process.Start("iexplore", "http://www.baidu.com"); 28 29 //通过一个进程打开指定的文件 30 31 ProcessStartInfo psi = new ProcessStartInfo(@"C:\Users\SpringRain\Desktop\1.exe"); 32 33 //第一:创建进程对象 34 Process p = new Process(); 35 p.StartInfo = psi; 36 p.Start(); 37 // p.star 38 39 40 Console.ReadKey(); 41 } 42 } 43 }
16、线程
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading; 6 using System.Threading.Tasks; 7 8 namespace _16_线程 9 { 10 class Program 11 { 12 static void Main(string[] args) 13 { 14 Thread.Sleep(3000); 15 Console.WriteLine("Hello World"); 16 Console.ReadKey(); 17 } 18 } 19 }
17、线程
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading; 9 using System.Threading.Tasks; 10 using System.Windows.Forms; 11 12 namespace _17_线程 13 { 14 public partial class Form1 : Form 15 { 16 public Form1() 17 { 18 InitializeComponent(); 19 } 20 Thread th; 21 private void button1_Click(object sender, EventArgs e) 22 { 23 //创建一个线程去执行这个方法 24 th = new Thread(Test); 25 //标记这个线程准备就绪了,可以随时被执行。具体什么时候执行这个线程, 26 //由cpu决定 27 //将线程设置为后台线程 28 th.IsBackground = true; 29 th.Start(); 30 th.Abort(); 31 th.Start(); 32 33 } 34 35 private void Test() 36 { 37 for (int i = 0; i < 10000; i++) 38 { 39 //Console.WriteLine(i); 40 textBox1.Text = i.ToString(); 41 } 42 } 43 44 private void Form1_Load(object sender, EventArgs e) 45 { 46 //取消跨线程的访问 47 Control.CheckForIllegalCrossThreadCalls = false; 48 } 49 50 private void Form1_FormClosing(object sender, FormClosingEventArgs e) 51 { 52 //当你点击关闭窗体的时候,判断新线程是否为null 53 if (th != null) 54 { 55 //结束这个线程 56 th.Abort(); 57 } 58 } 59 60 } 61 }
1 namespace _17_线程 2 { 3 partial class Form1 4 { 5 /// <summary> 6 /// 必需的设计器变量。 7 /// </summary> 8 private System.ComponentModel.IContainer components = null; 9 10 /// <summary> 11 /// 清理所有正在使用的资源。 12 /// </summary> 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> 14 protected override void Dispose(bool disposing) 15 { 16 if (disposing && (components != null)) 17 { 18 components.Dispose(); 19 } 20 base.Dispose(disposing); 21 } 22 23 #region Windows 窗体设计器生成的代码 24 25 /// <summary> 26 /// 设计器支持所需的方法 - 不要 27 /// 使用代码编辑器修改此方法的内容。 28 /// </summary> 29 private void InitializeComponent() 30 { 31 this.button1 = new System.Windows.Forms.Button(); 32 this.textBox1 = new System.Windows.Forms.TextBox(); 33 this.SuspendLayout(); 34 // 35 // button1 36 // 37 this.button1.Location = new System.Drawing.Point(168, 70); 38 this.button1.Name = "button1"; 39 this.button1.Size = new System.Drawing.Size(75, 23); 40 this.button1.TabIndex = 0; 41 this.button1.Text = "button1"; 42 this.button1.UseVisualStyleBackColor = true; 43 this.button1.Click += new System.EventHandler(this.button1_Click); 44 // 45 // textBox1 46 // 47 this.textBox1.Location = new System.Drawing.Point(168, 137); 48 this.textBox1.Name = "textBox1"; 49 this.textBox1.Size = new System.Drawing.Size(311, 21); 50 this.textBox1.TabIndex = 1; 51 // 52 // Form1 53 // 54 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 55 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 56 this.ClientSize = new System.Drawing.Size(638, 390); 57 this.Controls.Add(this.textBox1); 58 this.Controls.Add(this.button1); 59 this.Name = "Form1"; 60 this.Text = "Form1"; 61 this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); 62 this.Load += new System.EventHandler(this.Form1_Load); 63 this.ResumeLayout(false); 64 this.PerformLayout(); 65 66 } 67 68 #endregion 69 70 private System.Windows.Forms.Button button1; 71 private System.Windows.Forms.TextBox textBox1; 72 } 73 }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using System.Windows.Forms; 6 7 namespace _17_线程 8 { 9 static class Program 10 { 11 /// <summary> 12 /// 应用程序的主入口点。 13 /// </summary> 14 [STAThread] 15 static void Main() 16 { 17 Application.EnableVisualStyles(); 18 Application.SetCompatibleTextRenderingDefault(false); 19 Application.Run(new Form1()); 20 } 21 } 22 }
标签:
原文地址:http://www.cnblogs.com/liuslayer/p/4713560.html