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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:39:54+00:00 2026-05-12T09:39:54+00:00

Anyone who’s done any UI work with .Net and WinForms is very familiar with

  • 0

Anyone who’s done any UI work with .Net and WinForms is very familiar with this type of code:

TestForm frm = new TestForm();
frm.ShowDialog();

I found myself wishing that a call to show a modal dialog was a little less verbose, more like a static call. Andf there is a simpler way. All you really need, in a simple case, is something like this:

new TestForm().ShowDialog();

Am i missing anything? Could there be any repercussions from this kind of shorthand? E.g. windows messages not handled/routed correctly, dialog’s resources not disposed etc.?

Was working on this when i saw Ray’s feedback:

i suppose an even shorter way would be to create a static member withing TestForm that creates an instance of itself and calls ShowDialog internally. So, this code:

public static DialogResult DoModal()
{
    return new TestForm().ShowDialog();
}

could be invoked thusly:

TestForm.DoModal();
  • 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. Editorial Team
    Editorial Team
    2026-05-12T09:39:55+00:00Added an answer on May 12, 2026 at 9:39 am

    If you don’t want to reuse the form object anywhere in your code you can just use the short form

    new TestForm().ShowDialog();
    

    If you want to do something later with that object then you must assign it to a variable.

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

Sidebar

Related Questions

The following pseudocode works, which is probably no surprise to anyone who's done any
Anyone who can help me make this work? array.each_with_index do |buffer,index| if array[index][8] ==
This should be a snap for anyone who's done it before... I'm trying to
Anyone who know a alternative to this? http://razorjack.net/quicksand/ Maybe something that would actually sort
This is a question for anyone who has the pleasure to work in both
This would be a question for anyone who has code in the App_Code folder
(Bonus internets for anyone who can explain how I can do this in both
Is there anyone who knows this? I have been trying this for the last
Anyone who create a simple delete in codeigniter. help me! . this is my
Anyone who follows Android tags are probably familiar with me. I am having 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.