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 6158123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:54:13+00:00 2026-05-23T20:54:13+00:00

I’m sure I got the title terribly wrong (feel free to make it proper),

  • 0

I’m sure I got the title terribly wrong (feel free to make it proper), but the example code would clear the confusion.

I have something to do like this:

    private void a_Click(object sender, EventArgs e)
    {           
        if (abc = "cat")
            return;

        Form1 f = new Form1(abc);
        f.ShowDialog()
    }

    private void b_Click(object sender, EventArgs e)
    {
        if (abc = "cat")
            return;

        Form2 f = new Form2(abc);
        f.ShowDialog()
    }

    private void c_Click(object sender, EventArgs e)
    {
        if (abc = "cat")
            return;

        Form3 f = new Form3(abc);
        f.ShowDialog()
    }

Now how can I write a single method to show up forms like these by passing the form class itself. Or am I spoiling the very concept of classes and objects? Something like this:

   private void ShowForms(Form F)
   {
       if (abc = "cat")
           return;

       F f = new F(abc);
         f.Showdialog();
   }

and then

    private void a_Click(object sender, EventArgs e)
    {
        ShowForms(Form1); // I cant pass string abc from here..
    }

Thanks. I can live without it, but would be of great help if I can have one.

EDIT: I’ve slightly modified my example to make my requirement clearer, since the first answer wasnt exactly addressing my issue. Apologies.

EDIT2: My Question is not how to get my program running (that would be too trivial), but how to precisely use a third common function to show up forms by passing form as argument (as described above).

  • 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-23T20:54:14+00:00Added an answer on May 23, 2026 at 8:54 pm

    You could use generics and an interface to accomplish this without vs2010 and .net 2.0.

    The interface would be something like

    public interface IAbcForm { public string Abc {get;set;} }
    

    because you will need a property or setter method to set your parameter.

    The ShowForm method will look like:

    private void ShowForm<T>(string parameter) where T:IAbcForm, new
    {
        if(parameter == "cat") return;
    
        var form = new T();
        form.Abc = parameter;
        form.ShowDialog();
    }
    

    Usage would be:

    ShowForm<Form1>("abc");
    ShowForm<Form2>("abc");
    ShowForm<Form3>("abc");
    

    Your forms will have to implement the interface:

    public class Form1 : Form, IAbcForm
    {
        // use backing field when .net 2.0 does not support auto properties
        public string Abc { get;set; }
    
        public Form1() {}
    
        // I think your current constructor looks something like this:
        public Form1(string abc) { Abc = abc; }
    }
    

    }

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

Sidebar

Related Questions

i got an object with contents of html markup in it, for example: string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.