C#多項測試(class,updateformx2,centertoscreen)

  • 327
  • 0

class,updateformx2,centertoscreen

 

  先上程式碼 : 

    public partial class Form1 : Form
    {
        //實體化MyMath
        C_MyMath MyMath = new C_MyMath();
        //宣告委派
        public delegate void d_UpdateForm(string s1);

        public Form1()
        {
            InitializeComponent();
            Initialize();
        }

        //初始化的sub(void)
        public void Initialize()
        {
            this.CenterToScreen();
            this.Text = "Form String";
        }
        //委派
        private void btnUpdateForm2_Click(object sender, EventArgs e)
        {
            DoUpdateForm();
        }
        //使用委派修改label1
        public void DoUpdateForm()
        {
            d_UpdateForm u = new d_UpdateForm(UpdateForm);
            string Sum;
            Sum = MyMath.AddNumbers(12, 13).ToString();
            this.BeginInvoke(u,Sum);
        }
        //非委派
        private void btnUpdateForm1_Click(object sender, EventArgs e)
        {
            UpdateForm(MyMath.AddNumbers(5, 10).ToString());
        }
        //直接修改label1
        public void UpdateForm(string s1)
        {
            label1.Text = s1;
        }

    }

 多項測試,目前語法還不熟悉,宣告的地方還必須查網路,Class的宣告也要在熟悉一點