如何调出拾色器Pallete C#

时间:2014-05-04 09:50:22

标签: c# colors textbox

所以这就是我想要执行的: 用户从“背景颜色”菜单中选择一种颜色。这会调出颜色托盘并且用户选择自定义RGB颜色,此颜色将是新的textboxMain.BackColor

1 个答案:

答案 0 :(得分:1)

来自Microsoft ColorDialog Class

private void button1_Click(object sender, System.EventArgs e)
{
    ColorDialog MyDialog = new ColorDialog();
    // Keeps the user from selecting a custom color.
    MyDialog.AllowFullOpen = false;
    // Allows the user to get help. (The default is false.)
    MyDialog.ShowHelp = true;
    // Sets the initial color select to the current text color.
    MyDialog.Color =  textboxMain.BackColor;

    // Update the text box color if the user clicks OK  
    if (MyDialog.ShowDialog() == DialogResult.OK)
         textboxMain.BackColor =  MyDialog.Color;
}