Avatar of Sheryl Landis
Sheryl Landis

asked on 

How to show a form from a button in C# 2012?

The following code should work, but instead I get an error for the line:

frmInvoice.Show;  
Error: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement.

What am I doing wrong?

 
 private void button1_Click(object sender, EventArgs e)
        {
            FormInvoice frmInvoice = new FormInvoice();
            frmInvoice.Show;       
        }

Open in new window

C#

Avatar of undefined
Last Comment
it_saige
ASKER CERTIFIED SOLUTION
Avatar of Sammy
Sammy
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Sheryl Landis
Sheryl Landis

ASKER

That's it, thank you!
Avatar of Sammy
Sammy
Flag of Canada image

You welcome
Avatar of it_saige
it_saige
Flag of United States of America image

*No Points*

You also have an additional method called ShowDialog.  The difference is that Show does not block your code and allows for the user to move between the parent/child windows at will.  Show is perfect for scenarios where the parent/child are not codependent.

In cases where the parent is launching a child window because the child is responsible for additional logic and/or information that will be displayed later on the parent, that is when ShowDialog is beneficial.

Show vs. ShowDialog

-saige-
C#
C#

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

98K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo