• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 562
  • Last Modified:

Form Top-Most proberty Problem

i have a MDI-Form with property top-most=true
the problem when i open a child form and the focus entered to an object inside the child form specially datagrid object , the MDI_Form can't be always on top .
so what can i do ?
0
janartgroup
Asked:
janartgroup
  • 4
  • 2
  • 2
  • +2
3 Solutions
 
Bob LearnedCommented:
What are you trying to accomplish?  What problems are you having with the parent TopMost = True?

Bob
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
An MDI Child is contained completely within an MDI Parent.  Therefore you can't have the MDI Parent "above" the MDI Child with the TopMost property.  Setting the TopMost property on your MDI Parent will make it float above other applications.

~IM
0
 
wguerramCommented:
Are you setting the child form property MdiParent?

like

dim f as new form1
f.MdiParent = me

f.show

MDI Form is a container of forms and can't be on top of its own childs unless you don't set the mdiparent. you can do that only if you and SDI environment where every form is opened standalone. just like notepad.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
eozz_2000Commented:
Well... if you want to lost the top most when you open your child form and recover after closing the child:

you can set the topMost property of your first form to false before calling the child form, show the child form with ChildForm.ShowDialog(Me) and immediatly after this line set the topMos property of your parent form to True.

Or, in the code of you child form you can do this:

    Public Overloads Sub show(ByRef parentForm As Form)
        parentForm.TopMost = False
        Me.ShowDialog(parentForm)
        parentForm.TopMost = True
    End Sub

and in the parent form call frmChild.Show(Me)

Is practically the same thing, the second code give you the chance to access all the properties of the parent form... if you want.
0
 
janartgroupAuthor Commented:
Thanks For All Experts Care To Help Me in this problem

But till now i can't solve it .... so i will describe excatly what happned with me ..

well i develop in ERP Application so i have a lot of MDI Childs , so i can't use SDI Forms

i need my application to be Aloways on top of other windows opened in the operating system,not be alowys top on my MDI Child ..

ex: i have MDI Form , and Form A as switch board , and Form B ...

so i write the following code to open the Form B From Form A(switch board )
========================
dim vForm As New FormB
vForm.MdiParent = Me.ParentForm
vForm.Show
========================
This Code open the form B as MDI child to MDI Form

Till now no problem

The Problem Happned when I Clicked a button or foucsing any object inside the the Form B The MDI Parent LOST THE TOP-MOST PROPERTY ...

Just i need to avoid this problem , to let my application always on top

Thanks a lot
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Hi janartgroup,

I can't reproduce the problem.  I created a new project and added two forms: Form1 is the MDI Parent and Form2/Form3 are the two MDI Children.

On Form1, I set the IsMDIContainer and TopMost properties to True and had the following code to open Form2:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim f2 As New Form2
        f2.MdiParent = Me
        f2.Show()
    End Sub

On Form2, I had the following code to open Form3:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim f3 As New Form3
        f3.MdiParent = Me.MdiParent
        f3.Show()
    End Sub

On Form3, I added a couple buttons and textboxes so something could have the focus on it.  The TopMost property was never lost on my MDI Parent form.

~IM
0
 
wguerramCommented:
Can you post the code you are using to show FormA, the switch board
0
 
eozz_2000Commented:
Create a Module where with a function that receives the principal form ByRef, and then, when you click a child,  modify the TopMost property of the form that you have in your module, in the Closing event of your child, return the TopMost property to True.
0
 
janartgroupAuthor Commented:
Finally i Got where is the problem

just i make a new project with MDI Parent and MDI Child

the child form has an datagrid , when i open the child form the Top Most of MDI Parent Lost...

so i confirmed it when i set the datagrid visible to false and appned a button to re-set the datagrid visible to true , when i clicked this button the top-most of MDI Parent lost

so i think the problem in datagrid , and it mostly used in my application forms

thanks

Jean
0
 
janartgroupAuthor Commented:
Hello All Experts,

Congratulation ,,,,
I Come back This time with the solution....

This problem is caused by a bug with the DataGrid control.  When the handle of the DataGrid is created, it also creats its ToolTip which underneath calls SetWindowPos (Win API) and it breaks the zorder of the windows.  The workaround is to set form's TopMost property after the handle of the DataGrid is created.  
To create the handle of the DataGrid, you can explicitly request it and then ignore it.  Example,
the following code snippet will fix the problem:

Public Sub New()
        MyBase.New()
        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

        Dim trash As IntPtr
        trash = DataGrid1.Handle
        Me.TopMost = True
End Sub

So now , i will split the Point for who care to solve my problem
Thanks
Yours Jean
0
 
janartgroupAuthor Commented:
addional info

the best place to put this code ,in  the event Datarid.Paint
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now