码迷,mamicode.com
首页 > Windows程序 > 详细

C#Winform基础 一个button按钮调用另外一个button按钮的代码

时间:2016-10-06 12:55:38      阅读:414      评论:0      收藏:0      [点我收藏+]

标签:

 

 

1、UI

 

技术分享

 

2、通过代码调用

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 
11 namespace WindowsFormsApplication1
12 {
13     public partial class Form1 : Form
14     {
15         public Form1()
16         {
17             InitializeComponent();
18         }
19 
20         private void button1_Click(object sender, EventArgs e)
21         {
22             //sender object类型,里面装的是button1,这就是关键一点了。
23             Button btn = (Button)sender;
24             textBox1.Text = btn.Text;
25         }
26 
27         private void button2_Click(object sender, EventArgs e)
28         {
29             //这个sender里面装的是button2
30             button1_Click(sender, e);
31         }
32 
33         private void Form1_Load(object sender, EventArgs e)
34         {
35 
36         }
37     }
38 }

 

3、通过属性面板的邻居:事件调用

技术分享

 

 4、

 

 

效果1

 技术分享

 

 

效果2

 技术分享

 

效果3

技术分享

C#Winform基础 一个button按钮调用另外一个button按钮的代码

标签:

原文地址:http://www.cnblogs.com/jinlingzi/p/5933650.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!