Solved

How to override Checkbox OnMouseEnter event

Posted on 2010-08-18
4
473 Views
Last Modified: 2012-05-10
Hi,

I would like to trap standard Checkbox OnMouseEnter event and do something before letting it through so that any other function can handle it.

I tried the code below (to gt the mechanism working before implementing the "Do something") but it doesn't work so any help would be appreciated.
 
Public Class CheckBox
    Inherits System.Windows.Forms.CheckBox

    Protected Shadows Sub OnMouseEnter(ByVal e As System.Windows.Forms.MouseEventArgs)
        ' Do something
    End Sub

End Class

Open in new window

0
Comment
Question by:gem56
  • 2
  • 2
4 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 33472464
Instead of Shadowing the event, Override it....

    Protected Overrides Sub OnMouseEnter(ByVal eventargs As System.EventArgs)
        'your code
        'call the event so you can handle it on your form if required
        MyBase.OnMouseEnter(eventargs)
    End Sub

Wayne
0
 

Author Comment

by:gem56
ID: 33472613
I tried doing that since writing my post and if I use the standard windows Checkbox (with your suggestion) my dialog shuts down and I get the following error:

"Error: Unexpected internal error in MyDialog.Show, ex.Message=Unable to cast object of type 'System.Windows.Forms.CheckBox' to type 'MyApp.CheckBox"

If I insert MyApp.Checkbox control in the Dialog then all seems to be OK, using "Override " as you suggested.

So my question now is whether if I override a standart windows control do I then have to use MyApp.Checkbox?

I ask that because I already have an application with numerous windows/dialogs that use standard windows Checkbox so I was trying to avoid having to go in and substitute them with MyApp.Checkbox.

Cheers.
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 33472655
To handle the MouseEnter event of every checkbox you use, you will have to replace them with your custom control

I also suggest you change the name of your custom control to something other than "CheckBox" to avoid confusion.

Wayne
0
 

Author Closing Comment

by:gem56
ID: 33473057
I was hoping not to hear  "...you will have to replace..." although I suspected that may be the case. :-(

Thanks Wayne
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question