Results 1 to 7 of 7

Thread: [Resolved] - problem while drawing rectangles

  1. #1

    Thread Starter
    Lively Member harishs's Avatar
    Join Date
    Jul 2005
    Location
    Bombay, India
    Posts
    118

    Resolved [Resolved] - problem while drawing rectangles

    Hi there,
    I wanna draw rectangles on a picture box, as we do in paintBrush Application. I m able to draw rectangle but only filled one not an empty one, how to do this.
    for eg. i m attaching an image showing two type of rectangles that i wanna draw.

    What, if i wanna draw same kinda rounded rectangle and circles.

    plz help.

    thanx in advance
    harry
    Attached Images Attached Images  
    Last edited by harishs; Dec 2nd, 2005 at 06:15 AM. Reason: problem solved

  2. #2
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Re: problem while drawing rectangles

    Empty Box
    VB Code:
    1. Picture1.Line(10, 10)-Step(100, 30), RGB(0, 0, 0), B

    Filled Box
    VB Code:
    1. Picture1.Line(10, 10)-Step(100, 30), RGB(0, 0, 0), BF

    Circle
    VB Code:
    1. Picture1.Circle(50, 50), 10, RGB(0, 0, 0)

    Rounded Rectangle (not filled)
    VB Code:
    1. '// Uhm...
    2. Private Function Radians(ByVal deg as single) As single
    3.   Dim Pi as single
    4.   Pi = 3.14159265358979
    5.   Radians = deg * (Pi / 180)
    6. End Funtion
    7.  
    8. Private Sub Form_Load()
    9.   Dim rWidth as integer
    10.   Dim rHeight as integer
    11.   Dim rCorner as integer
    12.   Dim rX as integer
    13.   Dim rY as integer
    14.   Dim lC as long
    15.  
    16.   rWidth = 100 '// width of the rectangle
    17.   rHeight = 50 '// height of the rectangle
    18.   rCorner = 5 '// corner radius
    19.   rX = 10 '// left position of rectangle
    20.   rY = 10 '// top position of rectangle
    21.   lC = RGB(126, 0, 0) '// rectangle color
    22.  
    23.   '// top left corner
    24.   Picture1.Circle (rX + rCorner, rY + rCorner), rCorner, lC, Radians(90), Radians(180)
    25.   '// top right corner
    26.   Picture1.Circle (rX + rWidth - rCorner, rY + rCorner), rCorner, lC, Radians(0), Radians(90)
    27.   '// bottom left corner
    28.   Picture1.Circle (rX + rCorner, rY + rHeight - rCorner), rCorner, lC, Radians(180), Radians(270)
    29.   '// bottom right corner
    30.   Picture1.Circle (rX + rWidth - rCorner, rY + rHeight - rCorner), rCorner, lC, Radians(270), Radians(360)
    31.  
    32.   '// top line
    33.   Picture1.Line (rX + rCorner, rY)-Step(rWidth - (rCorner * 2), 0), lC
    34.   '// bottom line
    35.   Picture1.Line (rX + rCorner, rY + rHeight)-Step(rWidth - (rCorner * 2), 0), lC
    36.   '// left line
    37.   Picture1.Line (rX, rY + rCorner)-Step(0, rHeight - (rCorner * 2)), lC
    38.   '// right line
    39.   Picture1.Line (rX + rWidth, rY + rCorner)-Step(0, rHeight - (rCorner * 2)), lC
    40. End Sub
    Last edited by r0ach; Nov 25th, 2005 at 09:53 AM.

    r0ach™
    Don't forget to rate the post

  3. #3

    Thread Starter
    Lively Member harishs's Avatar
    Join Date
    Jul 2005
    Location
    Bombay, India
    Posts
    118

    Re: problem while drawing rectangles

    I tried this method, it give me black colour inside the rectangle. but i want it to be transparent i.e. only outline (only 4 lines)

    plz help

    harry

  4. #4
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: problem while drawing rectangles

    It gives you filled rect because the Picturebox fillstyle property is set so SOLID (0)

    Change to transparent:
    VB Code:
    1. Picture1.FillStyle = 1
    You also can do it at design time.

  5. #5

    Thread Starter
    Lively Member harishs's Avatar
    Join Date
    Jul 2005
    Location
    Bombay, India
    Posts
    118

    Re: problem while drawing rectangles

    thanx alot friends,

    now i'm using gdi APIs for making all the stuffs.
    plz tell me 1 thing, if i'm drawing a filled RoundRectangle / ellipse / rectangle then how to allow the user to select his own colour.

    plz reply soon

    thanx in advance
    harry

  6. #6
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Re: problem while drawing rectangles

    If you're using the GDI, there should be a param that specifies the color. Just have the user choose a color, and pass it in as this param. It will be the CreateSolidBrush that's got this param (I think. Too much VB.NET GDI+)

    r0ach™
    Don't forget to rate the post

  7. #7

    Thread Starter
    Lively Member harishs's Avatar
    Join Date
    Jul 2005
    Location
    Bombay, India
    Posts
    118

    Re: problem while drawing rectangles

    thanx alot friends,
    ur replies worked out for me.

    thanx alot

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