• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • Last Modified:

Windows Forms

I have a windows forms application and I am using C#

I have a main form which acts as a menu.  When the user clicks on a menu option I want to open a new form but this new form to be the same size and position as the main form so that if the use has moved the form around the screen it will be tidy and look like there is just one form open as they are on top of each other.

I achieved this by calling my form as follows:

            private void btnSearch_Click(object sender, System.EventArgs e)
            {
                  Forms.frmSearch objSearchForm = new Forms.frmSearch();

                  objSearchForm.Visible = false;
                  
                  objSearchForm.Show();

                  objSearchForm.Left = this.Left;
                  objSearchForm.Top = this.Top;

                  objSearchForm.Visible = true;
            }

This does work ok but the screen flashes as the window is moving from its original location to the new one.

I guess I must be doig this the wrong way.  Any thoughts on how to stop the flashing or a right way to do this.  I tried setting the Left and Top before calling Form.Show but this didn't work.

Thanks

Dave
0
daveamour
Asked:
daveamour
1 Solution
 
develcCommented:
Do you already try out the location property of the forms?

For example : you can demand the location property of the main form and when you call the other form you set the location property of the mainform to the new form.

Good luck
develc

0
 
GrumbleBotCommented:
Just modify your code as follows. You don't need to handle visible property when using show();


          private void btnSearch_Click(object sender, System.EventArgs e)
          {
               Forms.frmSearch objSearchForm = new Forms.frmSearch();

               objSearchForm.Show();
               objSearchForm.Left = this.Left;
               objSearchForm.Top = this.Top;
               
          }

That should work. Also a suggestion for the other form that you want to hide behind it. If the menu form is not needed after you popup this new window you can just hide it with:

              objMenuForm.Hide();

good luck


0
 
daveamourAuthor Commented:
develc - I did try this and it works fine but my problem is that the window is painted on the screen and then moved to the new location which causes the sceen to flash.

Same problem with your code GrumbleBot which is actually no differnt to mine other than I was trying to hide the form until it had arrived at its new location!

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Éric MoreauSenior .Net ConsultantCommented:
In VB.Net we do something like this:

        With frm
            .MdiParent = Me
            .Show()
            .Dock = DockStyle.Fill
        End With
0
 
daveamourAuthor Commented:
Thanks emoreu but that is for an MDI app and mine is SDI.

Dave
0
 
EBatistaCommented:
set up the StartPosition property to "Manual", this prevent the system from drawing the form in a default position, then when you say objSearchForm.Show(), the system will draw the form in the desired position and will not be repositioning it.

objSearchForm.StartPosition=FormStartPosition.Manual;
objSearchForm.Left = this.Left;
objSearchForm.Top = this.Top;
objSearchForm.Show();

regards
Elio
0
 
daveamourAuthor Commented:
Thanks EBastica your the man!

These things are so simple and I guess just down to experience.

Thanks mate.

Dave
0
 
EBatistaCommented:
time-matter issues dave :)

dont be worry, remember,  amateurs built the arch, professionals built the titanic

regards all
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now