PC Review


Reply
Thread Tools Rate Thread

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

 
 
Mick Doherty
Guest
Posts: n/a
 
      10th Dec 2003
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.


 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      11th Dec 2003
* "Mick Doherty" <EXCHANGE#(E-Mail Removed).[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>
 
Reply With Quote
 
Mick Doherty
Guest
Posts: n/a
 
      11th Dec 2003
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]" <hirf-spam-me-(E-Mail Removed)> wrote in message
news:br8f40$im6t$(E-Mail Removed)...
> * "Mick Doherty"

<EXCHANGE#(E-Mail Removed).[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>



 
Reply With Quote
 
Mick Doherty
Guest
Posts: n/a
 
      11th Dec 2003
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Argghhh... 30 Minute Log-in's :-( Dave Onex Microsoft Windows 2000 Active Directory 11 28th Nov 2009 01:37 AM
Button on top of inherited Control not visble Manfred Microsoft VB .NET 0 6th Aug 2009 01:59 PM
displaying inherited button cameljs18@yahoo.com Microsoft C# .NET 4 13th Dec 2007 07:40 PM
ARGGHHH!!! Stupid audio... =?Utf-8?B?VDNDSA==?= Windows XP Help 1 8th May 2004 08:57 PM
BUG: Inherited Button Mick Doherty Microsoft VB .NET 4 9th Dec 2003 09:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:09 AM.