|
-
Dec 26th, 2002, 02:14 PM
#1
Thread Starter
Junior Member
Rectangles & Lines in VB.NET
Hi, I have a problem with lines, rectangles and filled rectangles. For example, I want to draw a rectangle at location (10,10) with a size (10,10). It I use a pen with a width of 1 all is ok. If I use a pen with a width of 3 however things get bad. Meaning that instead the point (10,10) being EXACTLY in the upper left corner, the point (9,9) will be there, as .NET tries to have the "middle" of the line on the original point. So, I was wondering, if I do this:
dim k as integer
k = math.floor((mypen.width - 1 )/ 2)
and add k to the location.x and location.y, the rectangle should fall in the right place?
But what about the width and height. Probably I would have to reduce them both by 2*k ?
Does anybody know where I can read about this?
I have the same question for line: a line with width 3 has the (x,y) in the middle. But what about a line with width 4? Is the (x,y) on the "first middle pixel" or on the second??
I cannot even begin to say the problems with filling the rectangle. It looks too me like the fillrectangle fills the interior + the bottom line of the rectangle?
any help would be appreciated,
thank you,
iulian
-
Dec 28th, 2002, 04:46 PM
#2
New Member
Bump
On a slightly different note, I'm saddened that the Shape Control didn't make the cut.
-
Dec 30th, 2002, 08:57 AM
#3
Thread Starter
Junior Member
well, I finally made a function of my own called AdjustRect(rect, pen), which will adjust the rectangle's location and size in such a way, depending on the pen, so that the call to drawrectangle will draw the rectangle exactly inside the bounds. I will put it here, but i have to get home....
Now I wonder what is going to happen if the width of the pen is bigger than one side of the rectangle? Probably something ugly...
-
Dec 30th, 2002, 10:12 AM
#4
Registered User
There is an alignment property of the pen object, can't you use that?
Ex:
Code:
Dim p As New Pen(Color.Red, 10)
p.Alignment = Drawing.Drawing2D.PenAlignment.Inset
Every rectangle you paint with that pen will be painted inside the regions of the rectangle, use ".Center" for middle and ".Outset" for outside.
-
Dec 30th, 2002, 10:15 AM
#5
Thread Starter
Junior Member
Well, I didn't know about that, but it sure looks like it would solve my problems...
Thank you!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|