473,395 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

delegate proble?

7
my application contain three forms:

frmMain(mdiContainer)

frmEditable

frmTools

Expand|Select|Wrap|Line Numbers
  1. private void frmEditable_MouseDown(object sender, MouseEventArgs e)
  2.  
  3. {
  4.  
  5.        choice0Enable = true;
  6.  
  7.       if (choice0Enable)
  8.  
  9.       {
  10.  
  11.        Generating(0, e.X, e.Y, 20, 20);
  12.  
  13.       }
  14.  
  15. }
i want to capture this events using delegate..it is located in frmEditAble form.

actually i want that when a user click on frmTools's Rectangle label. it should be displayed a rectangle on frmEditable thorugh delegate..

how can i do this
Sep 27 '08 #1
1 940
tlhintoq
3,525 Expert 2GB
Is there a reason it *has* to be through a delegate?
A Label control already has an event you can subscribe to of "Click".
When your parent form creates child a, and child b, it can subscribe b to the Label.Click event of a control in a.

Otherwise, you define an event (and EventArguments) for each tool in your pallet. Then raise that event when it is clicked. Your other forms subscribe (or listen for) that event to be raised, then react accordingly.

Here's a sample of how I do my Help events to show a custom messagebox with helpful text. It's triggered much as you described: My someone clicking a label next to a control.


Expand|Select|Wrap|Line Numbers
  1.         #region HelpSystem events
  2.         public delegate void HelpSystemDelegate(object sender, HelpSystemEventArgs e);
  3.         public class HelpSystemEventArgs : EventArgs
  4.         {
  5.             private string szHelpMsg;
  6.             public string HelpMsg
  7.             {
  8.                 get { return szHelpMsg; }
  9.                 set { szHelpMsg = value; }
  10.             }
  11.  
  12.             public HelpSystemEventArgs(string HelpMsg)
  13.             {
  14.                 szHelpMsg = HelpMsg;
  15.             }
  16.         }
  17.         public event HelpSystemDelegate RaiseHelp;
  18.         #endregion
  19.         #region Control Help calls
  20.         private void lblWidget_Click(object sender, EventArgs e)
  21.         {
  22.             ShowHelp("This is the Widget control. It does Widgety things.");
  23.         }
  24.         void ShowHelp(string HelpMessage)
  25.         {
  26.             if (cboEvent.SelectedItem != null)
  27.             {
  28.                 HelpSystemEventArgs args = new HelpSystemEventArgs(HelpMessage);
  29.                 if (RaiseHelp != null) RaiseHelp(this, args);
  30.             }
  31.         }
  32.  
  33.  
Here you should see EventArgs for the event, the event itself, a delegate for it, a method that gets called with your label is clicked which calls the all-purpose "ShowHelp" method.
Sep 28 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: pintur | last post by:
The message is: SQL1036C Errore di I/O durante l' accesso al database. SQLSTATE=58030 what is the proble? what for restore tables? thanks
3
by: Minh Khoa | last post by:
Please give me more information about delegate and its usage? Why do i use it and when?
4
by: ^MisterJingo^ | last post by:
Hi all, I've been trying to get my head around delegates. The book i'm using had a single example, not much explaination, and didn't show how to set up a delegate and pass variables in and out...
7
by: Ant | last post by:
Hello, Very simple question but one I need clarified. Which part of the statement below is considered the 'delegate'? Is it the 'new System.EventHandler' or the btnAccept_Click? or is it...
6
by: David Veeneman | last post by:
I have several events that pass a value in their event args. One event passes an int, another a string, another a DateTime, and so on. Rather than creating a separate set of event args for each...
1
by: Quimbly | last post by:
I'm having some problems comparing delegates. In all sample projects I create, I can't get the problem to occur, but there is definitely a problem with my production code. I can't give all the...
11
by: matsi.inc | last post by:
I am looking to make something like a delegate that i can use in my projects but am having a hard time getting started. The behavior I am most interested in is how a delegate changes it's Invoke...
26
by: raylopez99 | last post by:
Here is a good example that shows generic delegate types. Read this through and you'll have an excellent understanding of how to use these types. You might say that the combination of the generic...
10
by: vcquestions | last post by:
Hi. Is there way to have a function pointer to a delegate in c++/cli that would allow me to pass delegates with the same signatures as parameters to a method? I'm working with managed code. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.