473,322 Members | 1,718 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,322 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 1996

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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.