C# 基础(6)--Winform

WinForm 简称,Windows Form ,调用.Net框架。

 

Return 只是退出当前方法。

 

MessageBox.Show("输入的Email地址是非法的!");

 

把整型转换为String 类型:

两种方法:

int sum ;

string StrSum = Sum.ToString();

String StrSum = Convert.ToString()

 

设置断点的一般方法:

哪出错在哪设置断点,看相关变量的值的变化。

 

Int.TryParse()的用法

如果能转换为int类型,则返回值为true,反之为false

  if (int.TryParse(str1, out  num1) == false)//判断输入的数是不是合法的整数

            {

                MessageBox.Show("第一个数不是合法的整数");

          }

comboBox2.Items.Clear();//清空旧数据

comboBox2.Items.Add("南京");//添加项目

 

throw new  Exception ("未知的错误!");

// 摘要:

        //     使用指定的错误信息初始化 System.Exception 类的新实例。

        //

        // 参数:

        //   message:

        //     描述错误的消息。

 

 

追加文本

textBox4.AppendText( DateTime.Now.ToString() + " "); //追加文本

            //textBox4.Text = textBox4.Text + DateTime.Now.ToString() + " ";//速度特点慢,占用内存

 

把多行文本赋给字符串数组

private void button1_Click(object sender, EventArgs e)

        {

            // string s = txtBox1.Text;//按照 进行Split

            string[] lines = txtBox1.Lines;

            string maxName = "";

            int maxScore = -1;

            foreach (string line in lines)

            {

                string[] strs = line.Split('=');

                string name = strs[0];

                string strScore = strs[1];

                int score = Convert.ToInt32(strScore );

                if (score >maxScore)

                {

                    maxName = name;

                    maxScore = score;

                }

            }

            MessageBox.Show(string .Format ("{0}是第1名,成绩是{1}。",maxName ,maxScore ));

        }

 

 

ComboBox 下拉列表:

MessageBox . Show(Convert.ToString(comboBox1 .SelectedItem)); //选择值

             MessageBox .Show(Convert.ToString(comboBox1.SelectedText));//数据库中会用到

             MessageBox.Show(Convert.ToString(comboBox1.SelectedValue));//数据库中会哦用到

             MessageBox.Show(Convert.ToString(comboBox1.SelectedIndex));//选择的第几项


判断字符串是否一致:

strUser.Equals("admin", StringComparison.OrdinalIgnoreCase );

摘要:

        //     确定此字符串是否与指定的 System.String 对象具有相同的值。参数指定区域性、大小写以及比较所用的排序规则。

        //

        // 参数:

        //   comparisonType:

        //     System.StringComparison 值之一。

        //

        //   value:

        //     一个 System.String 对象。

        //

        // 返回结果:

        //     如果 value 参数的值与此字符串相同,则为 true;否则为 false。

 

局部变量与字段

局部变量每次运行完毕后,变量的值都会被销毁,下次再运行,会重新初始化。

而类字段,只要是一个对象,你们只要对象不销毁,就会一直保持对象的字段值。

原文地址:https://www.cnblogs.com/sly-tongtong/p/3688260.html