c# - 覆盖派生控件中的 CreateHandle 方法
问题描述
让我们有一个第三方 DLL 来创建一个本地窗口并返回它的句柄。
我想通过基于 System.Windows.Forms.Control 的 MyControl 类在 C# WinForms 应用程序中使用此功能。
如何正确覆盖从 Control 派生的类中的虚拟受保护方法 Control.CreateHandle?
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WinFormsApp {
public class MyControl : Control {
[DllImport("MyLib.dll")]
static extern IntPtr CreateWindow();
protected override void CreateHandle() {
// Did to need do invoke a base.CreateHandle()?
// However, it creates Control.Handle it self.
var handle = CreateWindow();
// How to associate returned handle with MyControl instance?
(WindowTarget as NativeWindow)?.AssignHandle(handle);
}
}
}
解决方案
推荐阅读
- python - 用用户输入的变量替换 .docx 文件中的变量
- vue.js - 带有 HTTP 和 HTTPS url 的 Vue JS 项目
- c# - .Net 中带有订阅的 GraphQL 客户端
- php - 微前端:具有多个前端框架的 Web 应用程序
- c++ - 以嵌套类为参数的朋友模板声明
- r - 以编程方式将值发送到过滤器的 tidyeval 方式
- node.js - 节点js上的Multer sftp文件上传问题
- amazon-web-services - 我们可以使用 AWS Spot 实例来保证挖矿利润吗?
- kernel-module - 内核模块重启linux
- php - 无法向另一个 php 网站发出带有文件的 POST 请求