?
Solved

How to make a form Model?

Posted on 2010-01-10
21
Medium Priority
?
238 Views
Last Modified: 2013-11-26
Hi Experts,

Is there any way to make a form model in VB.NET?

thanks,
0
Comment
Question by:concern_support
[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
  • 10
  • 5
  • 4
  • +1
21 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 26280893
Set the form's TopMost property to True.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 26280901
Actually, that is incorrect. It's late....  :)

Use the ShowDialog() method to make a form modal.
0
 

Author Comment

by:concern_support
ID: 26280923
but now this property is not working

 frm1.StartPosition = FormStartPosition.CenterScreen
frm1.ShowDialog()
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:concern_support
ID: 26280932
and also i want the Dialog to be a child of main form.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 26280974
Well for the child relationship, do a

    frm1.ShowDialog(Me)

assuming you have declared frm1 to be a member of the parent form.

CenterScreen worked fine for me.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 26280980
The code as I have it:
Public Class Form1
    Private frm1 As Form2

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.frm1 = New Form2()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.frm1.StartPosition = FormStartPosition.CenterScreen
        Me.frm1.ShowDialog(Me)
    End Sub
End Class

Open in new window

0
 

Author Comment

by:concern_support
ID: 26281000
What i am doing is that. I have one MDI and another form Frm1(Which is the child of MDI) and i am showing the third form frm2 from frm1.

And i want the frm2 to show on the middle of my frm1 as Model. it is working fine with simple show method.
0
 

Author Comment

by:concern_support
ID: 26281064
for me the upper coding is working fine, but dosent show the dialog on the center of the screen.
0
 

Author Comment

by:concern_support
ID: 26281083
Actually my form1 is the child of MDI and and its start position is set to Center Screen, now the second form which is form2 and i want to show it as model and on the center of the form2, but it is not showing. also i tried the    
frm2.StartPosition = FormStartPosition.CenterParent. it is in the center of the screen, but not on center of the parent which i want.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 26283600
ShowDialog() doesn't work well with MDI apps...I think it'll end up being modal to the entire MdiParent.

One alternative is to disable the MdiChild and then re-enable it when the "modal" form closes.  This will make it modal to just that MdiChild form:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Enabled = False

        Dim f2 As New Form2
        AddHandler f2.FormClosed, AddressOf f2_FormClosed
        f2.StartPosition = FormStartPosition.CenterParent
        f2.Show(Me)
    End Sub

    Private Sub f2_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs)
        Me.Enabled = True
    End Sub

End Class

Open in new window

0
 
LVL 4

Expert Comment

by:barrislb
ID: 26287864
Hi concern_support,

As Idle_Mind said: "ShowDialog() doesn't work well with MDI apps"  I believe to be true. Here's another alternative to assist with the other experts. Make sure you set the 'StartPosition' in your form's properties to 'CenterScreen'.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '-- Create a new instance of the child form. '
        Dim ChildForm As New Form2
        '-- Make it a child of this MDI form before showing it. '
        ChildForm.MdiParent = Me  '<--  Your Main MDI '
        ChildForm.Show()
End Sub

Open in new window

0
 

Author Comment

by:concern_support
ID: 26290121
thanks, but these are not the solutions.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 26290125
These are not the droids you are looking for...

Could ya be a little more specific?   =\
0
 

Author Comment

by:concern_support
ID: 26290375
Find the detail in the attached image.
untitled.bmp
0
 
LVL 4

Expert Comment

by:barrislb
ID: 26290528
concern_support,

Check out link below. It may, or may not help your need.

http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/2dd87d8b-5def-41aa-8d2f-8a4e2aa21a60
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 26290585
Ok...try:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim rc As Rectangle = Me.MdiParent.RectangleToScreen(Me.Bounds)
        Dim f2 As New Form2
        f2.StartPosition = FormStartPosition.Manual
        f2.Location = New Point(rc.X + rc.Width / 2 - f2.Width / 2, rc.Y + rc.Height / 2 - f2.Height / 2)
        f2.ShowDialog()
    End Sub

End Class

Open in new window

0
 

Author Comment

by:concern_support
ID: 26290639
thanks idle_mind, it is now more dislocated
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 26292440
....


Does that mean it worked?
0
 

Author Comment

by:concern_support
ID: 26300156
No
It is now to the right of the screen not on the center of form2.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 26300163
Please upload your project to EE-Stuff so we can see where the problem is...   =\
http://www.ee-stuff.com/accessLogin.php
0
 

Author Closing Comment

by:concern_support
ID: 31675361
They can't solve my problem even it took two days.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

771 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