Solved

Visual Studio 2008

Posted on 2010-09-20
7
582 Views
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?
0
Comment
Question by:dastaub
  • 2
  • 2
  • 2
  • +1
7 Comments
 

Expert Comment

by:frostfire01
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.
0
 
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
        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
 
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)
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 85

Accepted Solution

by:
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?
0
 

Author Comment

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

Author Closing Comment

by:dastaub
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.
0
 
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.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

786 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