dastaub
asked on
Visual Studio 2008
I would liike a form to always be on top. In VB 6.0 that was accomplished by using modal.
I am told to use Showdialog in .Net When I use ShowDialog, as soon as any command button is pressed on the form it closes. It does nevertheless stay on top with showDialog until closing.
Also If I use TopMost = true, the form remains on top, but the user can still select a command button on the form underneath the top most form. I would like to accomplish the form always being on top and the command buttons on the form below the top most to be visible but unresponsive by the end user. This was done by opening a form in modal in VB 6.0 How can this be accomplished in Visual Studio 2008?
I am told to use Showdialog in .Net When I use ShowDialog, as soon as any command button is pressed on the form it closes. It does nevertheless stay on top with showDialog until closing.
Also If I use TopMost = true, the form remains on top, but the user can still select a command button on the form underneath the top most form. I would like to accomplish the form always being on top and the command buttons on the form below the top most to be visible but unresponsive by the end user. This was done by opening a form in modal in VB 6.0 How can this be accomplished in Visual Studio 2008?
In your Form1 set a button for testing purposes...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim obj As New Form2
obj.ShowDialog()
End Sub
in form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TopMost = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim obj As New Form2
obj.ShowDialog()
End Sub
in form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TopMost = True
End Sub
Or if you mean that the form should be on the top of your screen...set:
Me.StartPosition = FormStartPosition.Manual
Me.Location = New Point(0, 0)
Me.StartPosition = FormStartPosition.Manual
Me.Location = New Point(0, 0)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i did not want to question to be closed.
ASKER
you caught the core issue.
Something is not right there...
Is there a property of a command button that can cause the form to close? the original command buttons were copy and pasted from another form. When I deleted and started from fresh regarding the command buttons, the error was then resolved.
Something is not right there...
Is there a property of a command button that can cause the form to close? the original command buttons were copy and pasted from another form. When I deleted and started from fresh regarding the command buttons, the error was then resolved.
Yes...when you select the FORM itself, there is an AcceptButton() and a CancelButton() property that can be set to buttons on your form. When buttons are set as these properties, clicking them will the cause the DialogResult() property of the Form to be set to "Ok" or "Cancel" respectively. When DialogResult() is set on a form it immediately HIDES and execution returns to the ShowDialog() call that opened it in the first place.
Set Topmost=True on the child form, and use FormName.ShowDialog() to open the form from the parent. The result is a modal window and you can see but not interact with the parent form.
Hope this helps.