Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / May 2006

Tip: Looking for answers? Try searching our database.

Making multiple forms same size and position

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Enrico Campidoglio - 29 May 2006 11:53 GMT
Hi,

I have a Windows Forms application written in .NET 2.0 made up of multiple
forms. These forms use visual inheritance to share a common layout while
presenting some specific content.
The application switches among the different forms by showing/hiding them
making only one form visible at a time.

The problem arises when the user maximizes, resizes or repositions the
active form. What happens is that whenever another form is made visible this
won't have the same window status or position of the previous one which is
visually very disturbing.

I still haven't found any good solution to this problem. Do you have any
suggestions?

Signature

Thanks in advance
/Enrico

jaybinod@gmail.com - 29 May 2006 14:05 GMT
Hi,

Whatever windows size u want specify in paint event of Form.
Linda Liu [MSFT] - 30 May 2006 07:46 GMT
Hi Enrico,

Thank you for posting.

I think in order to make a form has the same window status or position of
another form, we should save this information such as size or location to a
"public" variable to which all the forms in your application could access.
Since the forms in your application are all derived from a base form class,
we could add some static variable to the base form class. Then we could add
a VisibleChanged, SizeChanged and LocationChanged event handlers in the
base form class to get and set the static variable.

The following is a sample.
public partial class BaseForm : Form
   {
       // static variable
       private static Point formlocation = new Point(0,0);
       private static Size formsize = new Size(300,300);
       private static FormWindowState formwindowstate =
FormWindowState.Normal;
   
       public BaseForm()
       {
           InitializeComponent();
           this.VisibleChanged += new EventHandler(Form2_VisibleChanged);
           this.SizeChanged += new EventHandler(Form2_SizeChanged);      
            this.LocationChanged += new
EventHandler(Form2_LocationChanged);    
       }

       void Form2_VisibleChanged(object sender, EventArgs e)
       {
           this.WindowState = formwindowstate;
           this.Size = formsize;
           this.Location = formlocation;
       }
       void Form2_LocationChanged(object sender, EventArgs e)
       {
           formlocation = this.Location;
       }
       void Form2_SizeChanged(object sender, EventArgs e)
       {
           formwindowstate = this.WindowState;
           formsize = this.Size;
       }      
     
   }

Hope this is helpful to you.
If you have other conerns or need anything else, please don't hesitate to
let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
Enrico Campidoglio - 30 May 2006 10:11 GMT
Hi Linda,

Your solution solved the problem, thanks a lot!

P.S I noticed that under some circumstances the current form position or
size are not correctly updated in the common state stored in the base class.
I am trying to isolate the problem but it looks some like some
synchronization issue. The event handlers for 'PositionChanged' and
'SizeChanged' are somewhat delayed which sometimes causes forms to receive
outdated values when becoming visible.

Signature

/Enrico

> Hi Enrico,
>
[quoted text clipped - 57 lines]
> from your issue.
> ====================================================
Linda Liu [MSFT] - 30 May 2006 11:41 GMT
Hi Enrico,

Thank you for your quick response.

If these forms are displayed as MDI child forms in your program, the
position or windows status of these MDI child forms may be incorrect. This
problem is related to the MDI parent form which may change the behavior of
its MDI child forms.

Hope this helps.

Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.