
上面是我單步除錯的顯示,但是在我沒有斷點除錯的情況下,在出影像的時候就會閃爍一下,然后消失,不知道是為什么,調了好久了,有沒有大神來解答
uj5u.com熱心網友回復:
using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using drew;
using System.Runtime.InteropServices;
using System.IO;
using System.Threading;
using System.Diagnostics;
namespace 表單應用程式
{
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 = 0x00C00000;
const int WS_THICKFRAME = 0x00040000;
const int WS_SYSMENU = 0X00080000;
[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 rect, bool bErase);
/// <summary>最大化視窗,最小化視窗,正常大小視窗
/// nCmdShow:0隱藏,3最大化,6最小化,5正常顯示
/// </summary>
[DllImport("user32.dll", EntryPoint = "ShowWindow")]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
#endregion
public delegate void UpdateUI();//委托用于更新UI
Thread startload;//執行緒用于matlab表單處理
IntPtr figure1;//影像句柄
public Form1()
{
InitializeComponent();
}
private void button4_Click(object sender, EventArgs e)
{
string text = textBox1.Text;
if(text == "")
{
return;
}
Process.Start("iexplore", text);
}
private void button1_Click(object sender, EventArgs e)
{
//通過一個行程打開指定的檔案
ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(@"D:\專案\刮板修復\Recesurface and save point\Recesurface and save point\bin\Debug\Recesurface and save point.exe");
//創建行程物件
Process p = new Process();
p.StartInfo = psi;
p.Start();
//Console.ReadKey();
}
private void button5_Click(object sender, EventArgs e)
{
Class1 te = new Class1();
//te.drew();
//多執行緒處理程式
Thread th = new Thread(te.drew);
th.IsBackground = true;
th.Start();
figure1 = IntPtr.Zero;
//實體化執行緒,用來初次呼叫matlab,并把影像表單放到winform
startload = new Thread(startload_run);
//開始執行緒
startload.Start();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = "192.168.1.10";
Control.CheckForIllegalCrossThreadCalls = false;
this.DoubleBuffered = true;//設定本表單
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
SetStyle(ControlStyles.DoubleBuffer, true); // 雙緩沖
}
void startload_run()
{
//回圈查找figure1表單
while (figure1 == IntPtr.Zero)
{
//查找matlab的Figure 1表單
figure1 = FindWindow("SunAwtFrame", "Figure 1");
}
//跨執行緒,用委托方式執行
UpdateUI update = delegate
{
//設定matlab影像表單的父表單為panel
SetParent(figure1,panel1.Handle);
//獲取表單原來的風格
var style = GetWindowLong(figure1, GWL_STYLE);
//設定新風格,去掉標題,不能通過邊框改變尺寸
SetWindowLong(figure1, GWL_STYLE, style & ~WS_CAPTION & ~WS_THICKFRAME);
//移動到panel里合適的位置并重繪
MoveWindow(figure1, 0, 0, 400 + 0, 300 + 0, true);
};
panel1.Invoke(update);
//再移動一次,防止顯示錯誤
//Thread.Sleep(100);
//MoveWindow(figure1, 0, 0, panel1.Width + 20, panel1.Height + 40, true);
}
}
}
上面是我所有的原始碼,有沒有人幫我看一下
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/131107.html
標籤:C#
下一篇:求教一下
