• 大小: 3.23MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-11-15
  • 语言: C#
  • 标签: 窗体嵌入  混合编程  

资源简介

C#调用matlab画图,解决图像嵌入Winform窗体和只能嵌入一次的问题 VS版本是2015注意兼容性问题 博客:https://blog.csdn.net/voidfaceless/article/details/84844713

资源截图

代码片段和文件信息

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 Caldb;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;

namespace WindowsFormsApplication2
{
    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窗体处理
        IntPtr figure1;//图像句柄
        
        private void button1_Click(object sender EventArgs e)
        {


            FileStream fs = new FileStream(“ttt.m“ FileMode.OpenOrCreate FileAccess.ReadWrite); //可以指定盘符,也可以指定任意文件名,还可以为word等文件
            StreamWriter sw = new StreamWriter(fs); // 创建写入流
            sw.WriteLine(Properties.Resources.ttt); // 写入Hello World
            sw.Close(); //关闭文件
            fs = null;

            figure1 = IntPtr.Zero;


            startload = null;

            MLApp.MLApp matlab = null;

            Type matlabAppType = System.Type.GetTypeFromProgID(“Matlab.Application“);
            matlab = System.Activator.CreateInstance(matlabAppType) as MLApp.MLApp;

            string path_project = Directory.GetCurrentDirectory();   //工程文件的路径,如bin下面的debug
            string path_matlab = “cd(‘“ + path_project + “‘)“;     //自定义matlab工作路径    这里我注释调用 
            matlab.Execute(path_matlab);


            matlab.Execute(“clear all“);
            matlab.Execute(“close all“);
            //yle=“color:#ff6666;“>//这条语句也很重要,先注释掉,下面讲解
            string command;
            //command = @“a=minus2(104)“;
            command = @“ttt(104)“;
            matlab.Execute(command);
            //try
            //{
 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     56320  2018-12-06 09:58  WindowsFormsApplication2\.vs\WindowsFormsApplication2\v14\.suo

     文件        136  2018-12-05 22:12  WindowsFormsApplication2\ttt.txt

     文件        161  2018-11-30 18:28  WindowsFormsApplication2\WindowsFormsApplication2\app.config

     文件     345600  2018-11-30 17:59  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\Caldb.dll

     文件     345600  2018-11-30 17:59  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\CaldbNative.dll

     文件     114688  2017-09-15 01:45  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\MWArray.dll

     文件      22688  2018-11-30 17:55  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.vshost.exe

     文件        490  2018-04-12 07:35  WindowsFormsApplication2\WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.vshost.exe.manifest

     文件     345600  2018-11-30 17:59  WindowsFormsApplication2\WindowsFormsApplication2\bin\x64\Debug\Caldb.dll

     文件     345600  2018-11-30 17:59  WindowsFormsApplication2\WindowsFormsApplication2\bin\x64\Debug\CaldbNative.dll

     文件        453  2018-11-28 10:05  WindowsFormsApplication2\WindowsFormsApplication2\bin\x64\Debug\capicity_fade.m

     文件       6211  2018-11-26 14:56  WindowsFormsApplication2\WindowsFormsApplication2\bin\x64\Debug\fade_PF_x_z_as_state.m

     文件         40  2018-11-30 18:43  WindowsFormsApplication2\WindowsFormsApplication2\bin\x64\Debug\minus2.m

     文件     114688  2017-09-15 01:45  WindowsFormsApplication2\WindowsFormsApplication2\bin\x64\Debug\MWArray.dll

     文件     143348  2018-11-26 14:59  WindowsFormsApplication2\WindowsFormsApplication2\bin\x64\Debug\sum.xlsx

     文件     192663  2018-11-26 14:59  WindowsFormsApplication2\WindowsFormsApplication2\bin\x64\Debug\sum_#36.xlsx

     文件      42835  2018-11-26 15:00  WindowsFormsApplication2\WindowsFormsApplication2\bin\x64\Debug\sum_#37.xlsx

     文件      64351  2018-11-26 14:59  WindowsFormsApplication2\WindowsFormsApplication2\bin\x64\Debug\sum_#38.xlsx

     文件      27031  2018-11-30 18:39  WindowsFormsApplication2\WindowsFormsApplication2\bin\x64\Debug\Test1.jpg

     文件      11776  2018-12-06 09:58  WindowsFormsApplication2\WindowsFormsApplication2\bin\x64\Debug\WindowsFormsApplication2.exe

     文件        161  2018-11-30 18:28  WindowsFormsApplication2\WindowsFormsApplication2\bin\x64\Debug\WindowsFormsApplication2.exe.config

     文件      24064  2018-12-06 09:58  WindowsFormsApplication2\WindowsFormsApplication2\bin\x64\Debug\WindowsFormsApplication2.pdb

     文件      22688  2018-12-06 09:58  WindowsFormsApplication2\WindowsFormsApplication2\bin\x64\Debug\WindowsFormsApplication2.vshost.exe

     文件        161  2018-11-30 18:28  WindowsFormsApplication2\WindowsFormsApplication2\bin\x64\Debug\WindowsFormsApplication2.vshost.exe.config

     文件     345600  2018-11-30 17:59  WindowsFormsApplication2\WindowsFormsApplication2\bin\x86\Debug\Caldb.dll

     文件     345600  2018-11-30 17:59  WindowsFormsApplication2\WindowsFormsApplication2\bin\x86\Debug\CaldbNative.dll

     文件     114688  2017-09-15 01:45  WindowsFormsApplication2\WindowsFormsApplication2\bin\x86\Debug\MWArray.dll

     文件       8704  2018-11-30 18:05  WindowsFormsApplication2\WindowsFormsApplication2\bin\x86\Debug\WindowsFormsApplication2.exe

     文件      19968  2018-11-30 18:05  WindowsFormsApplication2\WindowsFormsApplication2\bin\x86\Debug\WindowsFormsApplication2.pdb

     文件      22696  2018-11-30 18:05  WindowsFormsApplication2\WindowsFormsApplication2\bin\x86\Debug\WindowsFormsApplication2.vshost.exe

............此处省略70个文件信息

评论

共有 条评论