Solved

Windows Forms

Posted on 2004-08-26
8
279 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
In VB.Net we do something like this:

        With frm
            .MdiParent = Me
            .Show()
            .Dock = DockStyle.Fill
        End With
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 19

Author Comment

by:daveamour
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
time-matter issues dave :)

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

regards all
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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 Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

7 Experts available now in Live!

Get 1:1 Help Now