Solved

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

Posted on 2014-12-23
4
94 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 33

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c# - Best approach for objects in functions 3 28
Changes to XXX.exe.config file are not retrieved on restart. 3 50
Coding for the first time 9 70
Set custom font WPF 2 21
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.

726 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