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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:58:55+00:00 2026-06-18T09:58:55+00:00

I am creating a MDI form and I have a method that loads the

  • 0

I am creating a MDI form and I have a method that loads the different forms. Now I need to make a little modification – I need to add functionality that calls one child form from within another child form.

Because I need this in several different places I made a new class from who all the classes that need this functionality inherits. I want to make it work with generic types so I can pass every form class that I may need like LoadAForm(MyForm1) or LoadAForm(MyForm2) and so on.. I hope I it’s clear what I want as final result.

I tried this:

protected void LoadAForm<T>(ref T sender)
{
    MainForm frm = this.MdiParent as MainForm;
    T temp;
    if (frm != null)
    {
        sender  = SingletonFormProvider.GetInstance<temp>(frm, true);
        sender.MdiParent = frm;
        sender.Dock = DockStyle.Fill;
        sender.Show();
    }
}

which doesn’t work. But I have almost no experience with generics even more when they are used in methods, so I don’t know how to go on.

What I get as an error using this syntax is The type or namespace "temp" could not be found...". I'm not even sure that this is the way to do it.GetInstance<>` has to take an argument of the same type as the type of the form I’m calling.

  • 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-06-18T09:58:57+00:00Added an answer on June 18, 2026 at 9:58 am

    You need to use the type parameter, not the variable name:

    sender = SingletonFormProvider.GetInstance<T>(frm, true);
    

    Also, to ensure that T is valid (as your comment suggests) you will need to constrain it:

    protected void LoadAForm<T>(ref T sender) where T : Form
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Creating liquid layouts is an immense pain. Now, I totally understand that tables should
When creating a MDI parent, the entire inside of the form is made the
I need help solving the problem below. I am creating a Windows Forms Application
Creating a couple forms and I have styled the text inputs and textareas the
I'm creating an application, where the main form that is shown when the application
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
I creating a web application using JSF,Hibernate,Spring. I have added a filter for checking
Creating an iPhone App in xCode, and I need to populate it with data
Creating an accordion - on the slide - the elements underneath the element that
Creating a browser based single-page browser based RIA. Would like to make use of

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.