Click here to Skip to main content
15,887,386 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi masters,
excuse me because of the language,

i want to change the color of the form (gradient) for a while from low level of the color to the high , like a progress bar, almost like a splash screen, show the form & then hide it,
but i CAN'T :(

best wishes & dreams...
Posted
Updated 13-Sep-12 16:14pm
v2
Comments
[no name] 7-Aug-12 20:27pm    
What does "but i CAN'T" mean exactly?
Sergey Alexandrovich Kryukov 7-Aug-12 20:57pm    
...and what is "gradiant"? :-)
--SA
The_Leader 7-Aug-12 22:30pm    
it mean's i cant :)
i want to have a gradient color instead of solid color for my form's backcolor...

tnx masters.

1 solution

Override the method Form.OnPaint. In this method, use the instance of System.Drawing.Graphics passed to you via the event argument parameters, and paint on the form using its method System.Drawing.Graphics.FillRectangle. For a brush, use a gradient brush System.Drawing.Drawing2D.LinearGradientBrush.

Please see:
http://msdn.microsoft.com/en-us/library/yysstebh.aspx[^],
http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.lineargradientbrush.aspx[^].

Don't forget to dispose the objects which implement System.IDisposable. The best way of doing it and guarantee that it happens even if an exception is thrown, is using the using statement, which acts identically to the try-finally block:
http://msdn.microsoft.com/en-us/library/system.idisposable.aspx[^],
http://msdn.microsoft.com/en-us/library/yh598w02%28v=vs.100%29.aspx[^].

You may face some flicker. You can eliminate it using double buffering for the form (or other control) where you do your custom rendering:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.doublebuffered.aspx[^].

Best wishes and wake-ups… :-)

—SA
 
Share this answer
 
v3
Comments
The_Leader 7-Aug-12 22:31pm    
tnx master...
best wishes...
Sergey Alexandrovich Kryukov 8-Aug-12 0:06am    
You are welcome,
--SA

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