• 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

    • Does it mean that the game will have weapons now? If that is the case, I'm interested. Not having weapons does not make any sense, even if it changes the gameplay. In such a hostile environment the first thing anyone would do is get as much weapons as they could.
    • This DDR5-6400 CL36 32GB RGB RAM that supports both AMD and Intel is only $72 by Sayan Sen Recently, we covered several SSD deals, both internal and external. These include the Crucial X9 Pro and X10 Pro, the P310 2280, and the Samsung 990 EVO Plus. Meanwhile if you are looking for RAM to upgrade your desktop PC or build a new one, the PNY XLR8 Gaming EPIC-X RGB DDR5-6400 Kit can be your go-to choice as it is currently just $72 (purchase link down below). In terms of specs, this dual-RAM kit delivers 32GB of total DDR5 capacity (each module is 16GB) running at 3200 Hz to deliver 6400 MT/s (PC5-51200) at 1.4 volts. Pre-programmed Intel XMP 3.0 and AMD EXPO memory overclocking preset profiles mean you can fire up the kit to its rated speed with a simple BIOS tweak, rather than having to deal with manual timing adjustments. The CAS latency for this DDR5-6400 kit is 36, which is quite tight for a preset profile. Thermal performance is said to be stellar thanks to the aluminum heat spreader, which should help dissipate heat during extended gaming sessions. Additionally, the heat spreader is also said to feature an "embossed pennant design that enhances the overall look and complements the lighting of other components." Speaking of lighting, the included EPIC-X RGB model features ARGB LEDs diffused through a geometric polymer light pipe and allows syncing via Asus Aura Sync, Gigabyte RGB Fusion, MSI Mystic Light, or ASRock Polychrome Sync software. Get the PNY RAM at the link below: PNY XLR8 Gaming Epic-X RGB™ 32GB (2x16GB) DDR5 RAM 6400 CL36-48-48-104 Desktop Memory Kit (MD32GK2D5640036XRGB): $72.24 (Sold and Shipped by Amazon US) (MSRP: $109.99) 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.
    • Vivaldi 7.5 is out with colorful tab stacks, improved tab menu, and more by Taras Buria Vivaldi Technologies has released a new feature update for the Vivaldi browser. Version 7.5 is now available with some much-requested features by the community, privacy improvements, bug fixes, and other changes. The release is not the biggest one, but it still packs useful changes, such as colorful tab stacks, a reworked tab context menu, and multiple improvements under the hood: Vivaldi now supports colorful Tab Stacks. This feature groups related tabs and helps you keep everything well-organized. Now, besides giving your stacks names, you can assign colors, which makes it easier to find the stack you need. Developers also added a new dialog: right-click a stack, click "Edit Stack," and give it a new name or choose a color. The browser also received a cleaner and better-organized tab context menu. Vivaldi says the new version is more intuitive and easier to use. Another important change is the ability to define a custom DNS provider with support for DNS over HTTPS. Finally, here are some of the under-the-hood improvements in Vivaldi 7.5: Address Bar: Fixed focus weirdness, suggestion hiccups, and dropdown quirks Ad Blocker: Now supports badfilter, strict3p, and strict1p rules Bookmarks & Notes: Better drag-and-drop, with clearer visual feedback Mail & Calendar: Smarter threading, invite handling, and polish throughout Dashboard & Widgets: Layout tweaks, transparency improvements, drag-and-drop goodness Quick Commands: Now shows synced tabs and handles errors more gracefully Settings: UI improvements across the board, from DNS input to workspace rules visibility You can find the complete changelog for Vivaldi 7.5 in a blog post on the official website. If you want to try this highly customizable browser, download it using this link.
    • "While users may say they do not want their data used for personalized ads, Meta believes that without personalization, user experience declines with an almost 800% rise in ads being marked as “irrelevant” or “repetitive”. The ads might be more irrelevant, but it's not like people crave ads in the first place. My user experience with ads isn't better with personalization, because I don't want them there to begin with. So I might as well have non-personalized ads if I am gonna have ads, because then I at least get tracked less, and that makes it a better user experience for me.
    • The fact that they didn't offer a non-personalized ad-supported option, when they were mandated by law, was the final nail in the coffin in my case.
  • Recent Achievements

    • Week One Done
      BeeJay_Balu earned a badge
      Week One Done
    • Week One Done
      filminutz earned a badge
      Week One Done
    • Reacting Well
      SteveJaye earned a badge
      Reacting Well
    • One Month Later
      MadMung0 earned a badge
      One Month Later
    • One Month Later
      Uranus_enjoyer earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      446
    2. 2
      ATLien_0
      161
    3. 3
      +FloatingFatMan
      147
    4. 4
      Nick H.
      65
    5. 5
      +thexfile
      62
  • Tell a friend

    Love Neowin? Tell a friend!