Solved

Form Top-Most proberty Problem

Posted on 2004-09-29
11
512 Views
Last Modified: 2009-05-08
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
Comment
Question by:janartgroup
  • 4
  • 2
  • 2
  • +2
11 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12180622
What are you trying to accomplish?  What problems are you having with the parent TopMost = True?

Bob
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12181184
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
 
LVL 8

Assisted Solution

by:wguerram
wguerram earned 50 total points
ID: 12181906
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
 
LVL 4

Assisted Solution

by:eozz_2000
eozz_2000 earned 100 total points
ID: 12186835
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
 

Author Comment

by:janartgroup
ID: 12188357
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 100 total points
ID: 12189735
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
 
LVL 8

Expert Comment

by:wguerram
ID: 12190446
Can you post the code you are using to show FormA, the switch board
0
 
LVL 4

Expert Comment

by:eozz_2000
ID: 12191169
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
 

Author Comment

by:janartgroup
ID: 12199874
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
 

Author Comment

by:janartgroup
ID: 12205893
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
 

Author Comment

by:janartgroup
ID: 12206461
addional info

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
.net VBA word safemode 1 38
Create XML 5 46
Passing a form as a parameter to an external class 1 27
Help with AsEnumerable(), LINQ 4 22
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

22 Experts available now in Live!

Get 1:1 Help Now