积极答复者
转换页面以后如何让按钮保持红色?

问题
-
哈喽,哈喽
早上好啊
现在遇到这么一个问题。
1)我在form1中做了一个白色的按钮,点下去以后呢,这个按钮就变成红色了,这个是正常的。
2)但是,我一旦转换页面进入了form2窗体后,再返回form1窗体,发现,这个按钮又变成白色了。我要再次点击它才能变为红色,但是我再转换页面回来,它又恢复白色了
我的问题就是,不管我如何转换页面,我希望只点击一次按钮,她就一直保持红色。
private void button5_Click(object sender, EventArgs e) { button5.BackColor = Color.Red; }
答案
-
Hi,
我写了一个demo,演示效果可以看我的动态图。
代码如下:
public Form1() { InitializeComponent(); } Form form3 = new Form(); private void button1_Click(object sender, EventArgs e) { button1.BackColor = Color.Red; Button btn = new Button(); btn.Text = "show"; btn.Size = new Size(100, 50); btn.Location = new Point(100, 100); btn.Click += Btn_Click; form3.Controls.Add(btn); form3.Show(); this.Hide(); } private void Btn_Click(object sender, EventArgs e) { this.Show(); }
Best Regards,
Hart
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
- 已标记为答案 绿绿山水 2018年1月31日 3:54
全部回复
-
Hi,
你能把你的代码放到one drive 上面吗? 请不要包含私人信息。 我这边测试是没有问题的。
你可以看我的截图。
Best Regards,
Hart
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
-
Hi,
代码写的简单,粗暴。
private void button1_Click(object sender, EventArgs e) { button1.BackColor = Color.Red; } private void button2_Click(object sender, EventArgs e) { Form form2 = new Form(); form2.Show(); }
Best Regards,
Hart
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
-
Hi,
不明白你的需求,不明白你最终想要实现什么? 几个form 这些form的先后顺序,这些都是不知道的。
不过我觉得你带有红色button 按钮的form,肯定是被你销毁了,不然颜色会一直是红色。
Best Regards,
Hart
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
-
我知道为什么了,但是不知道该怎么解决这个问题:
我在form2窗体返回按钮的代码里创建了新的form1的对象,所以返回了新创建的form1窗体,所以按钮是白色的,而老的form1窗体按钮仍然是红色的,再返回时就有2 个form1窗体,如果我不重新创建form1窗体,我就没法返回到form1窗体。
我该怎么办呢?
private void button1_Click(object sender, EventArgs e) { this.Hide(); Form2 frm2 = new Form2(); frm2.Show(); }
private void button1_Click_1(object sender, EventArgs e) { this.Close(); Form1 frm1 = new Form1(); frm1.Show(); }
-
Hi,
我写了一个demo,演示效果可以看我的动态图。
代码如下:
public Form1() { InitializeComponent(); } Form form3 = new Form(); private void button1_Click(object sender, EventArgs e) { button1.BackColor = Color.Red; Button btn = new Button(); btn.Text = "show"; btn.Size = new Size(100, 50); btn.Location = new Point(100, 100); btn.Click += Btn_Click; form3.Controls.Add(btn); form3.Show(); this.Hide(); } private void Btn_Click(object sender, EventArgs e) { this.Show(); }
Best Regards,
Hart
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
- 已标记为答案 绿绿山水 2018年1月31日 3:54
-
亲爱的版主,您好
1) one drive 是什么呀?如何操作才能把代码放在one drive 上面呢?
one drive 就是类似百度云这种,当然还有更多功能,你可以把代码放在上面,再把链接给别人,别人就能看到这个内容。
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.