Solved

C# Show Form on button click

Posted on 2012-03-20
5
438 Views
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;
 this.panel1.Controls.Add(fTaskChange);

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;
 this.panel2.Controls.Add(fTaskChange);

I have tried another method too:

TaskChange.TaskChange fTaskChange = new TaskChange.TaskChange();
           
            staticVar = this;
            this.Hide();
            this.panel2.Controls.Add(fTaskChange);
            fTaskChange.Show();

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

Please help.
0
Comment
Question by:Aquarus
  • 3
  • 2
5 Comments
 
LVL 85

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;
this.panel2.Controls.Add(fTaskChange);
fTaskChange.Show()

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.
0
 

Author Comment

by:Aquarus
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.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 37747313
You may need to change FormBorderStyle():
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.formborderstyle.aspx

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

Author Comment

by:Aquarus
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
0
 
LVL 85

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().
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 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

21 Experts available now in Live!

Get 1:1 Help Now