Accessing Form Methods

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • 0 x deadbeef

    #1

    Accessing Form Methods

    I have constructed the following form:

    public class Form1 : System.Windows. Forms.Form
    {
    //code here to declare components
    ....
    public void GenerateNodes()
    {
    FillDirectoryTr ee(tvwSource, true);
    FillDirectoryTr ee(tvwTarget, false);
    }


    public Form1()
    {
    //
    // Required for Windows Form Designer support
    //
    InitializeCompo nent();

    }


    //end of class Form1


    .....more code

    [STAThread]
    static void Main()
    {
    System.Windows. Forms.Form theForm = new Form1();
    theForm.Generat eNodes();

    }

    I want to call the public methods that I have associated with Form1.
    However whenever I try to implement them through an instance of Form1 I
    get a build error saying that "System.Windows .Forms.Form" does not
    contain a definition for GenerateControl s(). Why? Are you not allowed to
    access methods of classes that are derived from Form? =\

  • mia lanui

    #2
    Re: Accessing Form Methods

    right, because you have declared theForm as a System.Windows. Forms.Form, not
    a Form1

    The method you defined in Form1 is not available in the base class
    System.Windows. Forms.Form

    Declare as:

    Form1 theForm

    not:

    System.Windows. Forms.Form theForm


    HTH

    "0 x deadbeef" <semaphore898@y ahoo.com> wrote in message
    news:3F42DE0D.8 030709@yahoo.co m...[color=blue]
    > I have constructed the following form:
    >
    > public class Form1 : System.Windows. Forms.Form
    > {
    > //code here to declare components
    > ...
    > public void GenerateNodes()
    > {
    > FillDirectoryTr ee(tvwSource, true);
    > FillDirectoryTr ee(tvwTarget, false);
    > }
    >
    >
    > public Form1()
    > {
    > //
    > // Required for Windows Form Designer support
    > //
    > InitializeCompo nent();
    >
    > }
    >
    >
    > //end of class Form1
    >
    >
    > ....more code
    >
    > [STAThread]
    > static void Main()
    > {
    > System.Windows. Forms.Form theForm = new Form1();
    > theForm.Generat eNodes();
    >
    > }
    >
    > I want to call the public methods that I have associated with Form1.
    > However whenever I try to implement them through an instance of Form1 I
    > get a build error saying that "System.Windows .Forms.Form" does not
    > contain a definition for GenerateControl s(). Why? Are you not allowed to
    > access methods of classes that are derived from Form? =\
    >[/color]


    Comment

    • 0 x deadbeef

      #3
      Re: Accessing Form Methods

      OMG....duhhh... .man I need sleep


      mia lanui wrote:[color=blue]
      > right, because you have declared theForm as a System.Windows. Forms.Form, not
      > a Form1
      >
      > The method you defined in Form1 is not available in the base class
      > System.Windows. Forms.Form
      >
      > Declare as:
      >
      > Form1 theForm
      >
      > not:
      >
      > System.Windows. Forms.Form theForm
      >
      >
      > HTH
      >
      > "0 x deadbeef" <semaphore898@y ahoo.com> wrote in message
      > news:3F42DE0D.8 030709@yahoo.co m...
      >[color=green]
      >>I have constructed the following form:
      >>
      >>public class Form1 : System.Windows. Forms.Form
      >>{
      >>//code here to declare components
      >>...
      >>public void GenerateNodes()
      >>{
      >> FillDirectoryTr ee(tvwSource, true);
      >> FillDirectoryTr ee(tvwTarget, false);
      >>}
      >>
      >>
      >>public Form1()
      >>{
      >>//
      >>// Required for Windows Form Designer support
      >>//
      >>InitializeCom ponent();
      >>
      >>}
      >>
      >>
      >>//end of class Form1
      >>
      >>
      >>....more code
      >>
      >>[STAThread]
      >>static void Main()
      >>{
      >> System.Windows. Forms.Form theForm = new Form1();
      >>theForm.Gener ateNodes();
      >>
      >>}
      >>
      >>I want to call the public methods that I have associated with Form1.
      >>However whenever I try to implement them through an instance of Form1 I
      >>get a build error saying that "System.Windows .Forms.Form" does not
      >>contain a definition for GenerateControl s(). Why? Are you not allowed to
      >>access methods of classes that are derived from Form? =\
      >>[/color]
      >
      >
      >[/color]

      Comment

      Working...