c# - 为 SAP B1 创建自定义 ActiveX 控件
问题描述
我正在尝试使用 ActiveX 为 SAP b1 创建自定义控件。
- 我创建了 Windows 窗体控件库
- 使项目装配信息 COM 可见(项目属性 => 应用程序 => 装配信息)
- 注册 COM 互操作(项目属性 => 构建)
我的用户控件看起来像这样:
[ComVisible(false)]
public delegate void OnCheckBoxClickEventHandler(string val);
[ProgId("MyComLib.Controls.TextBoxCheck")]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(ITextBoxCheckEvents))]
public partial class TextBoxCheckClass : UserControl, TextBoxCheck
{
public string PlaceHolder
{
get
{
return textBox1.Text;
}
set
{
textBox1.Text = value;
}
}
public TextBoxCheckClass()
{
InitializeComponent();
}
public event OnCheckBoxClickEventHandler OnCheckBoxClick;
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
textBox1.ReadOnly = checkBox1.Checked;
OnCheckBoxClick?.Invoke(textBox1.Text);
}
private void TextBoxCheck_Load(object sender, EventArgs e)
{
textBox1.Text = PlaceHolder;
}
[ComRegisterFunction()]
private static void RegisterClass(string key)
{
Registrar.RegisterClass(key, "MyComLib.Controls.TextBoxCheck");
}
[ComUnregisterFunction()]
private static void UnregisterClass(string key)
{
Registrar.UnregisterClass(key);
}
}
我正在使用的接口:
[Guid("5710FC13-103E-48F4-B674-80DDD3ABA0DB")]
public interface TextBoxCheck : ITextBoxCheck, ITextBoxCheckEvents_Event
{
}
[Guid("3AF22B4A-A941-4DBF-8ED5-EB6DAFF538E5")]
public interface ITextBoxCheck
{
[DispId(1)]
string PlaceHolder { get; set; }
}
[Guid("64C6CEC1-B855-4B7C-B2C8-31F7879DEA4E")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ITextBoxCheckEvents
{
[DispId(1)]
void OnCheckBoxClick(string val);
}
//[ComEventInterface(typeof(ITextBoxCheckEvents), typeof(ITreeViewEvents_EventProvider))]
[Guid("3DB40F69-E503-4CE2-8696-0349CC41114B")]
public interface ITextBoxCheckEvents_Event
{
[DispId(1)]
event OnCheckBoxClickEventHandler OnCheckBoxClick;
}
SAP b1 插件代码:
var classId = "MyComLib.Controls.TextBoxCheck";
var newItem = form.Items.Add("ActiveX1Id", BoFormItemTypes.it_ACTIVE_X);
var activeXControl = newItem.Specific as ActiveX;
activeXControl.ClassID = classId;
var myItem1 = activeXControl.Object as TextBoxCheck;
myItem1.PlaceHolder = "test1";
//getting error on this line
myItem1.OnCheckBoxClick += (val) =>
{
//some code;
};
但是当我在我的 SAP b1 插件中使用这个控件时,我得到了错误:
{“无法将 'System.__ComObject' 类型的对象转换为 MyComLib.Controls.OnCheckBoxClickEventHandler'。”}
如果有一些好的示例描述了如何将 dll 导出为 activeX 文件类型
,以及如何使用 ComEventInterface 属性和实现它会很好。
[ComEventInterface(typeof(ITextBoxCheckEvents), typeof(ITextBoxCheckEvents_EventProvider))]
另外,如果有一些好的文档如何创建像 ActiveX 库这样的 interop.MSComctlLib 会很好。
检查了这篇博文,但没有一篇描述如何处理事件
解决方案
推荐阅读
- python - 如何修复 os.path.join(os.getcwd(), os.relpath('my_file')) 不返回'my_file'的路径?
- html - 制作一个按钮以在 div 中水平滚动
- javascript - 为什么我会收到此错误 - “您正在使用未定义的组件调用 withTheme(Component)。” -反应JS
- javascript - filter() 和 includes() 获得部分匹配
- jhipster - 有没有办法在重新生成实体时不覆盖对实体所做的修改?
- java - Java 8 - 从具有嵌套列表的对象列表中收集到地图中
- spring - resttemplate GET 将一个集合包装在一个附加标签中
- python - 如何获得只有上对角线元素的零矩阵?(上对角线元素已知)
- python - OpenAI 健身房渲染 OSError
- sql - 如何使用 SQL 从 2 个表中获取百分比