.NET

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

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

269 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

Distinguished Contributor
khoa.ho
Posts: 149
Registered: ‎09-15-2011
Message 2 of 4 (258 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 (217 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

Distinguished Contributor
khoa.ho
Posts: 149
Registered: ‎09-15-2011
Message 4 of 4 (209 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community