Solved

Windows Forms

Posted on 2004-08-26
8
283 Views
Last Modified: 2008-02-01
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
Comment
Question by:daveamour
8 Comments
 
LVL 1

Expert Comment

by:develc
ID: 11901337
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
 
LVL 3

Expert Comment

by:GrumbleBot
ID: 11901432
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
 
LVL 19

Author Comment

by:daveamour
ID: 11901467
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
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 11901754
In VB.Net we do something like this:

        With frm
            .MdiParent = Me
            .Show()
            .Dock = DockStyle.Fill
        End With
0
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.

 
LVL 19

Author Comment

by:daveamour
ID: 11901767
Thanks emoreu but that is for an MDI app and mine is SDI.

Dave
0
 
LVL 10

Accepted Solution

by:
EBatista earned 50 total points
ID: 11901892
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
 
LVL 19

Author Comment

by:daveamour
ID: 11901960
Thanks EBastica your the man!

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

Thanks mate.

Dave
0
 
LVL 10

Expert Comment

by:EBatista
ID: 11902330
time-matter issues dave :)

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

regards all
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

Suggested Solutions

Title # Comments Views Activity
Achieve json result 2 65
IO.FileSystemWatcher dies when used in Powershell 1 45
Iterate two lists and remove inactive 11 49
SQL Exceptions 3 37
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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

911 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

16 Experts available now in Live!

Get 1:1 Help Now