体验Windows Forms

来源:互联网 发布:编c语言用什么软件 编辑:程序博客网 时间:2024/06/02 23:28


在窗体中创建一个新窗体
新建一个框体,将IsMdiContainer属性设置为True
MainMenuStrip属性与ContextmenuStrip控件相关联
 private void newToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Form2 frm = new Form2();
            frm.MdiParent = this;
            frm.Show();
        }
 
层叠排列
private void cToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.LayoutMdi(MdiLayout.Cascade);
        }

水平排列
private void hToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.LayoutMdi(MdiLayout.TileHorizontal);
        }

 MessageBox.Show("Help!","Help",MessageBoxButtons.OK,MessageBoxIcon.Information);
内容,标题,按钮样式,图标样式

按钮相互加载事件
        private void button1_Click(object sender, EventArgs e)
        {
            this.button2.Click+=new EventHandler(button2_Click);
        }
        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("You Click button2");
            this.button1.Click+=new EventHandler(btn1_Click2);
        }
        private void btn1_Click2(object sender, EventArgs e)
        {
            MessageBox.Show("You Click button1");
        }

继承
public static int Add(int a, int b)
  {
      return a + b;
 }

[WebMethod]
 public int Add(int a, int b) {
 return a + b;
 }

#region  Add
 private void button1_Click(object sender, EventArgs e)
 {
      int a = ClassLibrary1.Class1.Add(int.Parse(this.textBox1.Text), int.Parse(this.textBox2.Text));
       MessageBox.Show(a.ToString(), "Result", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); 
       localhost.Service srv = new WindowsApplication3.localhost.Service();
       int a = srv.Add(int.Parse (this.textBox1.Text),int.Parse (this.textBox2.Text));
       MessageBox.Show(a.ToString());
}
#endregion

原创粉丝点击