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. How to implement a Click event in an owner drawn object.

How to implement a Click event in an owner drawn object.

Scheduled Pinned Locked Moved C#
graphicshelptutorialquestion
4 Posts 3 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.
  • G Offline
    G Offline
    gr8tushar
    wrote on last edited by
    #1

    hii i am trying to make an flowchart kind of editor. i can draw an object. now i want to implement a click event in that object so that whenever it is selected, i can do something. the code for the object class is : public class MyObject { private int m_X; private int m_Y; private int m_Width; private int m_Height; private string m_Text; public MyObject() { m_X=m_Y=m_Width=m_Height=0; m_Text=null; } public MyObject(int s) { m_X=m_Y=m_Width=m_Height=0; m_Text=s.ToString(); } public MyObject(int x,int y, int width,int height) { m_X=x; m_Y=y; m_Width= width; m_Height= height; m_Text="M"; } public MyObject(int x,int y, int width,int height,string s) { m_X=x; m_Y=y; m_Width= width; m_Height= height; m_Text=s; } public MyObject (string s) { string[] temp = new string [5]; char[] c = new Char [2]; c[0] = ';'; temp = s.Split(c,6); X= Int32.Parse (temp[0]); Y=Int32.Parse (temp[1]); Width = Int32.Parse (temp[2]); Height = Int32.Parse (temp[3]); Text = temp[4]; } public int X { get { return m_X;} set { m_X= value;} } public int Y { get { return m_Y;} set { m_Y= value;} } public int Width { get { return m_Width;} set { m_Width= value;} } public int Height { get { return m_Height;} set { m_Height= value;} } public string Text { get { return m_Text;} set { m_Text= value;} } public void Draw (Graphics g) { //Graphics g= f.CreateGraphics(); g.DrawEllipse(System.Drawing.Pens.Chocolate ,X,Y,Width,Height); g.DrawString(Text,new Font("Arial",12),System.Drawing.Brushes.BlueViolet,X,Y); } public void WriteToFile(StreamWriter w) { w.WriteLine(X +";"+Y + ";" + Width + ";" + Height + ";" + Text); } public void Delete() { // this.Finalize (); } } } Please someone help me that if how do i do this : if i click this object then a messagebox if poped up ! thanx in advance

    B 1 Reply Last reply
    0
    • G gr8tushar

      hii i am trying to make an flowchart kind of editor. i can draw an object. now i want to implement a click event in that object so that whenever it is selected, i can do something. the code for the object class is : public class MyObject { private int m_X; private int m_Y; private int m_Width; private int m_Height; private string m_Text; public MyObject() { m_X=m_Y=m_Width=m_Height=0; m_Text=null; } public MyObject(int s) { m_X=m_Y=m_Width=m_Height=0; m_Text=s.ToString(); } public MyObject(int x,int y, int width,int height) { m_X=x; m_Y=y; m_Width= width; m_Height= height; m_Text="M"; } public MyObject(int x,int y, int width,int height,string s) { m_X=x; m_Y=y; m_Width= width; m_Height= height; m_Text=s; } public MyObject (string s) { string[] temp = new string [5]; char[] c = new Char [2]; c[0] = ';'; temp = s.Split(c,6); X= Int32.Parse (temp[0]); Y=Int32.Parse (temp[1]); Width = Int32.Parse (temp[2]); Height = Int32.Parse (temp[3]); Text = temp[4]; } public int X { get { return m_X;} set { m_X= value;} } public int Y { get { return m_Y;} set { m_Y= value;} } public int Width { get { return m_Width;} set { m_Width= value;} } public int Height { get { return m_Height;} set { m_Height= value;} } public string Text { get { return m_Text;} set { m_Text= value;} } public void Draw (Graphics g) { //Graphics g= f.CreateGraphics(); g.DrawEllipse(System.Drawing.Pens.Chocolate ,X,Y,Width,Height); g.DrawString(Text,new Font("Arial",12),System.Drawing.Brushes.BlueViolet,X,Y); } public void WriteToFile(StreamWriter w) { w.WriteLine(X +";"+Y + ";" + Width + ";" + Height + ";" + Text); } public void Delete() { // this.Finalize (); } } } Please someone help me that if how do i do this : if i click this object then a messagebox if poped up ! thanx in advance

      B Offline
      B Offline
      Bob Bonser
      wrote on last edited by
      #2

      Create your object as a new user control in your project (Add new item, UI, User control). The simply add the object to you main from (from the toolbox/My User Controls) and progam the "click" event for the object.

      G 1 Reply Last reply
      0
      • B Bob Bonser

        Create your object as a new user control in your project (Add new item, UI, User control). The simply add the object to you main from (from the toolbox/My User Controls) and progam the "click" event for the object.

        G Offline
        G Offline
        gr8tushar
        wrote on last edited by
        #3

        this is not a user control. i even tried inheriting my class from usercontrol but then also the click event is not working. The click event only works on the form. its not working on the Myobjects.. i don't know y. I feel as if i am totally lost.. please someone help me !!!

        L 1 Reply Last reply
        0
        • G gr8tushar

          this is not a user control. i even tried inheriting my class from usercontrol but then also the click event is not working. The click event only works on the form. its not working on the Myobjects.. i don't know y. I feel as if i am totally lost.. please someone help me !!!

          L Offline
          L Offline
          Luis Alonso Ramos
          wrote on last edited by
          #4

          piscian1982 wrote: The click event only works on the form. its not working on the Myobjects Because your object is not a control that can trap user events. It draws itself on the form, but you would need the form to trap the click event and forward to your object. Or your object could install an event handler for the Click event of the form, and check in the delegate if the location of the click is inside your object, and if so, react accordingly. If the point is outside your object, just let the form process its event. -- LuisR


          Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

          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