First, use the Deploytool tool or the command line to compile the matlab m file into a class, resulting in a dynamic link library. dll file and classes of some C # code.
The second step is to import the DLL files and use some of the WIN32API functions, because this m file produces a figure window, which embeds the figure window into the VB program form.
Code:
Imports System
Imports System.Runtime.InteropServices
Imports MathWorks.MATLAB.NET.Arrays
Imports MathWorks.MATLAB.NET.Utility
Imports Sinimage.sinimage
Public Class Sinform
Dim img as New sinimage.sinimage
Dim Figurehwnd as IntPtr = IntPtr.Zero
Public Declare Function SetParent Lib "user32" Alias "SetParent" _
(ByVal hwndchild as INTPTR, ByVal hwndnewparent as INTPTR) As Integer
Public Declare Function FindWindow Lib "user32" Alias "Findwindowa" _
(ByVal lpclassname As String, ByVal Lpwindowname as String) As IntPtr
Public Declare Function GetWindowLong Lib "User32.Dll" Alias "Getwindowlonga" _
(ByVal hWnd as System.IntPtr, ByVal NIndex as Integer) As Integer
Public Declare Function SetWindowLong Lib "User32.Dll" Alias "Setwindowlonga" _
(ByVal hWnd as INTPTR, ByVal nIndex As Integer, ByVal dwnewlong As Integer) As Integer
Public Declare Function MoveWindow Lib "user32" Alias "MoveWindow" _
(ByVal hwnd as INTPTR, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal Flags as Bo Olean) as Boolean
Private Sub number_nud_valuechanged (ByVal sender as Object, ByVal e as System.EventArgs) Handles Number_nud. Click
IMG.SX (Number_nud. Value)
Move_window ()
End Sub
Private Sub sinform_load (ByVal sender as Object, ByVal e as System.EventArgs) Handles me.load
&nb sp; img.sx (Number_nud. Value)
Threading.Thread.Sleep (+)
Do While figurehwnd = IntPtr.Zero
Figurehwnd = FindWindow (Nothing, "Figure 1")
Threading.Thread.Sleep (+)
Loop
SetWindowLong (Figurehwnd, -16, GetWindowLong (Figurehwnd, -16) and (not &hc00000))
SetParent (Figurehwnd, ME.IMAGE_GBX. Handle)
Move_window ()
End Sub
Private Sub Move_window () Handles me.resize
MoveWindow (Figurehwnd, -3, -20, ME.IMAGE_GBX. Width + 8, ME.IMAGE_GBX. Height + si, True)
Me.refresh ()
End Sub
End Class
In fact, the C # code of the M file can be compiled directly into a. netmodule file using Csc.exe, and the. vb file that applies the functions contained in this m file is also compiled into an EXE file using vbc.exe. In this case, the csc.exe compiled. netmodule file is referenced to the vbc.exe compilation.
If the M file does not produce a figure window, the program is simpler, import the. dll file directly, and use the functions in it.
Mixed programming of vb.net and MATLAB