Visual Studio 2008

Posted on 2010-09-20
Last Modified: 2012-05-10
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?
Question by:dastaub
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
  • 2
  • 2
  • 2
  • +1

Expert Comment

ID: 33722784
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.
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33722887
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
    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
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33722917
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)
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

LVL 85

Accepted Solution

Mike Tomlinson earned 500 total points
ID: 33725200
"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?

Author Comment

ID: 33731446
i did not want to question to be closed.

Author Closing Comment

ID: 33731451
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.
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 33731466
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.

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

762 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