Trying to create a Math Input Panel in C#

让人想犯罪 __ 提交于 2019-12-21 02:45:25

问题


How do I create a Math Input Panel in C#?

I have tried to put it into a dll and call it but it just closes right away.

#include <stdafx.h>
#include <atlbase.h>
#include "micaut.h"
#include "micaut_i.c"

extern "C" __declspec(dllexport) int run()
{
   CComPtr<IMathInputControl> g_spMIC; // Math Input Control
   HRESULT hr = CoInitialize(NULL);
   hr = g_spMIC.CoCreateInstance(CLSID_MathInputControl);
   hr = g_spMIC->EnableExtendedButtons(VARIANT_TRUE);
   hr = g_spMIC->Show();

   return hr;
}

I call the dll function in C# and the panel pops up but disappears right away. Any suggestions?


回答1:


In your C# project, add a reference to the COM library micautLib. Then you can use the following code (in C#):

MathInputControl ctrl = new MathInputControlClass();
ctrl.EnableExtendedButtons(true);
ctrl.Show();

I'm not sure if this is exactly how you're supposed to do it, but this seems to work cleanly (complete program).

using System;
using System.Windows.Forms;
using micautLib;

namespace MathInputPanel
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MathInputControl ctrl = new MathInputControlClass();
            ctrl.EnableExtendedButtons(true);
            ctrl.Show();
            ctrl.Close += () => Application.ExitThread();
            Application.Run();
        }
    }
}


来源:https://stackoverflow.com/questions/1623378/trying-to-create-a-math-input-panel-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!