By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,276 Members | 1,951 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,276 IT Pros & Developers. It's quick & easy.

Custom Paint with Gradient Panel

P: n/a
In my WinForms app I'd long ago implemented a drag & drop mechanism just like
is used in PowerPoint when one wants to rearrange the order of the slides.
Specifically, a thin black line is shown between thumbnails to indicate where
an item will be dropped.

As the user moved away I'd erase it by simply drawing another line using the
BackColor of the panel. This worked great! But I've recently switched to
using a Gradient panel and so now the BackColor no longer applies.

Can anyone recommend how I should erase the thin black line?

--
Robert W.
Vancouver, BC
www.mwtech.com
May 2 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Mon, 1 May 2006 18:34:02 -0700, Robert W. wrote:
In my WinForms app I'd long ago implemented a drag & drop mechanism just like
is used in PowerPoint when one wants to rearrange the order of the slides.
Specifically, a thin black line is shown between thumbnails to indicate where
an item will be dropped.

As the user moved away I'd erase it by simply drawing another line using the
BackColor of the panel. This worked great! But I've recently switched to
using a Gradient panel and so now the BackColor no longer applies.

Can anyone recommend how I should erase the thin black line?


It's not very clear how you've implemented the black line drawing (which
control is drawing it?). If the panel is drawing it, then calling its
Invalidate() method passing the appropriate rectangle will cause the panel
to redraw itself properly. If the drawing is made by the form, then call
the form's Invalidate() method passing the appropriate rectangle to force
it to redraw properly.
May 2 '06 #2

P: n/a
Mehdi,

Thank you so much! I wasn't very familiar with "Invalidate" but your
response lead me to a successful fix.

In case you're wondering, originally I had just one method to draw and erase
lines:

private void DrawSeparatorLine(Panel panel, int y, Color color)
{
Graphics g = panel.CreateGraphics();
Pen myPen = new Pen(color, 1);
g.DrawLine(myPen, 2, y, panel.ClientSize.Width - 2 , y); // Leave
2-pixel gap
g.Dispose();
}
But it wasn't working once I switched to gradient panels. To resolve the
problem I implemented a second method:

private void EraseSeparatorLine(Panel panel, int y)
{
Graphics g = panel.CreateGraphics();
Rectangle rect = new Rectangle(2, y, panel.ClientSize.Width - 2, 1);
panel.Invalidate(rect, false);
g.Dispose();
}
Though written for the general public, I even gave you credit on my blog:
http://pelalusa.blogspot.com/2006/05...can-be-so.html

Thank you again!

--
Robert W.
Vancouver, BC
www.mwtech.com

"Mehdi" wrote:
On Mon, 1 May 2006 18:34:02 -0700, Robert W. wrote:
In my WinForms app I'd long ago implemented a drag & drop mechanism just like
is used in PowerPoint when one wants to rearrange the order of the slides.
Specifically, a thin black line is shown between thumbnails to indicate where
an item will be dropped.

As the user moved away I'd erase it by simply drawing another line using the
BackColor of the panel. This worked great! But I've recently switched to
using a Gradient panel and so now the BackColor no longer applies.

Can anyone recommend how I should erase the thin black line?


It's not very clear how you've implemented the black line drawing (which
control is drawing it?). If the panel is drawing it, then calling its
Invalidate() method passing the appropriate rectangle will cause the panel
to redraw itself properly. If the drawing is made by the form, then call
the form's Invalidate() method passing the appropriate rectangle to force
it to redraw properly.

May 3 '06 #3

P: n/a
On Tue, 2 May 2006 21:14:01 -0700, Robert W. wrote:

private void EraseSeparatorLine(Panel panel, int y)
{
Graphics g = panel.CreateGraphics();
Rectangle rect = new Rectangle(2, y, panel.ClientSize.Width - 2, 1);
panel.Invalidate(rect, false);
g.Dispose();
}


Note that you do not need to create a Graphics object here (it's not being
used). You can remove the first and the last line of your code to save time
and ressources.
May 3 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.