• 大小: 442KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-18
  • 语言: C#
  • 标签:

资源简介

C#调用matlab画图,将图像嵌入Winform窗体,并解决首次画图慢的问题 预览和介绍请看:http://blog.csdn.net/yxy244/article/details/79305757

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MyMatlabFunctionDemo;
using MathWorks.MATLAB.NET.Arrays;
using System.Threading;
using System.Runtime.InteropServices;

namespace WindowsFormsApp1
{
    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);

        /// 最大化窗口,最小化窗口,正常大小窗口
        /// nCmdShow:0隐藏3最大化6最小化,5正常显示
        /// 

        //[DllImport(“user32.dll“ EntryPoint = “ShowWindow“)]
        //public static extern int ShowWindow(IntPtr hwnd int nCmdShow);
        #endregion

        public Form1()
        {
            InitializeComponent();
        }

        public delegate void UpdateUI();//委托用于更新UI
        Thread startload;//线程用于matlab窗体处理
        MatlabFunction matlabFunction;//matlab编译的类
        IntPtr figure1;//图像句柄
        private void Form1_Load(object sender EventArgs e)
        {
            //实例化线程,用来初次调用matlab,并把图像窗体放到winform
            startload = new Thread(new ThreadStart(startload_run));
            //运行线程方法
            startload.Start();
        }


        void startload_run()
        {
            int count50ms = 0;
            //实例化matlab对象
            matlabFunction = new MatlabFunction();
            //调用方法画高斯分布函数图
            matlabFunction.mysurf();//高斯分布函数

            //循环查找figure1窗体
            while (figure1 == IntPtr.Zero)
            {
                //查找matlab的Figure 1窗体
                figure1 = FindWindow(“SunAwtframe“ “Figure 1“);  
                //延时50ms
                Thread.Sleep(50);
                count50ms++;
                //20s超时设置
                if (count50ms >= 400)
                {
                    label1.Text = “matlab资源加载时间过长!“;
                    return;
                }
            }

            //跨线程,用委托方式执行
            UpdateUI update = delegate
            {
                //隐藏标签
                label1.Visible = false;
                //设置matlab图像窗体的父窗体为panel
                SetParent(figure1 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-02-11 14:55  C#&matalbDemo\
     目录           0  2018-02-09 16:34  C#&matalbDemo\.vs\
     目录           0  2018-02-09 16:34  C#&matalbDemo\.vs\WindowsFormsApp1\
     目录           0  2018-02-09 16:34  C#&matalbDemo\.vs\WindowsFormsApp1\v15\
     文件       48640  2018-02-11 15:33  C#&matalbDemo\.vs\WindowsFormsApp1\v15\.suo
     目录           0  2018-02-09 16:34  C#&matalbDemo\.vs\WindowsFormsApp1\v15\Server\
     目录           0  2018-02-11 15:33  C#&matalbDemo\.vs\WindowsFormsApp1\v15\Server\sqlite3\
     文件           0  2018-02-09 16:34  C#&matalbDemo\.vs\WindowsFormsApp1\v15\Server\sqlite3\db.lock
     文件      577536  2018-02-11 15:33  C#&matalbDemo\.vs\WindowsFormsApp1\v15\Server\sqlite3\storage.ide
     文件         150  2018-02-11 15:33  C#&matalbDemo\Readme.txt
     目录           0  2018-02-11 14:47  C#&matalbDemo\WindowsFormsApp1\
     文件        1147  2018-02-09 16:34  C#&matalbDemo\WindowsFormsApp1.sln
     目录           0  2018-02-10 11:56  C#&matalbDemo\WindowsFormsApp1\bin\
     目录           0  2018-02-10 10:11  C#&matalbDemo\WindowsFormsApp1\bin\Debug\
     文件       98304  2010-08-03 20:14  C#&matalbDemo\WindowsFormsApp1\bin\Debug\MWArray.dll
     文件      247115  2010-08-03 20:14  C#&matalbDemo\WindowsFormsApp1\bin\Debug\MWArray.xml
     文件      106496  2018-02-09 16:26  C#&matalbDemo\WindowsFormsApp1\bin\Debug\MyMatlabFunctionDemo.dll
     文件       13312  2018-02-10 11:56  C#&matalbDemo\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.exe
     文件       24064  2018-02-10 11:56  C#&matalbDemo\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.pdb
     目录           0  2018-02-10 12:01  C#&matalbDemo\WindowsFormsApp1\bin\Release\
     文件      106496  2018-02-09 16:26  C#&matalbDemo\WindowsFormsApp1\bin\Release\MyMatlabFunctionDemo.dll
     文件       13312  2018-02-11 14:47  C#&matalbDemo\WindowsFormsApp1\bin\Release\WindowsFormsApp1.exe
     文件       24064  2018-02-11 14:47  C#&matalbDemo\WindowsFormsApp1\bin\Release\WindowsFormsApp1.pdb
     文件        5567  2018-02-11 14:47  C#&matalbDemo\WindowsFormsApp1\Form1.cs
     文件        9287  2018-02-10 16:28  C#&matalbDemo\WindowsFormsApp1\Form1.Designer.cs
     文件        5817  2018-02-10 16:28  C#&matalbDemo\WindowsFormsApp1\Form1.resx
     目录           0  2018-02-10 11:56  C#&matalbDemo\WindowsFormsApp1\obj\
     目录           0  2018-02-10 11:22  C#&matalbDemo\WindowsFormsApp1\obj\Debug\
     文件        1452  2018-02-09 17:09  C#&matalbDemo\WindowsFormsApp1\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7027  2018-02-10 10:08  C#&matalbDemo\WindowsFormsApp1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2018-02-09 16:33  C#&matalbDemo\WindowsFormsApp1\obj\Debug\TempPE\
............此处省略30个文件信息

评论

共有 条评论