Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to set back color to my textbox.

If I write an event to create and access a color dialog box I can set the color which I want.

But my problem is that while opening the color dialog box the default selected value should be the color which is current used for the selected text box.

Such as generally textbox backcolor would be white.

When I write an event to open color dialog box white color should be highlighted

How to do this
Posted

I think that solves your problem:

colorDlg.Color=txtAText.Backcolor;


see: ColorDialog[^]
 
Share this answer
 
Comments
KUMAR619 12-Mar-14 9:50am    
Thanks

Now if I select a new color apart from the colors in the default palette it should be added to customcolors
Vedat Ozan Oner 12-Mar-14 10:13am    
I couldn't understand. Is that a question?
KUMAR619 13-Mar-14 0:40am    
Yes if my default textbox backcolor doesn't support basic 48 colors then then color should be automatically added to the custom colors.

Is it clear
Vedat Ozan Oner 13-Mar-14 5:57am    
AllowFullOpen property supports what you want, I think. If you open the link of ColorDialog, you will see that there are many options provided.
I suggest you set these ColorDialog Properties:

AnyColor = true;
FullOpen = true;

Then, when you use the ColorDialog like this:
C#
private void btnOpenColorDialog_Click(object sender, EventArgs e)
{
    colorDialog1.Color = textBox1.BackColor;

    colorDialog1.ShowDialog();

    textBox1.BackColor = colorDialog1.Color;
}
If the current BackColor of the TextBox is not one of the standard 48 solid colors, at least the color-picker displayed on the right will show you the current TextBox BackColor.

To make custom colors you define persist in the 16-slots provided for custom color definitions you need to do several things:

0. select a slot from the 16 slots for custom colors.

1. move the cross-hairs to select a color

2. set the color intensity using the vertical slider on the far right

3. click somewhere in that vertical slider

4. click the "Add to custom colors" button

5. click okay
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900