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

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?
0
dastaub
Asked:
dastaub
  • 2
  • 2
  • 2
  • +1
1 Solution
 
frostfire01Commented:
You need to do both.

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.
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
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
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
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)
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"When I use ShowDialog, as soon as any command button is pressed on the form it closes."

Something is not right there...

...can you show use the code on your "dialog" form?
0
 
dastaubAuthor Commented:
i did not want to question to be closed.
0
 
dastaubAuthor Commented:
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.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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