如何用红色,绿色和蓝色按钮更改具有生成颜色的面板的颜色 [英] How to change color of a panel with generated color from red , green and blue button click

查看:84
本文介绍了如何用红色,绿色和蓝色按钮更改具有生成颜色的面板的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过红色,绿色和蓝色按钮更改具有生成颜色的面板的颜色?

我有三个按钮和一个面板.当我按下红色和绿色按钮时,其输出颜色将显示在面板中,依此类推..........

How to change color of panel with generated color from red, green and blue button click ?

i have three button and one panel. When i press button red and green its output color will show in panel and so on..........

推荐答案

设置BackGroudColor属性单击面板上的按钮.
如果单击红色按钮,则将颜色设置为红色,依此类推.
Set the BackGroudColor property of the Panel on the button click.
If Red Button is clicked set the color as Red and so on.


您需要做的就是设置BackColor.
All you''d need to do would be to set the BackColor.
private void button2_Click(object sender, EventArgs e)
{
    panel1.BackColor = Color.Yellow;
}

private void button3_Click(object sender, EventArgs e)
{
    panel1.BackColor = Color.Red;
}


如果您想通过单击按钮来更改颜色,则
将这些事件处理程序连接到每个按钮的Clicked事件.
If you want to change color with clicks on buttons then
connect these event handlers to each button''s Clicked event.
private void btnRed_Clicked(object sender, EventArgs e)
{
   panel.BackColor = Colors.Red;
}

private void btnGreen_Clicked(object sender, EventArgs e)
{
   panel.BackColor = Colors.Green;
}

private void btnBlue_Clicked(object sender, EventArgs e)
{
   panel.BackColor = Colors.Blue;
}



为了更改按钮组合的颜色,我建议将按钮替换为checkBoxes并将此事件处理程序添加到每个checkBox的Checked事件中.



In order to change color with combination of buttons I suggest to replace buttons with checkBoxes and add this event handler to each checkBox''s Checked event.

void checkBox_Checked(object sender, EventArgs e)
{
  int state = 0;
  if(btnRed.Checked)
  {
   //001
    state += 1;
  }

  if(btnGreen.Checked)
  {
    //010
    state += 2;
  }

  if(btnBlue.Checked)
  {
    //100
    state += 4;
  }
 
  switch(state)
  {
    //red
    case 1:
       panel.BackColor = Colors.Red;
       break;
    //green
    case 2:
       panel.BackColor = Colors.Green;
       break;
    //blue
    case 4:
       panel.BackColor = Colors.Red;
       break;
    //red + green
    case 3:
        //whatever you think is appropriate 
        break;
    //
    //code for other combinations goes here
    //

    default:
        panel.BackColor = SystemColors.Control;
  }
}


这篇关于如何用红色,绿色和蓝色按钮更改具有生成颜色的面板的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆