none
a class this class derives from already defines the method - problem RRS feed

  • Question

  • hi

     

    I want to connect between textbox control (from a derived from ) to a protected method from the base from. it's work but it is not let me to watch the derived form now, this is the msg :

     "The method 'ParameterTxt_Change' cannot be the method for an event because a class this class derives from already defines the method."

     

    what should i do ?

    again  - at runtime it's work perfect !!!

     

    thanks :-)

     

     
      

     

    Sunday, November 18, 2007 12:33 PM

Answers

  • The solution for this problem which I found:

     

    To make event handler method in all derived classes (as it is generated by designer), but move it's common code to the method of the base class.

     

    E.g. there is Dialog1: Dialog and Dialog2: Dialog, both with buttons 'Cancel', which could be displayed differently, but you want them to behaive in the same way,

    so in Dialog1 and Dialog2:

            private void buttonCancel_Click(object sender, System.EventArgs e)

            {

                this.dialog_buttonCancel_Click(sender, e);

            }

    in Dialog:

            protected void dialog_buttonCancel_Click(object sender, EventArgs e)

            {

                // your mega reusable code for handling click event

            }

     

    Wednesday, October 19, 2011 3:02 PM

All replies

  • It is hard to give specific answers without specific code examples, so I will provide a broad answer. 

     

    It sounds like what you are trying to do might not be consistent with good OOP, Object Oriented Programming, practices.  If 2 two classes need access to the same method, define that method in a separate class.  AH, but the form designer makes your textbox controls private, so you have to define your methods within a given form's class.  Or do you....

     

    Rudedog

    "Stuck in a procedural world since 1971."

    PDP-8

    ASR-33

    Sunday, November 18, 2007 2:26 PM
    Moderator
  •  Rudedog2 wrote:

    It is hard to give specific answers without specific code examples, so I will provide a broad answer. 

     

    It sounds like what you are trying to do might not be consistent with good OOP, Object Oriented Programming, practices.  If 2 two classes need access to the same method, define that method in a separate class.  AH, but the form designer makes your textbox controls private, so you have to define your methods within a given form's class.  Or do you....

     

    Rudedog

    "Stuck in a procedural world since 1971."

    PDP-8

    ASR-33

     

     

    Rudedog

     

    thank's for your answer but this isn't the right answer i'm afraid but thank you any way

     

    i should see my lectures wendsday i will ask him about it

     

    maybe i will also upload the answer

     

     

    itzika

     

    Sunday, November 18, 2007 3:40 PM
  • Sounds like you are trying to re-write/override an inherited method, which is defined by a class , not an interface.

     

    Sunday, November 18, 2007 5:17 PM
    Moderator
  • Hi itzika,

    It seems that you redefine a method. Would you please a snippet code for analysis?

     

    Friday, November 23, 2007 7:54 AM
  • The solution for this problem which I found:

     

    To make event handler method in all derived classes (as it is generated by designer), but move it's common code to the method of the base class.

     

    E.g. there is Dialog1: Dialog and Dialog2: Dialog, both with buttons 'Cancel', which could be displayed differently, but you want them to behaive in the same way,

    so in Dialog1 and Dialog2:

            private void buttonCancel_Click(object sender, System.EventArgs e)

            {

                this.dialog_buttonCancel_Click(sender, e);

            }

    in Dialog:

            protected void dialog_buttonCancel_Click(object sender, EventArgs e)

            {

                // your mega reusable code for handling click event

            }

     

    Wednesday, October 19, 2011 3:02 PM
  • This solved my problem,

    http://bytes.com/topic/c-sharp/answers/821539-placing-event-handler-base-class

    Is there is anything wrong with that. Please let me know.

    Regards

    Syam

    Monday, December 10, 2012 7:12 AM