I have a block styler application and would like to call a windows form that I have created within the block styler application. The new form is called Form1.vb and I have not been able to figure out how to call it from code. I have been able to display a form created programatically but not the one contained within the application.
I have tried the following code but get the error "Type 'Form1' is not defined.
Dim myForm as New Form1
Solved! Go to Solution.
Assuming you have created the Form within the project, this should work:
Public Function update_cb(ByVal block As NXOpen.BlockStyler.UIBlock) As Integer
If block Is button0 Then
Dim myForm As Form1 = New Form1
Catch ex As Exception
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
update_cb = 0
Note that I used an Action Button to launch it. If it would help I can zip up my project and dialog and post it - just let me know.
Steve, Yes, Form1 was created within my project and I have inserted the code you suggested in the OK action button function. However when I run the code I still get the error that Type 'Form1 is not defined'. I have imported System.Windows.Forms thinking it was needed but still get the error. If you could post your zipped project for me to look at that may help or any other suggestions would be appreciated.
Public Function ok_cb() As Integer Dim errorCode As Integer = 0 Try Dim myForm As Form1 = New Form1 myForm.ShowDialog() Catch ex As Exception '---- Enter your exception handling code here ----- errorCode = 1 theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString) End Try ok_cb = errorCode End Function
Hmmm, as you can imagine, it is hard for me to guess what might be going wrong if you are using my project, because it worked perfectly here.
So...did you use my entire project, or did you just paste my code into your old project?
I created the dialog in NX9 and saved it, then I created an NXOpen VB.Net project in the Visual Studio, and overwrote the template code with the code that Block Styler wrote.
Then I selected Project -> Add Windows Form and made the form, added a button and one line of code to close the form when the button was pressed. Then I added the code I sent earlier to the update callback.
Oddly enough I did not have to add an Imports statement or a Reference to the Windows Forms library.
Steve, I used your entire project. I unzipped it and ran it as a journal application from within NX using Module1.vb as the source.
When you run the .VB file using Tools -> Journal -> Play, one of the restrictions is that all of your source code has to be in one .VB file.
So in the project, the form code is created as a separate .VB file, and that file will not be triggered running in the Journal editor. It is possible, but a little bit of trouble, to take your Form code and put it inside the same source file so you can run as a journal. I'll see what I can do as time permits...but at least we have a logical explanation for the behavior that you are seeing.
Yes, absolutely! That is what I did.
Sometimes people need to run the .VB because they do not have the dotnet_author license, but as long as you have the license, that is the simplest solution.