468,470 Members | 1,401 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,470 developers. It's quick & easy.

GDI+ question-rounded label border does not draw correctly

I'm trying to create a form with some rounded controls, and I'm having
some problems with the rounding not working correctly. I've tried a
couple of different methods for creating the graphics path, including
the one from the GDI+ FAQ. It's a pretty simple path, and
mathematically it looks just fine. When I apply it to a control
though, I have two problems. First, the corners on the right side of
the control are obviously not rounded as much as the ones on the left
side, and if I attempt to add an outline to the control (by drawing the
path), I get missing pixels that break my lines. Essentialy, here's
what I'm doing in my derived label class (I included the gradient brush
code in case that might be affecting things):

Rectangle rect = new Rectangle(0, 0, Width, Height);
LinearGradientBrush GBrush = new LinearGradientBrush(
new Point(0, 0),
new Point((int)(Width*1.2), 0), cLeft, cRight);
this.region=CreateRoundedRectPath(rect, 6);
e.Graphics.FillRectangle(GBrush, rect);
Pen p = new Pen(Color.Gray, 2);
e.Graphics.DrawPath(p, path);
SolidBrush drawBrush = new SolidBrush(this.ForeColor);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
RectangleF rectF = new RectangleF(0, 0, this.Width, this.Height);
e.Graphics.DrawString(this.Text, this.Font, drawBrush, rect, sf);

I'm using this code from the FAQ to calculate the path:

gp.AddLine(X + radius, Y, X + width - (radius * 2), Y);

gp.AddArc(X + width - (radius * 2), Y, radius * 2, radius *
2, 270, 90);

gp.AddLine(X + width, Y + radius, X + width, Y + height -
(radius * 2));

gp.AddArc(X + width - (radius * 2), Y + height - (radius *
2), radius * 2, radius * 2, 0, 90);

gp.AddLine(X + width - (radius * 2), Y + height, X +
radius, Y + height);

gp.AddArc(X, Y + height - (radius * 2), radius * 2, radius
* 2, 90, 90);

gp.AddLine(X, Y + height - (radius * 2), X, Y + radius);

gp.AddArc(X, Y, radius * 2, radius * 2, 180, 90);

gp.CloseFigure();
return gp;

Anyone have any idea what's going on? Is this just a limitation of
GDI+ that you're never going to get things correct to the pixel? I
have to doubt it, simply because the labels are very obviously lopsided
with broken outlines.

Thanks in advance!

Chris

Sep 25 '06 #1
0 1766

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Charles Law | last post: by
1 post views Thread by P1ayboy | last post: by
1 post views Thread by David Sobey | last post: by
7 posts views Thread by | last post: by
3 posts views Thread by Daniel | last post: by
2 posts views Thread by SStory | last post: by
7 posts views Thread by Marcin Rzeznicki | last post: by
3 posts views Thread by Asfar | last post: by
reply views Thread by Tao | last post: by
2 posts views Thread by user | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.