• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 504
  • Last Modified:

How to override Checkbox OnMouseEnter event

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
gem56
Asked:
gem56
  • 2
  • 2
1 Solution
 
Wayne Taylor (webtubbs)Commented:
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
 
gem56Author Commented:
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
 
Wayne Taylor (webtubbs)Commented:
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
 
gem56Author Commented:
I was hoping not to hear  "...you will have to replace..." although I suspected that may be the case. :-(

Thanks Wayne
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now