• 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

    • Claude Code gets throttled as Anthropic rolls out fresh usage caps by David Uzondu Claude Code, the AI-in-terminal utility developed by Anthropic and launched back in February, is getting updated usage limits following weeks of user complaints about being abruptly cut off. Many developers on the "$200/month Max plan" found their access blocked after just a few requests, with no explanation from the company. In a recent thread posted to X, the AI lab explained that it has seen "unprecedented demand since launch," pointing to some of its heaviest users who were running the tool continuously in the background 24/7, with one person reportedly consuming tens of thousands of dollars in model usage on a single $200 subscription. Anthropic also claimed that some users were violating its usage policy by sharing and reselling accounts, which impacts system capacity for everyone. These factors all led the company to announce new weekly limits that will be added on top of the existing five-hour caps, effective August 28. Max plan subscribers will have the option to buy additional usage at standard API rates if they hit their cap. Here's what the new weekly limits look like: Pro Plan ($20/month): An estimated 40 to 80 hours of usage with the Sonnet 4 model. Max Plan ($100/month): An estimated 140 to 280 hours with Sonnet 4 and 15 to 35 hours with the top-tier Opus 4 model. Max Plan ($200/month): An estimated 240 to 480 hours with Sonnet 4 and 24 to 40 hours with Opus 4. Per TechCrunch, the company provided these hour-based estimates, noting that the actual numbers may vary based on the size of a project's codebase. What's interesting is how this new structure compares to the old marketing. Anthropic previously advertised its $200 Max plan as offering 20 times more usage than the Pro plan. Based on these new hourly estimates, that multiple is now closer to six. It is possible the 20x figure still applies when measured in tokens or raw compute, but, according to TechCrunch, the company has not clarified that point.
    • I don't give a rat's f### what Trumpette, the Putin puppet likes!
    • The multi tab function is definitely useful. I was constantly asking it to analyze my screen and perform certain functions, but having to do that for each tab was a chore. This is def a welcome improvement!
    • Tablet mode doesn't exist on public releases in Windows 11, but there is a very good option activated with a few registry tweaks they must be testing. I've been using it on an old Surface Pro and love it. Minimised taskbar with no pinned icons or Start button visible, only clock and settings (battery/wifi/sound) icons. When the whole thing is visible, the icons are much larger and easy to tap. Swiping up does shows it and if you continue, opens the Start Menu. Needs more work, like a single finger swipe for multitasking, and perhaps miniaturised widget/s visible on the left, but it works well and I think it even works with mouse & keyboard use (mine's forced always on). Reddit - https://preview.redd.it/what-w...51db8351dd56cbf6bc012397a20
  • Recent Achievements

    • First Post
      Gladiattore earned a badge
      First Post
    • Reacting Well
      Gladiattore earned a badge
      Reacting Well
    • Week One Done
      NeoWeen earned a badge
      Week One Done
    • One Month Later
      BA the Curmudgeon earned a badge
      One Month Later
    • First Post
      Doreen768 earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      636
    2. 2
      ATLien_0
      260
    3. 3
      Xenon
      164
    4. 4
      neufuse
      142
    5. 5
      +FloatingFatMan
      107
  • Tell a friend

    Love Neowin? Tell a friend!