Unwanted clipping in user control

G

Guest

Hi everyone,

I have a really annoying problem: I've made a simple user control (an
enhanced progress bar); both at design-time and run-time everything that is
outside the default control size is not drawn. It's like the default size
works as a clipping region and everything drawn outside is not visible.

Did I miss something to set or code?

Also, anyone here knows how to give an icon to my control to show up when in
the toolbox among the other controls?

TIA :)

::mrc
 
B

Bob Powell [MVP]

G

Guest

Hi Bob,

thanks for your reply. Unfortunately, I tryed over and over, but without
success. I checked the windows forms FAQ, but I couldn't get it right anyway.

Could you please take a look at my code and tell me what's missing?

Thanks a lot.

Mirco


public void Render(PaintEventArgs e)
{
int Left = 0;
int Top = 0;
int Right = this.Size.Width-1;
int Bottom = this.Size.Height-1;

// draw the border

m_Graphics.DrawLine(new Pen(Color.Black), Left, Bottom, Left, Top);
m_Graphics.DrawLine(new Pen(Color.Black), Left, Top, Right, Top);

m_Graphics.DrawLine(new Pen(Color.White), Right, Top, Right, Bottom);
m_Graphics.DrawLine(new Pen(Color.White), Right, Bottom, Left, Bottom);
}


protected override void OnPaintBackground(PaintEventArgs e)
{
Render(e);
}

protected override void OnResize(EventArgs e)
{
this.Refresh();
}
 
B

Bob Powell [MVP]

What is m_Graphics? you should be using the Graphics object passed to the
method in the PaintEventArgs. Have you stored the graphics or used
CreateGraphics somewhere??

You've overridden OnPaintBackground but you're only painting a single pixel
border. how does the rest of the background get painted?

If you really want to create a custom border you should override WndProc and
handle the WM_NCCALCSIZE and WM_NCPAINT messages to specify the relationship
between the client and non-client areas and paint the non-client area with
your border.

To have your control appear in the toolbox you need to create an icon or
bitmap in your solution, mark it as an embedded resource and then use the
ToolboxIcon attribute on your class to specify the toolbox icon to use.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
 
G

Guest

Hi Bob

Thanks for your reply. I managed to make the control paint correctly. The
problem was that I created the graphics in the constructor and then assigned
it to m_Graphics. I now use "e.Graphics" from the Paint() event and
everything work fine.

About the icon, that is still a mistery. I followed step by step
instructions from a couple of web sites, but I can't make it appear in the
toolbox list.
That is a minor problem though so I'll keep using the default icon.

Thanks for your time.

Mirco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top