Unsure as to whether this is actually a bug. I think it is probably a flaw
in my programming.
I still don't understand it but I found the problem. There are several
requirements necessary to see the "bug".
\\\
Private m_FlatStyle As FlatStyle = FlatStyle.Standard
Private m_SomeProperty As SomeEnum
Private Enum SomeEnum
[Value1] = 1
[Value2]
End Enum
Private Property SomeProperty() As SomeEnum
Get
Return m_SomeProperty
End Get
Set(ByVal Value As SomeEnum)
If [Enum].IsDefined(GetType(SomeEnum), Value) Then
m_SomeProperty = Value
Invalidate()
End If
End Set
End Property
<DefaultValue(GetType(FlatStyle), "Standard")> _
Public Shadows Property FlatStyle() As FlatStyle
Get
Return m_FlatStyle
End Get
Set(ByVal Value As FlatStyle)
If [Enum].IsDefined(GetType(FlatStyle), Value) Then
m_FlatStyle = Value
If Value.Equals(FlatStyle.System) Then
MyBase.FlatStyle = FlatStyle.Standard
Else
MyBase.FlatStyle = Value
End If
Invalidate()
End If
End Set
End Property
Protected Overrides Sub OnPaint(ByVal pevent As PaintEventArgs)
MyBase.OnPaint(pevent)
Me.Region = New Region(New Rectangle(5, 5, Width - 10, Height - 10))
End Sub
Protected Overrides Sub OnMouseMove(ByVal mevent As MouseEventArgs)
MyBase.OnMouseMove(mevent)
If Not Me.Enabled Then Return
If mevent.Button = MouseButtons.Left Then
SomeProperty = SomeEnum.Value1
Else
SomeProperty = SomeEnum.Value2
End If
End Sub
///
Now you sould see the "bug".
Now the annoying parts:
1. Comment out the line:
Me.Region = New Region(...
and rerun the project. The "bug" has gone. But I need to set the
Region.
2. Uncomment, comment out the Shadowed Flatstyle property and rerun. The
bug has gone again, but I can not now custom Paint when FlatStyle.System is
selected. I need to do this, it was the whole reason for writing this
control (to draw an image in an XP Styled button).
3. Uncomment and comment out the line:
SomeProperty = SomeEnum.Value2
and rerun the project. Once more the "bug" has gone. But I need to set
that property.
4. The real bug was in my SomeProperty code, but because of the above
apparent fixes it was hard to find. A simple check to see if the property
had actually changed was all that was necessary.
...
Set(ByVal Value As SomeEnum)
If [Enum].IsDefined(GetType(SomeEnum), Value) Then
If m_SomeProperty.Equals(Value) Then Return '<----
m_SomeProperty = Value
Invalidate()
End If
End Set
...
Thankyou for listening, and if you can explain why I was seeing this error
only with all the above circumstances, or why the "bug" appeared to be gone
when I took any of the above steps, then please do.
|