Solved

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

Posted on 2014-12-23
4
74 Views
Last Modified: 2015-01-07
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

0
Comment
Question by:Sheryl Landis
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
Sammy earned 500 total points
Comment Utility
Show is a method and should be called as such
Show();
private void button1_Click(object sender, EventArgs e)
        {
            FormInvoice frmInvoice = new FormInvoice();
            frmInvoice.Show();       
        }

Open in new window

More about the show method
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.show%28v=vs.110%29.aspx
0
 

Author Comment

by:Sheryl Landis
Comment Utility
That's it, thank you!
0
 
LVL 27

Expert Comment

by:Sammy
Comment Utility
You welcome
0
 
LVL 32

Expert Comment

by:it_saige
Comment Utility
*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-
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now