C# Show Form on button click

Posted on 2012-03-20
Last Modified: 2012-03-21
I am relatively new in C#.

I have the Form1 with the Button on it.  On Button_click event I need to open another form.

Since I am working with in a structured project I first tried to use method that already proved working.

Below are 3 lines of codes that worked for me when the form fTaskChange was to be opened from the Tree node click on another form - another "this"(means form).  This form "this" has panel1 on it.  Below is how it worked to open the Form fTaskChange in the panel1.

TaskChange.TaskChange fTaskChange = new TaskChange.TaskChange();
fTaskChange.Dock = DockStyle.Fill;

But under Button_click method on another form if I step through codes I see that all the tasks that have to happen before the form fTaskChange show up are completed, but the form is not seen.

TaskChange.TaskChange fTaskChange = new TaskChange.TaskChange();
fTaskChange.Dock = DockStyle.Fill;

I have tried another method too:

TaskChange.TaskChange fTaskChange = new TaskChange.TaskChange();
            staticVar = this;

This made "this" form to hide, but I don't see my form.

Please help.
Question by:Aquarus
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
  • 3
  • 2
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 37745104
Not sure...but if you really are dealing with FORMS, then TopLevel() needs to be false:
TaskChange.TaskChange fTaskChange = new TaskChange.TaskChange();
fTaskChange.TopLevel = false;
fTaskChange.Dock = DockStyle.Fill;

Open in new window

Also, if there was another form already in Panel2 then you'd need to either clear out Panel2, or bring the new form to the front.

Author Comment

ID: 37747303
What was actually happenning, is that structured by the project I used UserControl instead of WINDOWS .FOrm class.  I have changed that and now I see the form modally.

But it has a weird size - very small.  It is 750 / 600 in pixels in design view, but on run time - it is smal and its borders are not even sizable.

Please help.  Time issue already.
LVL 86

Accepted Solution

Mike Tomlinson earned 500 total points
ID: 37747313
You may need to change FormBorderStyle():

The change in size could be a Font issue.  Are you changing it at run-time?

Author Comment

ID: 37747430
FormBorderStyle is set to sizable.
 But the Autosize was set to True.  I have changed it to False and removed Grow and Shrink from Autosize Mode. Now it shows in its correct size.

Now I need to balance the deimnsions of grid on the form and the form itself.  I'll be continue working but If there is anything that may speed me up on this - i will appreciate greatly
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 37747608
"Balance" it how?  You can use Anchor()/Dock() to control the sizing of controls.  For more control, use the TableLayoutPanel().

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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