Solved

How to override Checkbox OnMouseEnter event

Posted on 2010-08-18
4
443 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now