Results 1 to 2 of 2

Thread: Fillrectange problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    71

    Fillrectange problem

    Hi all,

    I am trying to set up a picturebox in a form so i can add small rectangles (points of interest) over a floor plan. I have the following code which does exactly what i want but im having trouble filling the rectangles with solid colour. Heres the code i have:

    Code:
    Dim MyRect As New Rectangle(e.X, e.Y, 10, 10)
            Dim g As Graphics = Me.picShowPicture.CreateGraphics
            Dim Pn As Pen = New Pen(Color.Red) 'Create pen from color
            Dim Mybrush = New SolidBrush(Color.Red)
    
            points.Add(e.Location) '
            For Each p As Point In points
                picShowPicture.Invalidate(MyRect)
                If ComboBox4.Text = ("Computer") Then
                    g.DrawRectangle(Pn, MyRect)
                    'g.FillRectangle(Mybrush, MyRect)
    
                End If
            Next
            g.Dispose()
    Any help gratefully received.

    Kev

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Fillrectange problem

    For a start, you shouldn't be calling CreateGraphics at all. You should be doing your drawing in the Paint event handler and using the Graphics object provided by the 'e' parameter.

    As for the question, you use FillRectangle to draw a filled rectangle.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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