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
Solved! Go to Solution.
Solved by khoa.ho. Go to Solution.
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
Thanks for the help. I used the visible change event as you suggested and it now works.
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
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