.NET

.NET

Reply
Distinguished Contributor
fxcastil
Posts: 404
Registered: ‎11-11-2002
Message 1 of 4 (317 Views)
Accepted Solution

Showing a (2nd) modeless from from a (1st) modal from.

317 Views, 3 Replies
08-07-2012 02:59 PM

I am having problems showing a modeless form when it is called from another form. (the main start form)

 

I can show the main start from as modeless without a problem.  

 

Again the problem is trying to hide a modal from and then show a modeless from.

 

I have tried disposing of the first (main start) form but still no sucess.

 


********************** MAIN START CLASS **************************

Public Class ClassMainStart


    <CommandMethod("BT")> Public Sub BodeTools()


        Dim form_Main As System.Windows.Forms.Form = New MainForm
     
        Application.ShowModalDialog(form_Main)
      


 End Sub

***********************    A button click the main  start from *******************

Public Class MainForm


    Private Sub OneButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTextFill.Click


        Dim form_Main As System.Windows.Forms.Form = New MainForm

        Dim form_Second As System.Windows.Forms.Form = New formOther


        form_Main.Hide()
       
        Application.ShowModelessDialog(form_Second)


    End Sub

This is a very interesting topic. When we hide a modal form, it will hide other opened modeless forms, even we show them later. The following code will use an event on the visibility of the main form on close (not hide the control that will not work), it will open another modeless form. So one form is off then another form will be on.

Public Class MainForm
    Private Sub OneButton_Click(sender As Object, e As EventArgs)
        Me.VisibleChanged += OnVisibleChanged
        Me.FindForm().Close()
    End Sub

    Private Sub OnVisibleChanged(sender As Object, eventArgs As EventArgs)
        Autodesk.AutoCAD.ApplicationServices.Application.ShowModelessDialog(New FormOther())
    End Sub
End Class

-Khoa

Mentor
khoa.ho
Posts: 224
Registered: ‎09-15-2011
Message 2 of 4 (306 Views)

Re: Showing a (2nd) modeless from from a (1st) modal from.

08-07-2012 04:43 PM in reply to: fxcastil

This is a very interesting topic. When we hide a modal form, it will hide other opened modeless forms, even we show them later. The following code will use an event on the visibility of the main form on close (not hide the control that will not work), it will open another modeless form. So one form is off then another form will be on.

Public Class MainForm
    Private Sub OneButton_Click(sender As Object, e As EventArgs)
        Me.VisibleChanged += OnVisibleChanged
        Me.FindForm().Close()
    End Sub

    Private Sub OnVisibleChanged(sender As Object, eventArgs As EventArgs)
        Autodesk.AutoCAD.ApplicationServices.Application.ShowModelessDialog(New FormOther())
    End Sub
End Class

-Khoa

Distinguished Contributor
fxcastil
Posts: 404
Registered: ‎11-11-2002
Message 3 of 4 (265 Views)

Re: Showing a (2nd) modeless from from a (1st) modal from.

08-08-2012 11:03 AM in reply to: khoa.ho

Thanks for the help. I used the visible change event as you suggested and it now works. :smileyhappy:

Where did you find out about this solution?

I am looking for books and other learing material.

 

I'm not sure what you meant by "Me.VisibleChanged += OnVisibleChanged"

 

 

 

****************************************************

 

 

Imports Autodesk.AutoCAD.ApplicationServices

 

Public ClassFormBonusToolsDim bolBtnTextFill AsBoolean

 

PrivateSub btnTextFill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesbtnTextFill.Click

 

' use this flag to know which of the buttons on the Main UserForm was pressed

bolBtnTextFill = True' close this form and open the UserForm described by button Me.FindForm.Close()

 

EndSub

 

PrivateSub FormBonusTools_VisibleChanged(ByVal sender AsObject, ByVal e As system.EventArgs) HandlesMe.VisibleChanged

 

Dim form_textFill As System.Windows.Forms.Form = NewformTextSeries

Dim form_Main As System.Windows.Forms.Form = NewFormBonusTools'

 

'  Showing the UserForm using AutoCAD method , use the AutoCAD method if you want to show a modeless UserForm.

 

If form_Main.Visible = FalseAnd bolBtnTextFill = true ThenApplication.ShowModelessDialog(form_textFill)

bolBtnTextFill =False

EndIf

 

EndSub

Mentor
khoa.ho
Posts: 224
Registered: ‎09-15-2011
Message 4 of 4 (257 Views)

Re: Showing a (2nd) modeless from from a (1st) modal from.

08-08-2012 11:57 AM in reply to: fxcastil

I am glad that it works for you! I found the solution by guessing what wrong when we hide only a form that will hide everything regardless their open states. Then I think an event should be independent with this hiding process. This outside event is triggered after the form is closed/invisible so it will not relate to .Hide() method that has the issue. I also played a bit with Visual Studio debugging to find the final solution.

 

The original code was on C# that I converted to VB.NET. So the code "this.VisibleChanged += OnVisibleChanged" attaches the visible event to the main form. It is similar to your VB.NET method "Private Sub FormBonusTools_VisibleChanged(ByVal sender AsObject, ByVal e As system.EventArgs) Handles Me.VisibleChanged".

 

-Khoa

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.