Solved

Form Top-Most proberty Problem

Posted on 2004-09-29
11
542 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 86

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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

734 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