473,503 Members | 7,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BUG: Inherited Button No.2 Argghhh!! }:-(

Minimal Code and steps needed to show problem.

Inherit from Button and set Region as below.

\\\
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
///

Add several of the inherited buttons to your form, set the forms
startposition to centerscreen and run the project. Place the mouse over any
one of the buttons you added to the form except the first one and press
Alt-F4 to close the form. Press F5 to start the project. All of the
inherited buttons added to the form before the one the mouse is over do not
get painted until after the mouse moves outside that buttons region.

The above steps were only necessary to make sure the mouse was over one of
the inherited buttons at startup.
Nov 20 '05 #1
3 1258
* "Mick Doherty" <EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> scripsit:
Inherit from Button and set Region as below.

\\\
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
///

Add several of the inherited buttons to your form, set the forms
startposition to centerscreen and run the project. Place the mouse over any
one of the buttons you added to the form except the first one and press
Alt-F4 to close the form. Press F5 to start the project. All of the
inherited buttons added to the form before the one the mouse is over do not
get painted until after the mouse moves outside that buttons region.

The above steps were only necessary to make sure the mouse was over one of
the inherited buttons at startup.


I am /not/ able to repro that on a Windows XP Professional machine
running .NET 1.1. What's your Windows/.NET version?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
XP Home/Net 1.1

My System must have been remembering something because today it works just
fine, whereas yesterday, even when I commented out all code and just had the
Windows Form Designer Generated code and the code shown my buttons would not
paint in that situation.
My original code still fails when uncommented, and I can see no logical
reason for it.
Looks like a day of headbashing for me. If I find the problem I will post
it.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:br***********@ID-208219.news.uni-berlin.de...
* "Mick Doherty"

<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> scripsit:
Inherit from Button and set Region as below.

\\\
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
///

Add several of the inherited buttons to your form, set the forms
startposition to centerscreen and run the project. Place the mouse over any one of the buttons you added to the form except the first one and press
Alt-F4 to close the form. Press F5 to start the project. All of the
inherited buttons added to the form before the one the mouse is over do not get painted until after the mouse moves outside that buttons region.

The above steps were only necessary to make sure the mouse was over one of the inherited buttons at startup.


I am /not/ able to repro that on a Windows XP Professional machine
running .NET 1.1. What's your Windows/.NET version?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #3
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.
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.