• 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

    • Sony started with 70 Euro games, Nintendo with 80 Euro games.
    • It has only been about 2 years since Microsoft raised prices from $60 to $70! I don't think it's a good idea they are doing it again so soon. Instead of raising prices, manage game development budgets better.
    • Intel's 20-core Ultra 7 processor is now available with a massive discount by Taras Buria The Intel Core Ultra 7 265K, Intel's latest 20-core desktop processor, is getting more affordable. Now, the chip is available on Amazon with a 36% discount, saving you $144, which you can spend on a higher-spec graphics card, better cooling, a bigger SSD, or some new games. If you want to build a computer with the discounted Intel Core Ultra 7 265K, you will need a motherboard with the LGA 1851 socket and 800 series chipset. The Core Ultra 7 265K has 20 cores, 8 of which are performance cores, and 12 are efficiency cores operating at lower clocks for less demanding tasks. Performance cores have the maximum clock speed of 5.4GHz, while efficiency cores peak at 4.6GHz. However, the processor is unlocked, which means you can push those clocks higher if you have enough cooling and a motherboard that supports overclocking. Speaking of cooling, the processor has a TDP of 125W. A cooler is not included in the box, so do not forget to add one to your shopping cart. The Intel Core Ultra 7 265K has 30MB of level 3 cache (L3). It works with DDR5 memory (rated for 6,400 MT/s) and has a built-in graphics at 2GHz, which is enough for image output, media consumption, and all sorts of tasks that do not require a lot of GPU power. There is also a neural processing unit with 13 TOPS, which can handle on-device AI processing. Intel Core Ultra 7 Desktop Processor 265K 5.5 GHz - $259.99 | $144 off on Amazon US This Amazon deal is US-specific and not available in other regions unless specified. If you don't like it or want to look at more options, check out the Amazon US deals page here. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
    • It's stuff like this countries like Denmark are giving up by switching to Linux. Good luck to them.
    • I think a big part of it is developers have grown themselves too big and ballooned their budgets. It's the only way to show endless growth to investors between releases. Then they make massive investments in games designed for the bottom line hoping players follow instead of designing them for the players and hoping the bottom line follow in the way smaller, indie developers do. This often causes the games to fail to hook players. Instead they need to streamline development, lower budgets and sales forecasts, actually listen to gamer feedback, realize that social media doesn't dictate real world gaming tastes and habits, and overall learn to adapt instead of regurgitating the same formulas over and over.
  • Recent Achievements

    • Week One Done
      bukro earned a badge
      Week One Done
    • One Year In
      Wulle earned a badge
      One Year In
    • One Month Later
      Wulle earned a badge
      One Month Later
    • One Month Later
      Simmo3D earned a badge
      One Month Later
    • Week One Done
      Simmo3D earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      552
    2. 2
      ATLien_0
      246
    3. 3
      +FloatingFatMan
      167
    4. 4
      Michael Scrip
      121
    5. 5
      Steven P.
      95
  • Tell a friend

    Love Neowin? Tell a friend!