Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5930377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:32:50+00:00 2026-05-22T14:32:50+00:00

I have two Froms (Form1, Form2) and I’m getting this Error when I try

  • 0

I have two Froms (Form1, Form2) and I’m getting this Error when I try to call a public function of Form2 from the Form1 class.

Error 1 ‘System.Windows.Forms.Form’ does not contain a definition for ‘getText1’ and no extension method ‘getText1’ accepting a first argument of type ‘System.Windows.Forms.Form’ could be found (are you missing a using directive or an assembly reference?) C:\Users…\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 24 17 WindowsFormsApplication1.

  public partial class Form1 : Form
  {

    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Form gen = new Form2();
        gen.ShowDialog();
        gen.getText1(); // I'm getting the error here !!!
    }
}

public partial class Form2 : Form
{
    public string Text1;

    public Form2()
    {
        InitializeComponent();
    }

    public string getText1()
    {
        return Text1;
    }

    public void setText1(string txt)
    {
        Text1 = txt;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        this.setText1(txt1.Text);
        this.Close();
    }
}

Any ideas? Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:32:51+00:00Added an answer on May 22, 2026 at 2:32 pm

    The compile-time type of gen is currently just Form. Change that and it should be fine:

    Form2 gen = new Form2();
    gen.ShowDialog();
    gen.getText1();
    

    Note that this has nothing to do with GUIs in particular – it’s just normal C#. If you’re just starting out with C#, I suggest that you learn it with console apps instead – there are far fewer oddities that way, and you can learn one thing at a time.

    I’d recommend that you start following .NET naming conventions, use properties as appropriate, and dispose of forms too:

    using (Form2 gen = new Form2())
    {
        gen.ShowDialog();
        string text = gen.Text1;
    }
    

    (Even then, Text1 isn’t a very descriptive name…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two forms (Form1 and Form2). On Form1 there is a 'public int
Consider this scenario: I have two forms (Form1 and Form2). When a button is
I have two forms Form1 and Form2 I am opening Form2 from Form1 on
Let say I have are two WPF forms: Form1 and Form2 . Form1 contains
Now, I have two forms, called form1 and form2, in the form1 there's a
I have two forms named form1 and form2 in a php page. I have
Suppose I have two forms: Form1 and Form2. Form2 has a text control named
i need your help. I have two forms, Form1 and Form2. In Form1 i
I have two forms in a page <form id=form1> </form> <form id=form2> </form> in
I have this code: <div class=LoginBox> <form id=form2 runat=server> <asp:ContentPlaceHolder ID=ContentPlaceHolder2 runat=server> lolbags </asp:ContentPlaceHolder>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.