0

I'm wanting to use visual studio to create a form with buttons, but then have it coded elsewhere, so that I can use the events (ie; button clicks) to perform specific actions in this application.

Is it possible/practical to do this? If not/if so, what do I need to look up and learn about from here to be able to implement it? My knowledge base in programming is limitted; I've just been starting to get familiar with Classes.

(I'm working in Autodesk Inventor, and am trying to create a prompt window with buttons to control the output of another program I have. In order to save on the amount of calls/interfacing, I was hoping to just create an uncoded button form, but code it within my program/macro I have within Inventor - its to be a form with six buttons that end up rotating some graphics within the program at a certain stop point, and then the program resumes when the form is closed via the "x")

I have seen posts such as the one below, but that doesn't seem to have the capability to receive user input: How to create a custom MessageBox?

Currently I am here, which works for showing the toolbox. Can someone show me how I would handle the events please?

AddReference "C:\Users\Documents\Visual Studio 2013\Projects\WindowsApplication1\WindowsApplication1\bin\Release\SectionSymToolBox.dll" 

Imports System.Windows.Forms

Public Class SectionSymRule
'Public dlg As New System.Windows.Forms.For
Public Shared ToolBox As New SectionSymToolBox.SectionSymToolBox

Dim WithEvents EClass As New EventClass

Sub Main()
    ToolBox.Show()
End Sub

End Class

Public Class SectionSymToolBox

Private Sub Main()

End Sub

Public Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    'Swap Symbols

End Sub

Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    'Flip Symbol

End Sub

Public Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    'Flip Text

End Sub

Public Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    '<

End Sub

Public Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
    '>
End Sub

End Class
Community
  • 1
  • 1
  • Are you saying you have a VBA macro in Autodesk Inventor and you want it to get input from a VB.Net form? – Blackwood Feb 02 '16 at 14:20
  • The macro is coded in partial vb.net in the internal inventor API environment. (it goes as high as declaring classes and imports/references) – MechMachineMan Feb 02 '16 at 14:35
  • 1
    I don't know what "partial VB.Net" means, I thought Autodesk used Visual Basic for Applications (VBA) for macros. VB.Net is not the same as VBA. – Blackwood Feb 02 '16 at 14:39
  • Macros are in VBA in inventor, but their "simplified programming language" - iLogic - is based in vb.net, and thus the "Rule" environment within Inventor operates using vb.net. It has a lot of the overhead work done due to this; ie some imports are already called, references only need to be called for things they didnt think people would use in it (such as XML or LINQ). It makes it so that a line as simple as MsgBox(ThisDoc.ModelDocument.FullFileName) would produce results without any additional overhead work. – MechMachineMan Feb 02 '16 at 15:41

1 Answers1

0

You can always use Partial Class to split your code into multiple files.

So you create your Form (say Form1) the normal way. Then put the code in another class file with class declared as Partial

For example,

Partial Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox(TextBox1.Text)
    End Sub
End Class

The other way is to inherit your Form. The inherited form will then have everything of whatever is on the form, with whatever you want to add.

Public Class Form1Code
    Inherits Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox(TextBox1.Text)
    End Sub
End Class
Pradeep Kumar
  • 6,836
  • 4
  • 21
  • 47
  • Is this one of the actual good uses for a partial class? A quick search suggested I avoid partial classes like they are the plague. Is there any other way to accomplish this aside from having it all in one project? – MechMachineMan Feb 02 '16 at 14:20
  • The other way is to inherit your Form. The inherited form will then have everything of whatever is on the form, with whatever you want to add. – Pradeep Kumar Feb 02 '16 at 14:29
  • And the inheriting will still allow access to listen to the events of the form? – MechMachineMan Feb 02 '16 at 14:30
  • Just updated my answer with an example of inherited form. – Pradeep Kumar Feb 02 '16 at 14:32
  • 1
    Thanks for the responses Pradeep! Found some good information here to read on: https://msdn.microsoft.com/en-us/library/hy3sefw3.aspx – MechMachineMan Feb 02 '16 at 14:33