Results 1 to 5 of 5

Thread: Rectangles & Lines in VB.NET

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Location
    New York
    Posts
    29

    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

  2. #2
    New Member
    Join Date
    Dec 2002
    Location
    USA
    Posts
    10

    Bump

    On a slightly different note, I'm saddened that the Shape Control didn't make the cut.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Location
    New York
    Posts
    29
    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...

  4. #4
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    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.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Location
    New York
    Posts
    29
    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
  •  



Click Here to Expand Forum to Full Width