码迷,mamicode.com
首页 > Windows程序 > 详细

c# 第一个实例 通哥

时间:2016-11-11 00:03:30      阅读:441      评论:0      收藏:0      [点我收藏+]

标签:win   img   system   file   bsp   ons   message   ada   .text   

  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# 第一个实例 通哥

标签:win   img   system   file   bsp   ons   message   ada   .text   

原文地址:http://www.cnblogs.com/zhubinglong/p/6052545.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!