How do I paint partically in panel?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I want to paint my panel partically. Suppose the height of my panel is 400. The first 200 of panel, I want to paint with color red, and the rest 200, I want to paint with Green color. How do I do that

Regards
 
Hook into the Paint event for the Panel and use the Graphics object that is
passed in via the PaintEventArgs object. I'm sure sure which way you want to
split the Panel for painting but the code below should work for you.

private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs
e)
{
e.Graphics.FillRectangle(Brushes.Red, 0, 0, ((Panel)sender).Width / 2,
((Panel)sender).Height);
e.Graphics.FillRectangle(Brushes.Green, ((Panel)sender).Width / 2, 0,
((Panel)sender).Width / 2, ((Panel)sender).Height);
}


--
Tim Wilson
..Net Compact Framework MVP
{cf147fdf-893d-4a88-b258-22f68a3dbc6a}
robert said:
Hi,
I want to paint my panel partically. Suppose the height of my panel is
400. The first 200 of panel, I want to paint with color red, and the rest
200, I want to paint with Green color. How do I do that?
 
Type-O
"I'm NOT sure which way you want to split the Panel for painting but the
code below should work for you."
 
* =?Utf-8?B?cm9iZXJ0?= said:
I want to paint my panel partically. Suppose the height of my panel is
400. The first 200 of panel, I want to paint with color red, and the
rest 200, I want to paint with Green color. How do I do that?

In the panel's 'OnPaint' method, use 'e.Graphics.FillRectangle' to draw
the two rectangles.
 
Thank you Herfried K.Wagner

I have another question. I want to paint the panel by the other button's click event.
How can I do that?

Regards
 
Back
Top