Showing posts with label Full Screen in WinForms. Show all posts
Showing posts with label Full Screen in WinForms. Show all posts

Friday, January 11, 2013

Child WinForms in Touch Screen Application in .Net

Task:
I had given a task about showing child windows in Full Screen mode properly
Issue:
What was done before I start to fix this issue. 
An MDI form was created with a menustrip with one menu item in it and setting its 
MdiWindowListItem property
For details: http://msdn.microsoft.com/en-us/library/system.windows.forms.menustrip.mdiwindowlistitem.aspx
Briefly it maintains the childwindows in MDI so it is normally necessary to set in MDI applications.
We had set these properties at MDIWIndow Level:
this.FormBorderStyle = FormBorderStyle.None;
this.ControlBox = false;
this.ShowIcon = false;
this.WindowState = FormWindowState.Maximized;
When we create an instance of  child window we also set these properties of the instance of the form:
ChildForm childwindowfrm = new ChildForm();
childwindowfrm.MdiParent = this;
childwindowfrm.Show();
childwindowfrm.Focus();
We had set these properties at ChildWIndow Level:
this.FormBorderStyle = FormBorderStyle.None;
this.ControlBox = false;
this.ShowIcon = false;
this.WindowState = FormWindowState.Maximized;
After setting all this, we noticed that whenever we open some child there is a flickering and the Title Bar and ControlBox of the child form appear and disappear immediately. Getting Visible and invisible are noticeable on machines like Core 2 Duo with 2 GB RAM, Windows 7. On i3 it can be ignored but if you see then this issue exists on every machine. ControlBox must not appear in any case.
Solution:
ChildForm childwindowfrm = new ChildForm();
// These two bold lines fixed the issue
childwindowfrm.TopLevel= false; 
childwindowfrm.Parent = this;
childwindowfrm.Show();
childwindowfrm.Focus();
Reason:
Menustrip gets the child and make it visible but child sets its properties later. That is why flickering   has not be noticed.