• 0

[C#] User Control Events not firing


Question

Is this a built in feature of C# that I'm missing... I create a bunch of user controls, and add them to my main Form1...

inside the Creation of the user Control.. I try to add Events

			InitializeComponent();
....
			this.Click += new EventHandler(Bin_Click);
			this.MouseHover += new EventHandler(Bin_MouseHover);

And below I have the definitions for the events... But they are not getting fired when I mouseover or click the User Control... What gives?

Link to comment
https://www.neowin.net/forum/topic/618506-c-user-control-events-not-firing/
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Let me clarify...

My User control has a couple different controls.. Ultimatele I want a click to be captured on anywhere inside the usercontrol...

It only works right now for areas on which dont have a user control, merely just the background.

Add the Click event to all controls... I'm assuming the answer I found is going to be the one i ge... guess there's no way to capture them all without capturing mouse events?

  • 0

Yea, as you said, I'm not at all sure you can bind the event to the User Control itself.

Have you tried putting everything in the User Control inside one Panel and binding the Click/OnMouseOver eventhandlers to the Panel instead? I haven't tried this, but _I_ would try this first.

And depending on where you actually want to do the processing of those events you might need to bubble the event up to Page (search for "bubble events asp.net").

  • 0

Override the OnMouseClick method and it should work.

protected override void OnMouseClick(MouseEventArgs e)

{

// label1 belongs to the user control

label1.Text = String.Format("{0} mouse button clicked at {1},{2}", e.Button,

e.X, e.Y);

base.OnMouseClick(e);

}

The same would apply to any event you want to utilize.

Edited by azcodemonkey
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Really? Do you want it spelled out? Ok: It was a funsies way to say that we can confidently asume that their update servers were shut down years ago already, and no updates have been developed or delivered to any LG phone in years, since, to begin, LG wasn't too well known for their software support.
    • Good afternoon, I have a customer who purchased a Dell laptop last year. One of the latest Inspirons. they are older so it can be a bit hard to see things on the screen. They are using Windows 11 Home 23H2, I have not upgraded them yet to 24H2. What I did was changed the scaling to 150% and that automatically made all the icons on desktop bigger and using in Chrome webpage elements are bigger etc. The thing is I overlooked the Taskbar and the icons most notably hidden within the arrow pointing up. I though by changing to 150% the scaling even the taskbar would get bigger. Again I don't know how I missed seeing that. Is this something that can be fixed? One other thing is I notice in File Explorer things are also small and not larger after the change. Can this be fixed as well?   Thank You.
    • Apple still has two unannounced features for iOS 26 by Hamid Ganji Apple held its WWDC25 event this month to unveil a slew of AI features and its new design for operating systems, known as Liquid Glass. While iOS 26 currently has no shortage of features, the iPhone maker might still have some features under wraps that didn’t make a debut at this month’s WWDC. Bloomberg’s Mark Gurman writes in his weekly Power On newsletter that Apple didn’t announce two iOS 26 features at the WWDC event. The first feature is a live translation of conversations via AirPods, and the latter is the ability to sync your wireless network login information across devices at a hotel or gym. Even though these features were already tipped to arrive in iOS 26, Apple held them from the event, presumably because they’re still not ready to ship. Apple appears to have learned from its experience with Apple Intelligence and aims to break the habit of unveiling new features before they are ready for release. The Live Translation on iOS 26 is currently integrated with popular apps like Messages, FaceTime, and Phone to help users break language barriers and communicate in different languages. The feature is now under development for AirPods, allowing users to hear real-time speech translations. Moreover, the WiFi syncing feature allows you to sync your sign-in information across your entire Apple ecosystem, enabling you to connect to a public WiFi network with ease. This would eliminate the need to sign into a WiFi network separately on each device. While these features haven’t arrived in iOS 26 yet, they’re more likely to be released later this year, in October or December.
    • Intel Level L4 cache has been around for a long time, so AMD Zen 3D Cache is a copy of Intel L4 cache that was introduced with Broadwell i7-5775c, which had 128mb of Level L4 cache. Secondly, Zen 6 is not faster in single-threaded performance than 13900k/14900k. 285k is something new Intel is trying, basically showing us that chiplet design does not work for gaming, just like AMD design does not work for gaming. Throwing more cores at it and having L4 cache won't fix the issue, and that is frame dip and stuttering caused by a very stupid design decision to keep the memory controller outside the compute tile. Might as well put a memory controller by bringing back a south bridge chip. lol
  • Recent Achievements

    • Community Regular
      Primey_ went up a rank
      Community Regular
    • Reacting Well
      Gromvar earned a badge
      Reacting Well
    • Dedicated
      BreakingBenjamin earned a badge
      Dedicated
    • Week One Done
      Hartej earned a badge
      Week One Done
    • One Year In
      TsunadeMama earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      515
    2. 2
      +FloatingFatMan
      183
    3. 3
      ATLien_0
      168
    4. 4
      Skyfrog
      97
    5. 5
      Som
      96
  • Tell a friend

    Love Neowin? Tell a friend!