?
Solved

Windows Forms

Posted on 2004-08-26
8
Medium Priority
?
288 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
[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
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
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!

 
LVL 70

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
 
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 200 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

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.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

770 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