<winform>简单应用控件

       对于初学者来说,怎样简单应用Winform中的控件,不是一件容易的事。我浅显的讲讲应用,首先双击VS2012--->FILE--->New--->Project--->Windows Forms Application。在Form中可以设计布局了,例如选择工具栏中的Button/Label/TextBox等控件,将其拖入Form中进行设计。我选择上次做的软件来举例。所以软件布局如下:

                    

        其中,Label控件就是将想输入的字母写入它的Text属性,然而要想输入&并不容易,就是多写入一个&,例如INC&DEC要在Text属性中写入INC&&DEC。Button控件的字母是通过Text属性,设置Enabled属性就会改变Button的色彩。在TextBox中通过设置Text属性来设初始值。

        最后,Button/Form控件可以通过双击出它的Click事件,从中可以编写相关代码。例如:

 private void btnStart_Click(object sender, EventArgs e)

        {

            btnStart.Enabled = false;

            btnStop.Enabled = true;

            btnReset.Enabled = true;

            btnClose.Enabled = true;

            




            timer1.Enabled = true;   

            if (time == 1)

            {

                textBox2.Text = "INC & DEC :Increasing ";

                StreamWriter aw = new StreamWriter("d://c.text");  

                aw.WriteLine("1");

                aw.Close();

            }

            else if(time == 2)

            {

                textBox2.Text = "INC & DEC : Decreasing ";

                StreamWriter aw = new StreamWriter("d://c.text"); 

                aw.WriteLine("6");

                aw.Close();

            }                              //Send start information

       

        }

 

posted @ 2012-10-08 17:20  伍锋  阅读(202)  评论(0编辑  收藏  举报