C#自學之路19

來源:互聯網
上載者:User

標籤:private   圖片   public   風格   

19.按鈕控制項

  1.常用的屬性。

a.Text屬性。該屬性設定在按鈕上顯示文本。

b.FlatStyle屬性。該屬性指定按鈕的外觀風格。

c.Image屬性。該屬性指定在按鈕上顯示圖形。

d.ImageAlign屬性。該屬性可以調節圖片在按鈕上的位置。

e.Enable屬性。該屬性是否可用,不可用則用灰色表示。

f.Visiable屬性。該屬性是否可見,不可見則隱藏。


在加上視窗的單擊,載入,關閉等事件,如下。

namespace WindowsFormsApplication3

{

    public partial class Form1 : Form

    {

        private int ncount = 50;


        public Form1()

        {

            InitializeComponent();

        }


        private void Form1_Load(object sender, EventArgs e)

        {

            this.ncount = 50;

            this.ShowCounter();

            this.BackColor = Color.Red;

        }


        private void ShowCounter()

        {

            string strMsg = this.ncount.ToString( "D8" );

            this.label1.Text = strMsg;

        }


        private void button1_Click(object sender, EventArgs e)

        {

            this.ncount++;

            this.ShowCounter();

        }


        private void button2_Click(object sender, EventArgs e)

        {

            this.ncount--;

            this.ShowCounter();

        }


        private void button3_Click(object sender, EventArgs e)

        {

            string strMsg = "當前計數為:" + this.ncount.ToString( "D8" );

            MessageBox.Show( strMsg,"提示" );

        }


        private void Form1_Click(object sender, EventArgs e)

        {

            MessageBox.Show( "單擊了視窗!");

        }


        private void Form1_FormClosing(object sender, FormClosingEventArgs e)

        {

            DialogResult dr = MessageBox.Show( "是否關閉視窗?","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Warning );

            if (dr == DialogResult.Yes)

            {

                e.Cancel = false;

            }


            else

            {

                e.Cancel = true;

            }

        }

    }

}


650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/5F/DB/wKiom1UqZNzBEq0AAADVPCri96o813.jpg" title="ET4D3%M7`3W3{W)00}S1WNB.png " alt="wKiom1UqZNzBEq0AAADVPCri96o813.jpg" />

本文出自 “郭俊的部落格” 部落格,轉載請與作者聯絡!

C#自學之路19

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.