delegate proble?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maifs
    New Member
    • Sep 2008
    • 7

    delegate proble?

    my application contain three forms:

    frmMain(mdiCont ainer)

    frmEditable

    frmTools

    Code:
    private void frmEditable_MouseDown(object sender, MouseEventArgs e)
    
    {
    
           choice0Enable = true;
    
          if (choice0Enable)
    
          {
    
           Generating(0, e.X, e.Y, 20, 20);
    
          }
    
    }
    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
    Last edited by kenobewan; Sep 27 '08, 01:00 PM. Reason: Use code tags
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    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.


    Code:
            #region HelpSystem events
            public delegate void HelpSystemDelegate(object sender, HelpSystemEventArgs e);
            public class HelpSystemEventArgs : EventArgs
            {
                private string szHelpMsg;
                public string HelpMsg
                {
                    get { return szHelpMsg; }
                    set { szHelpMsg = value; }
                }
    
                public HelpSystemEventArgs(string HelpMsg)
                {
                    szHelpMsg = HelpMsg;
                }
            }
            public event HelpSystemDelegate RaiseHelp;
            #endregion
            #region Control Help calls
            private void lblWidget_Click(object sender, EventArgs e)
            {
                ShowHelp("This is the Widget control. It does Widgety things.");
            }
            void ShowHelp(string HelpMessage)
            {
                if (cboEvent.SelectedItem != null)
                {
                    HelpSystemEventArgs args = new HelpSystemEventArgs(HelpMessage);
                    if (RaiseHelp != null) RaiseHelp(this, args);
                }
            }
    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.

    Comment

    Working...