Solved

How to override Checkbox OnMouseEnter event

Posted on 2010-08-18
4
488 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

728 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