Hi, yes I'm a student with homework problems, but I am trying. I need to display various shapes in a picture box, and am trying to do so via a combobox that the user can select from. My problem is clearing a previous selection when a new selection is made. Code to date is:

Public Class frmGraphics1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Populate cboShape with shapes
        cboShape.Items.Add("Select a shape")
        cboShape.Items.Add("Circle")
        cboShape.Items.Add("Square")
        cboShape.Items.Add("Rectangle")

        'Set index to 0
        cboShape.SelectedIndex = 0
    End Sub

    Private Sub cboShape_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboShape.SelectedIndexChanged

        Dim GraphicsDisplay As Graphics
        GraphicsDisplay = pboGraphics.CreateGraphics

        If cboShape.SelectedIndex = 0 Then
            Exit Sub

        ElseIf cboShape.SelectedIndex = 1 Then
            GraphicsDisplay.DrawEllipse(Pens.Blue, 10, 10, 150, 150)

        ElseIf cboShape.SelectedIndex = 2 Then
            GraphicsDisplay.DrawRectangle(Pens.Blue, 10, 10, 150, 150)

        ElseIf cboShape.SelectedIndex = 3 Then
            GraphicsDisplay.DrawRectangle(Pens.Blue, 10, 10, 250, 100)

        End If
    End Sub
End Class

Thank you, Brenda

Clear() method clears entire area of drawing surface and fill it specified background color.

GraphicsDisplay = pboGraphics.CreateGraphics
 GraphicsDisplay.Clear(pboGraphics.BackColor)

Clear() method clears entire area of drawing surface and fill it specified background color.

GraphicsDisplay = pboGraphics.CreateGraphics
 GraphicsDisplay.Clear(pboGraphics.BackColor)

Thank you so much, i was missing the

pboGraphics.Backcolor

bit. My only problem now is that the top left hand portion of my shape is missing when I reselect. B

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.