?
Solved

How to override Checkbox OnMouseEnter event

Posted on 2010-08-18
4
Medium Priority
?
492 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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

777 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