Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 4th, 2007, 02:49 AM
Registered User
 
Join Date: Jan 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Control that detects events

i designed a control that has a label docked Fill (it covers the whole form)
i want to create a MouseHover event.
the problem is that you should disable the lable.

SOLUTION SHOULD BE:
   1. Providing a control with a label filling the control's form.
   2. The control should detect the MouseHover event

Thankyou



 
Old January 4th, 2007, 03:43 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

There is an event on most controls: "OnMouseHover" that will fire when you hover over the control. You need to set up an event handler to that event for the label control.

-Peter
 
Old January 5th, 2007, 02:37 AM
Registered User
 
Join Date: Jan 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Look Peter the problem is that the Events that are attached to the label on the control will not be raised when the whole control is used. You can try some other method.

 
Old January 5th, 2007, 10:18 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What do you mean "when the whole control is used"? How could only part of the control be used? Or do you mean that the events aren't firing when the label control is docked as Fill? Can you try the label without to docked to see if at least the code for the label is working first?

-Peter
 
Old January 9th, 2007, 07:02 AM
Registered User
 
Join Date: Jan 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am sorry for the "when the whole control is used" is used.
What i mean is that when i use the control in a form the required event will not be raised. I know that disabling the label works fine. But i want the label to have a colorful background image and the text displayed should be colorful (which will be lost if the label is disabled).
i guess the problem is that because the label covers the whole control and is enabled, the event on the form cannot be raised. If this is so, the solution should be by raising the form's MouseHover event when the label's MouseHover event is fired.
Can you get me some way of doing this.

10X in advance.

 
Old January 9th, 2007, 10:49 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Why can you not do what you need on the label's mouseover event?

I'm not sure if there's a way to force another object's event to fire from outside that object itself.

-Peter
 
Old January 9th, 2007, 07:54 PM
Authorized User
 
Join Date: Sep 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Eyob_the_pro:

I think the following might work for you.

1. Within your custom control, create an event handler that will be called whenever the child label control's MouseHover event fires.

2. Within that event handler, call your custom control's OnMouseHover method.

Here's some sample code:

Code:
  public partial class MyControl : UserControl
  {

    // Custom control's constructor.
    public MyControl()
    {
      InitializeComponent();

      // Add event handler for child label's MouseHover event...
      objLabel.MouseHover += new EventHandler(objLabel_MouseHover);
    }

    //----------

    // Event handler called whenever child label control MouseHover
    // event occurs.
    void objLabel_MouseHover(object sender, EventArgs e)
    {
      // Fire this custom control's MouseHover event.
      this.OnMouseHover(e);
    }

  }
Cheers.

- Roger Nedel
 
Old February 14th, 2007, 11:58 PM
Registered User
 
Join Date: Dec 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Damn!
This works, and thanks for the solution, but is it possible that there is no other way to solve this problem? I am creating a list control where each list item consists of a picture and six labels. I need all these sub controls to act as one, which means i have to forward a dozen of mouse events x7 sub controls! Almost hundred event handlers for a single list item!?! I can't believe it!...





Similar Threads
Thread Thread Starter Forum Replies Last Post
Events for Control Inside DetailsView AspNetGuy ASP.NET 3.5 Basics 3 June 6th, 2008 02:09 PM
Dynamic control events??? feffe Pro VB 6 21 October 21st, 2007 05:47 PM
Events for custom control in datarepeater?? lauriedthompson VB How-To 0 June 20th, 2007 05:11 AM
Web Custom Control Events junshi ASP.NET 1.0 and 1.1 Professional 1 May 3rd, 2007 01:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.