Home > Net >  I in c # call matlab, and then the matlab generated figure image embedded in a panel, in the case of
I in c # call matlab, and then the matlab generated figure image embedded in a panel, in the case of

Time:10-10




According to the above is my step through, but in the case, I don't have a breakpoint debugging will flash when the image, and then disappear, don't know is why, up for a long time, have a great god to answer

CodePudding user response:

using System;
Using System. Collections. Generic;
Using System.Com ponentModel;
Using System. The Data;
Using System. Drawing;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;
Using System. Windows. Forms;
Using drew;
using System.Runtime.InteropServices;
using System.IO;
Using System. The Threading;
Using System. Diagnostics;

The namespace forms application
{


Public partial class Form1: Form
{
# region//Windows API
[DllImport (" user32. DLL)]
Public static extern IntPtr FindWindow (string lpClassName, string lpWindowName);
[DllImport (" user32. DLL)]
Public static extern IntPtr SetParent (IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport (" user32. DLL, "CharSet=CharSet. Auto)]
Public static extern int MoveWindow (IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool BRePaint);

Const int GWL_STYLE=- 16;
Const int WS_CAPTION=0 x00c00000;
Const int WS_THICKFRAME=0 x00040000;
Const int WS_SYSMENU=0 x00080000;
[DllImport (" user32 ")]
Private static extern int GetWindowLong (System. IntPtr HWND, int nIndex);

[DllImport (" user32 ")]
Private static extern int SetWindowLong (System. IntPtr HWND, int index, int newLong);
[DllImport (" user32 ")]
Private static extern int InvalidateRect (System. IntPtr HWND, object the rect, bool bErase);
///& lt; summary> Maximize window, minimize window, normal size window
Maximize hidden///nCmdShow: 0, 3, 6, 5 normal display
///& lt;/summary>
[DllImport (" user32. DLL, "EntryPoint=" ShowWindow ")]
Public static extern int ShowWindow (IntPtr HWND, int nCmdShow);
# endregion
Public delegate void UpdateUI ();//used to update the UI
Thread startload;//thread used to deal with the matlab form
IntPtr figure1.//handle to the image
Public _click ()
{
InitializeComponent();
}

Private void button4_Click (object sender, EventArgs e)
{
A string of text=textBox1. Text;
If (text=="")
{
return;
}
Process. The Start (" iexplore ", text);
}

Private void button1_Click (object sender, EventArgs e)
{
//by a process opens a specified file
ProcessStartInfo psi=new System. Diagnostics. ProcessStartInfo (@ "D: \ projects \ scraper repair \ Recesurface and save point \ Recesurface and save point \ bin \ Debug \ Recesurface and save point. Exe");
//create the process object
Process p=new Process();
P. tartInfo=psi.
p.Start();
//the Console. ReadKey ();
}
Private void button5_Click (object sender, EventArgs e)
{
Class1 te=new Class1 ();
//te. Drew ();
//multithreading program
Thread th=new Thread (te) drew);
Th. IsBackground=true;
Th. The Start ();
Figure1=IntPtr. Zero;
//instantiate threads to first call matlab, and forms the image on the winform
Startload=new Thread (startload_run);
//thread
Startload. Start ();
}

Private void Form1_Load (object sender, EventArgs e)
{
TextBox1. Text="192.168.1.10";
Control. CheckForIllegalCrossThreadCalls=false;
Enclosing DoubleBuffered=true;//set the form
SetStyle (ControlStyles. UserPaint, true);
SetStyle (ControlStyles. AllPaintingInWmPaint, true);//erase background is prohibited.
SetStyle (ControlStyles. DoubleBuffer, true);//double buffer

}
Void startload_run ()
{
//loop through figure1 form
While (figure1==IntPtr. Zero)
{
//find the matlab Figure 1 form
Figure1=FindWindow (" SunAwtFrame Figure ", "1");
}
//across threads, entrust executed
UpdateUI update=delegate
{
//sets the parent form at the matlab image form a panel
SetParent (figure1, panel1. Handle);
//to get form the style of the original
Var style=GetWindowLong (figure1, GWL_STYLE);
//set up the new style, get rid of the title, can change through the border size
The SetWindowLong (figure1, GWL_STYLE, style & amp; ~ WS_CAPTION & amp; ~ WS_THICKFRAME);
//move into place equal emphasis on the panel painting
MoveWindow (figure1, 0, 0, 400 + 0, + 0 300, true);
};
Panel1. Invoke (update);
//move again, to prevent error
//Thread. Sleep (100);
//MoveWindow (figure1, 0, 0, panel1. Width + 20, panel1. Height + 40, true);
}
}
}







The above is my all the source code, does anyone help me have a look at
  •  Tags:  
  • C #
  • Related