Solved

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

Posted on 2014-12-23
4
98 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
Sammy earned 500 total points
ID: 40515405
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
ID: 40515449
That's it, thank you!
0
 
LVL 27

Expert Comment

by:Sammy
ID: 40515450
You welcome
0
 
LVL 34

Expert Comment

by:it_saige
ID: 40515477
*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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

707 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