Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I change the colors of the controls in style XP?

Status
Not open for further replies.

mondi

Programmer
Sep 10, 2003
169
AL
I am making a project and the controls I have used are set in style XP. But I did not find a way to change the colors of the controls, I mean I don't need them in their default color (e.g. the color of the buttons not to be in gray or something like that, but in blue). I don't know if there is any way to do that, except making some controls like the buttons that would cost me a lot of time.
Thank you in advance for any help!
 
I would like also ta add an icon to the buttons in style XP, but I can't add an icon. Please any help would be very appreciated.
Thank you!

Mondi, albanian
 
to change a color of control:
public class NewClButton : Button

{

protected override void OnPaint(PaintEventArgs e)

{

base.OnPaint(e);
int borderWidth = 2; //change the width
Color borderColor = Color.Blue;
ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, borderColor, borderWidth, ButtonBorderStyle.Solid, borderColor, borderWidth,ButtonBorderStyle.Solid, borderColor, borderWidth, ButtonBorderStyle.Solid, borderColor, borderWidth, ButtonBorderStyle.Solid);

}

}

 
It didn't seem to work, at least for me. However, I need to change the color of the whole control, not just the color of the border. Is there any way how to do that?
Thanks however for your answer

Country of eagles
 
shifar has the right idea actually. You need to override the Paint method. He gave you an example using a border, but you can apply this to other drawing as well.

Take a look into the Graphics class (e.Graphics)

You can manually draw or modify settings for the controls in there.
 
I tried to everride the Paint Method. But it only changes the borders outside the button, not in it. I have set the FlatStyle property of the button to System, because in Windows XP, I want the buttons to be displayed in XP style.
Maybe this does not allow the buttons to change the colors.
I saw also an example in msdn about changing the colors of the buttons but it didn't work, or maybe I made something wrong with that. This example overrided the Paint method too.

Can anybody give me an example of changing the colors?
You would really help me a lot if you give me an answer.
Thank you

Country of eagles
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top