首页 > 代码库 > c# 第一个实例 通哥

c# 第一个实例 通哥

  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 
 12 namespace tongge
 13 {
 14     public partial class Form1 : Form
 15     {
 16         public Form1()
 17         {
 18             InitializeComponent();
 19         }
 20 
 21         public double a, b, c;
 22         string path;
 23 
 24         private void textBox1_TextChanged(object sender, EventArgs e)
 25         {
 26             try
 27             {
 28                 a = Convert.ToDouble(textBox1.Text);
 29             }
 30             catch (Exception)
 31             {
 32                 DialogResult dr = MessageBox.Show("您输入的高度不是数字", "错误提示", MessageBoxButtons.OKCancel);
 33                 throw;
 34             }
 35 
 36         }
 37 
 38         private void textBox2_TextChanged(object sender, EventArgs e)
 39         {
 40             b = Convert.ToDouble(textBox2.Text);
 41         }
 42 
 43 
 44         public void textBox3_TextChanged(object sender, EventArgs e)
 45         {
 46 
 47         }
 48 
 49         private void button1_Click(object sender, EventArgs e)
 50         {
 51 
 52             //string path = @"C:\Users\Administrator\Desktop\岩层厚度.txt";
 53 
 54             OpenFileDialog openFileDialog = new OpenFileDialog();
 55             openFileDialog.InitialDirectory = @"C:\Users\Administrator\Desktop";
 56             openFileDialog.Filter = "(*.txt)|*.txt";
 57             openFileDialog.RestoreDirectory = true;
 58             openFileDialog.FilterIndex = 1;
 59             if (openFileDialog.ShowDialog() == DialogResult.OK)
 60             {
 61                 path = openFileDialog.FileName;
 62             }
 63 
 64             string[] contents = File.ReadAllLines(path, Encoding.Default);
 65             for (int i = 0; i < contents.Length; i++)
 66             {
 67                 string[] strNew = contents[i].Split(new char[] {  , \t }, StringSplitOptions.RemoveEmptyEntries);
 68                 if (i == 0)
 69                 {
 70                     textBox1.Text = strNew[1];
 71                 }
 72                 if (i == 1)
 73                 {
 74                     textBox2.Text = strNew[1];
 75                 }
 76                 c = a + b;
 77                 textBox3.Text = Convert.ToString(c);
 78 
 79                 // Console.WriteLine("{0} {1} {2}", strNew[0], strNew[1],);
 80             }
 81         }
 82 
 83         public void Form1_Load(object sender, EventArgs e)
 84         {
 85             //textBox1.Text = "3.00";
 86             //textBox2.Text = "4.00";
 87             DialogResult dr = MessageBox.Show("欢迎使用中国矿业大学编制的软件", "欢迎使用", MessageBoxButtons.OKCancel);
 88 
 89         }
 90 
 91 
 92 
 93         private void button2_Click_1(object sender, EventArgs e)
 94         {
 95             DialogResult dr = MessageBox.Show("确认删除吗?", "提示", MessageBoxButtons.OKCancel);
 96             if (dr == DialogResult.OK)
 97             {
 98                 //用户选择确认的操作
 99                 MessageBox.Show("您选择的是【确认】");
100             }
101             else if (dr == DialogResult.Cancel)
102             {
103                 //用户选择取消的操作
104                 MessageBox.Show("您选择的是【取消】");
105             }
106 
107         }
108 
109     }
110 }

 

技术分享

 

 

技术分享

技术分享

 技术分享

 

c# 第一个实例 通哥