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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:13:43+00:00 2026-06-13T21:13:43+00:00

I have a function I want to make generic to display forms. I want

  • 0

I have a function I want to make generic to display forms. I want the function to check if the form is opened already and if so bring it to the top if not create a new instance of the form and show it.

The first part of checking if the form is open is all good but I am having casting from T and creating a new form object of type T. I have used this line of code to create an instance of the form obj = Activator.CreateInstance<T>(); but it does not show all the methods and properties in intellisense. Where as the code Form x = new Form1.
x
will show all the methods and properties.

I am sure I am doing something wrong here any shine some light for me please.

     private static void ShowForm<T>(  )
    {
        T obj = default( T );

        List<T> opened = FormManager.GetListOfOpenForms<T>();
        if ( opened.Count == 0 )
        {
            // not opened

            // obj does not show all properties and methods
            obj = Activator.CreateInstance<T>();


            // x shows all properties and methods
            frmLogin x = new frmLogin();

        }
        else
        {
            // opened

        }

    }
  • 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-13T21:13:44+00:00Added an answer on June 13, 2026 at 9:13 pm

    You need to constrain T to inherit Form:

    private static void ShowForm<T>() where T : Form, new()
    

    Once the compiler knows that T is guaranteed to inherit Form, you’ll be able to use all members defined in Form or its base classes.

    The more general answer to your question would be to cast obj to Form.

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

Sidebar

Related Questions

using .NET 3.5. I have a function I want to make multithreaded calls to.
I have this function and I want to make the var category to have
I have a PHP function that I want to make available publically on the
Say, i have a function which returns a reference and i want to make
I want to make a reverse string function and I have done it like
I want to make a kind of generic function which gets executed and -
I want to create a generic function that takes any Map & a String
I have a function that processes a row vector. I want to make it
I want to create a generic function with signature like this : void funcName<T>()
I'm attempting to make a generic query executer function. I want to be able

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.