Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

How to make a form Model?

Hi Experts,

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

thanks,
0
concern_support
Asked:
concern_support
  • 10
  • 5
  • 4
  • +1
1 Solution
 
käµfm³d 👽Commented:
Set the form's TopMost property to True.
0
 
käµfm³d 👽Commented:
Actually, that is incorrect. It's late....  :)

Use the ShowDialog() method to make a form modal.
0
 
concern_supportAuthor Commented:
but now this property is not working

 frm1.StartPosition = FormStartPosition.CenterScreen
frm1.ShowDialog()
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
concern_supportAuthor Commented:
and also i want the Dialog to be a child of main form.
0
 
käµfm³d 👽Commented:
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
 
käµfm³d 👽Commented:
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
 
concern_supportAuthor Commented:
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
 
concern_supportAuthor Commented:
for me the upper coding is working fine, but dosent show the dialog on the center of the screen.
0
 
concern_supportAuthor Commented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
barrislbCommented:
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
 
concern_supportAuthor Commented:
thanks, but these are not the solutions.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
These are not the droids you are looking for...

Could ya be a little more specific?   =\
0
 
concern_supportAuthor Commented:
Find the detail in the attached image.
untitled.bmp
0
 
barrislbCommented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
concern_supportAuthor Commented:
thanks idle_mind, it is now more dislocated
0
 
käµfm³d 👽Commented:
....


Does that mean it worked?
0
 
concern_supportAuthor Commented:
No
It is now to the right of the screen not on the center of form2.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Please upload your project to EE-Stuff so we can see where the problem is...   =\
http://www.ee-stuff.com/accessLogin.php
0
 
concern_supportAuthor Commented:
They can't solve my problem even it took two days.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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