Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. delegate problem?

delegate problem?

Scheduled Pinned Locked Moved C#
questionhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maifs
    wrote on last edited by
    #1

    my application contain three forms: frmMain(mdiContainer) frmEditable frmTools private void frmEditable_MouseDown(object sender, MouseEventArgs e) { choice1Enable = true; if (choice1Enable) { 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

    hghghgh

    L 1 Reply Last reply
    0
    • M maifs

      my application contain three forms: frmMain(mdiContainer) frmEditable frmTools private void frmEditable_MouseDown(object sender, MouseEventArgs e) { choice1Enable = true; if (choice1Enable) { 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

      hghghgh

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I'm not sure I entirely understand your question, is this what you are looking for? First, you need to create an EventArgs class that will notify the listeners which rectangle should be genereated:

      public class NewRectangleEventArgs : EventArgs
      {
      public int ID;
      public int X;
      public int Y;
      public int Width;
      public int Height;

      public NewRectangleEventArgs(int ID, int X, int Y, int Width, int Height)
      {
      this.ID = ID;
      this.X = X;
      this.Y = Y;
      this.Width = Width;
      this.Height = Height;
      }
      }

      Next, you need to create an event in your for class that others can register to:

      public EventHandler<NewRectangleEventArgs> OnNewRectangle;

      Now, other classes can register the event when they have a handle to your form:

      form.OnNewRectangle += new EventHandler<NewRectangleEventArgs>(NewRectangleEventHandler);

      With NewRectangleEventHandler being a method like:

      public void NewRectangleEventHandler(object sender, NewRectangleEventArgs args)
      {

      }

      Finally, your form needs to raise the event whenever a new rectangle should be generated:

      if(OnNewRectangle != null)
      OnNewRectangle(this, new NewRectangleEventArgs(0, e.X, e.Y, 20, 20));

      Hope this helps :) regards

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups