Graduated Color Windows Forms

  • Thread starter Thread starter snesbit
  • Start date Start date
S

snesbit

I want to create form background themes similar to powerpoint.

For example, the top 1/4 of the screen would be a slightly darker (of the same color used for screen background)
and the bottom 1/4 of the screen woud be slightly darker (of the same color used for screen background.


I've seen this done for presentations and I've seen this done in presentations for the upcomming windows version, how can this be done today?
 
Seems like you could override OnPaintBackground for your Form in order to do
custom drawing. Then it wouldn't be much of a trick to use GDI+ to render
the color gradient for you.

--
I may not always have the best answers, but at least I'm not posting
questions in the wrong newsgroups...


I want to create form background themes similar to powerpoint.

For example, the top 1/4 of the screen would be a slightly darker (of the
same color used for screen background)
and the bottom 1/4 of the screen woud be slightly darker
(of the same color used for screen background.


I've seen this done for presentations and I've seen this done in
presentations for the upcomming windows version, how can this be done today?
 
snesbit said:
For example, the top 1/4 of the screen would be a slightly darker (of the
same
color used for screen background)
and the bottom 1/4 of the screen woud be slightly
darker (of the
same color used for screen background.

I've seen this done for presentations and I've seen this done in
presentations for the >upcomming windows version, how can this be done
today?

Override your form's 'OnPaint' method and use 'e.Graphics.FillRectangle' in
combination with a 'LinearGradientBrush' to draw the gradient.
 
Hi snesbit,

Thanks for your posting!!

I think "Herfried K. Wagner [MVP]" gives you a good direction. Yes, with
GDI+, we may draw the entire form what style we like. The below is a little
code snippet which do something similiar as you want:
protected override void OnPaint(PaintEventArgs e)
{
Color LightColor = Color.FromArgb(245,223,162);
Color DarkColor = Color.FromArgb (207,188,136);
Rectangle r = new Rectangle(0,0, this.Width, this.Height/4);
// Create a LinearGradientBrush... the two colors specified will be
// overridden, so they don't matter.
LinearGradientBrush lb = new LinearGradientBrush(r, Color.Black
,Color.Black, 90, false);

// Setup a ColorBlend that has the color names and positions.
// Basically, an array of any amount of color/position pairs. I'm doing 3
colors
ColorBlend lbColors = new ColorBlend(3);
// Set the colors equal to a new array
lbColors.Colors = new Color[] {Color.Red, Color.Blue, DarkColor};
// Set the positions for the three colors. The range is 0.0 to 1.0 (floats)
lbColors.Positions = new float[] {0.0f, 0.8f, 1.0f};
// Set the InterpolationColors of the LinearGradientBrush to this new
ColorBlend
lb.InterpolationColors = lbColors;

// Draw the gradient.
e.Graphics.FillRectangle(lb, r);
e.Graphics.FillRectangle(lb, new Rectangle(0, this.Height*3/4, this.Width,
this.Height/4));

base.OnPaint (e);
}
You may directly copy and paste in your Form class. For your information.
Note: the sample is far from perfect, you should do a lot of improvement to
it.

Also, there is a GDI+ tutorial writen by Robert W. Powell MVP, please refer
to:
"Using The LinearGradientBrush"
http://www.bobpowell.net/linear.htm

Hope this helps
================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top