Hi,

DO somebody know how to remove the rectangle graphics, I'm able to draw a rectangle graphics using this code:

Dim g As System.Drawing.Graphics
        Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red, 2)
        Dim myRect As New Rectangle(x1, y1, x2, y2)
        g = Me.CreateGraphics()
        g.DrawRectangle(myPen, myRect)
        g.Dispose()

Is it possible to remove this rectangle graphics i had draw, Please tell me how to do so.

Thanks.

OMG, I was looking for a similar thing but was amazed by the solution I found! You can just use VisualBasic PowerPacks, it is included with my version of Visual Studio 2008

Here's a sample code that will draw a rectangle over a TextBox, i.e. I am giving it a custom border

Dim x = TextBox1.Location.X
    Dim y = TextBox1.Location.Y
    Dim width = TextBox1.Width
    Dim height = TextBox1.Height
    Dim ShapeContainer1 As New Microsoft.VisualBasic.PowerPacks.ShapeContainer
    Me.Controls.Add(ShapeContainer1)
    Dim RectangleShape1 As New Microsoft.VisualBasic.PowerPacks.RectangleShape
    ShapeContainer1.Shapes.AddRange(New Microsoft.VisualBasic.PowerPacks.Shape() {RectangleShape1})
    RectangleShape1.Location = New System.Drawing.Point(x - 1, y - 1)
    RectangleShape1.Size = New System.Drawing.Size(width + 1, height + 1)
    RectangleShape1.BorderColor = Color.MistyRose
    ShapeContainer1.Refresh()

Code is self describing but if you'd have any problem, just leave a message...
Yes, if you want to remove the rectangle, just dispose the controls(either the Rectangle or the ShapeContainer in whole), no painting, no hassle!!!

Courtesy: CandorZ

This article has been dead for over six months. Start a new discussion instead.