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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:19:37+00:00 2026-05-11T08:19:37+00:00

Say I want to open a new form.. TestForm test = new TestForm(); What

  • 0

Say I want to open a new form..

TestForm test = new TestForm();  

What is the good way to close it? More precisely, is only calling close() ok? Should I use the using() {} so dispose() is called ? And finally, suppose there is a dialog that should have only one instance of a dialog opened, is there a well ‘known’ pattern? I’ve got different choices such as storing it in a static field, and null-‘ing’ it when it is closed..

Thanks

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T08:19:38+00:00Added an answer on May 11, 2026 at 8:19 am

    Well in terms of your single instance dialog (if it’s modal you don’t have to worry) you can make the constructor private and provide a public static method to access the form.

    public class MyForm : Form {     protected MyForm()     {     }      protected int MyValue { get; set; }      public static int GetResult()     {         using(MyForm myForm = new MyForm())         {             if(myForm.ShowDialog == DialogResult.OK)                 return myForm.MyValue;            }         return -1;     } } 

    That would force calls to by in the form of..

    int someValue = MyForm.GetResult(); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I open a form and want to attach a command to it
I want to open a new browser window with a specific url (say http://google.com
Let's say you want to start contributing to an open source project with thousands
I want to open a new browser window without menu bar, tool bar or
Say I want to create a card class. and want to have enums for
Say you want to filter elements out of a List. Running this code triggers
Say you want a simple maze on an N by M grid, with one
Say you want to generate a matched list of identifiers and strings enum {
Say I want to copy the contents of a directory excluding files and folders
Say I want to create vb.net application in Visual studio 2005. What is the

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.