开发者

"No default property"

开发者 https://www.devze.com 2023-03-29 05:06 出处:网络
I have entered in the lines Private Sub tmrAnalogueCounter_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrAnalogueCounter.Tick

I have entered in the lines

Private Sub tmrAnalogueCounter_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrAnalogueCounter.Tick
        AnalogCounter += 1
        If AnalogCounter >= 17 Then
            tmrAnalogueCounter.Enabled = False
        End If
        pboTimer.Image = My.Resources.ResourceManager("Timer" & AnalogCounter)
End Sub

Unfortunately, I'm getting the error "Class 'System.Resources.ResourceManager' cannot be indexed because it has no default property.

I don't understand why, "pboTimer.Image = My.ResourceManager("Timer" & AnalogCounter)" replaced

Select Case AnalogCounter
        Case 1 : pboTimer.Image = My.Resources.Timer1
        Case 2 : pboTimer.Image = My.Resources.Timer2
        Case 3 : pboTimer.Image = My.Resources.Timer3
        Case 4 : pboTimer.Image = My.Resources.Timer4
        Case 5 : pboTimer.Image = My.Resources.Timer5
        Case 6 : pboTimer.Image = My.Resources.Timer6
    开发者_如何学运维    Case 7 : pboTimer.Image = My.Resources.Timer7
        Case 8 : pboTimer.Image = My.Resources.Timer8
        Case 9 : pboTimer.Image = My.Resources.Timer9
        Case 10 : pboTimer.Image = My.Resources.Timer10
        Case 11 : pboTimer.Image = My.Resources.Timer11
        Case 12 : pboTimer.Image = My.Resources.Timer12
        Case 13 : pboTimer.Image = My.Resources.Timer13
        Case 14 : pboTimer.Image = My.Resources.Timer14
        Case 15 : pboTimer.Image = My.Resources.Timer15
        Case 16 : pboTimer.Image = My.Resources.Timer16
        Case 17 : pboTimer.Image = My.Resources.Timer17
        Case Else : tmrAnalogueCounter.Enabled = False
End Select

Any idea how to fix it?


You are getting this error because there is no default property defined on ResourceManager. From Default Properties:

A default property is the property that Visual Basic will use when no specific property has been named for an object. Default properties are useful because they allow you to make your source code more compact by omitting frequently used property names.

As there is no default property defined, you will have to explicitly call the property to return the value you want. In this case it would be:

pboTimer.Image = My.Resources.ResourceManager.GetObject("Timer" & AnalogCounter)

You may also have to explicity convert the Object returned to an image:

pboTimer.Image = CType(My.Resources.ResourceManager.GetObject("Timer" & AnalogCounter), System.Drawing.Image)
  Or
pboTimer.Image = CType(My.Resources.ResourceManager.GetObject("Timer" & AnalogCounter), System.Drawing.Bitmap)
0

精彩评论

暂无评论...
验证码 换一张
取 消