Pergunta

Como faço para criar uma entrada Math Panel em C #?

Eu tentei colocá-lo em uma DLL e chamá-lo, mas ele simplesmente fecha imediatamente.

#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;
}

Eu chamo a função de dll em C # e o painel aparece mas desaparece imediatamente. Alguma sugestão?

Foi útil?

Solução

Em seu projeto C #, adicione uma referência à biblioteca micautLib COM. Então você pode usar o seguinte código (em C #):

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

Eu não tenho certeza se isso é exatamente como você deveria fazê-lo, mas isso parece funcionar de forma limpa (programa completo).

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();
        }
    }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top