C# 无法处理SAP B1 UI API中的按钮单击事件

C# 无法处理SAP B1 UI API中的按钮单击事件,c#,visual-studio-2015,sapb1,C#,Visual Studio 2015,Sapb1,我从SAPB1UIAPI(9.0)开始,并尝试在没有任何运气的情况下处理按钮点击。我就是这样做的(删除不必要的内容以缩短它): 当我点击按钮时,什么也没发生,这是我要走的路吗?我在handler方法中做了很多变化,但什么都没有。另一个细节是VisualStudio的调试器在加载项启动后立即终止(这可能与我的问题有关) 我希望你能帮助我。提前谢谢 David。由于应用程序停止运行,根据您喜欢使用什么,这个问题有两种可能的答案 如果您使用的是SAPbouiCOM库,则需要一种保持应用程序运行的方法,

我从SAPB1UIAPI(9.0)开始,并尝试在没有任何运气的情况下处理按钮点击。我就是这样做的(删除不必要的内容以缩短它):

当我点击按钮时,什么也没发生,这是我要走的路吗?我在handler方法中做了很多变化,但什么都没有。另一个细节是VisualStudio的调试器在加载项启动后立即终止(这可能与我的问题有关)

我希望你能帮助我。提前谢谢


David。

由于应用程序停止运行,根据您喜欢使用什么,这个问题有两种可能的答案

如果您使用的是
SAPbouiCOM
库,则需要一种保持应用程序运行的方法,我使用的方法是
System.Windows.Forms.application.Run()

如果您使用SAP BusinessOneSDK和
sapbuicom.Framework
作为参考,则可以使用
App.Run()


这两个都需要在安装代码运行后立即调用。

非常感谢Vyron,我正在使用
SAPbouiCOM
System.Windows.Forms.Application.run()
非常有效。
static void Main(string[] args)
{
    SetApplication(args);

    var cParams = (FormCreationParams)App.CreateObject(BoCreatableObjectType.cot_FormCreationParams);
    cParams.UniqueID = "MainForm_";
    cParams.BorderStyle = BoFormBorderStyle.fbs_Sizable;

    _form = App.Forms.AddEx(cParams);
    /*Setting form's title, left, top, width and height*/

    // Button
    var item = _form.Items.Add("BtnClickMe", BoFormItemTypes.it_BUTTON);
    /*Setting button's left, top, width and height*/
    var btn = (Button)item.Specific;
    btn.Caption = "Click Me";
    _form.VisibleEx = true;

    App.ItemEvent += new _IApplicationEvents_ItemEventEventHandler(App_ItemEvent);
}

private static void SetApplication(string[] args)
{
    string connectionString = args[0];
    int appId = -1;
    try
    {
        var guiApi = new SboGuiApi();
        guiApi.Connect(connectionString);
        App = guiApi.GetApplication(appId);
    }
    catch (Exception e)
    { /*Notify error and exit*/ }
}

private static void App_ItemEvent(string FormUID, ref ItemEvent pVal, out bool BubbleEvent)
{
    BubbleEvent = true;

    if (FormUID == "MainForm_" && pVal.EventType == BoEventTypes.et_CLICK &&
        pVal.BeforeAction && pVal.ItemUID == "BtnClickMe")
    {
        App.MessageBox("You just click on me!");
    }
}