Solved

Windows Forms

Posted on 2004-08-26
8
285 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 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