473,216 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,216 software developers and data experts.

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 1986

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Charles Law | last post by:
If I draw a rectangle, 6 inches by 2 inches, on a user control with a PageUnit of Inches, I get a rectangle of 7 by 2.2 inches. Is this what people would expect? I would have hoped that it was at...
1
by: P1ayboy | last post by:
How efficient is it to use GDI to create images. Instead of having to create loads of titles for a web site, i would like to use the GDI. My concern is how intensive it is on the processor. ...
1
by: David Sobey | last post by:
Hi I'm making a custom component using GDI+, a calendar grid thingy. I paint the grid and numbers in my overrided OnPaint. However, when i go to paint other things at other times in other...
7
by: | last post by:
We create VC++ programs that does some GDI drawing functionality. I discovered GDI+ and this seems to be a big step forward, and appears to be standard available in Windows XP and Windows Server...
3
by: Daniel | last post by:
hi , was just wondering if anyone could tell me how to use the gdi++ i cant seem to find out .. soz i know this is a very newb question but i have to ask it Regards , >> Daniel <<
2
by: SStory | last post by:
Question #1) If I do Image.Save with the same filepath that I got the image from, it bombs with "A generic error occurred in GDI+" Any ideas? I prompt the user before overwriting, but if they...
7
by: Marcin Rzeznicki | last post by:
Hello, Do you think it is legitimate practice to mix GDI+ and GDI calls (via Get/ReleaseHDC()) in paint event of a control? I've heard there is possibility of performance loss while "locking"...
3
by: Asfar | last post by:
Hi, Can some one tell me from where can I download the GDI+ SDK to use with VC6. Thanks, -Asfar
0
by: Tao | last post by:
hi.. group, Is there a easy way (or a safe way, whatever you call it) to transfer a DirectX output to GDI image? For example: Somebody draws a rectangle using DirectX with C++. I need to...
2
by: user | last post by:
Hi all... i am trying to print an image using GDI - but the only thing i get is a black rectangle. Does anybody know what is wrong, or how else to get the bitmap on the printer (GDI+ is not...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.