0

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

Edited by __avd: Add [code] tags. Encase your code in: [code] and [/code] tags.

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by BrendaByrne
0

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

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

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.