I am not sure how you are adding your OvalShapes or what type of container you are using. In order to add them to a Windows Form Control you will need to use the shapeContainer as mentioned by Slaks. In this example I am creating a shapeContainer and adding it to the Form, then I am using the shapeContainers.Shapes.Add Method to add the oval to the ShapeCollection Class. I also am attaching an eventhandler to the Click Event of the Ovals so that I can access the calling Shape to change its fill color through the sender object of the EventHandler. See if this will work for you.
Imports Microsoft.VisualBasic.PowerPacks
Public Class Form1
Dim offset As Integer = 0
Dim OvalContainer As New ShapeContainer
Public Sub New()
' This call is required by the designer.
InitializeComponent()
OvalContainer.Size = New Size(Me.Width, 50)
Me.Controls.Add(OvalContainer)
OvalContainer.Location = New Point(0, 0)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim oval As New OvalShape()
oval.Size = New Size(30, 40)
oval.Location = New Point(offset, 0)
oval.FillStyle = FillStyle.Solid
oval.FillColor = Color.Transparent
oval.BorderColor = Color.Black
oval.BorderWidth = 2
AddHandler oval.Click, AddressOf ShapeClick
OvalContainer.Shapes.Add(oval)
offset += 40
End Sub
Private Sub ShapeClick(sender As Object, e As EventArgs)
Dim oval As OvalShape = DirectCast(sender, OvalShape)
If oval.FillColor.Equals(Color.Red) Then
oval.FillColor = Color.Blue
Else
oval.FillColor = Color.Red
End If
End Sub
End Class
Edit per OP's clarification
When you create your ovals add oval.Name = "oval" & index
this will add the name property that will enable
the following code to work.
You can iterate through the Shapes Collection like this(this is based off of my above example):
For Each o As OvalShape In OvalContainer.Shapes
If o.Name = "oval1" Then o.FillColor = Color.Azure
Next
or you can search for the exact Oval that you are looking for by using the ShapeContainer.Shapes.IndexOfKey
Method
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim index As Integer = OvalContainer.Shapes.IndexOfKey("oval1")
If index >= 0 Then
DirectCast(OvalContainer.Shapes(index), OvalShape).FillColor = Color.Purple
End If
End Sub