如何重写 Winforms 控件的绘制方法以使其绘制到纹理?
我正在尝试将 Winforms 与 SharpDX 项目集成,以便在我的 3D 应用程序中使用 Winforms(最终通过 HostElement 使用 WPF)。
我需要创建或配置一个控件或表单,以便我可以
:将其渲染为纹理(我可以将其显示为精灵*)
b.当控件不活动时,过滤其输入以删除鼠标/键盘事件。
我尝试过对 Control 和 Form 进行子类化,以覆盖 OnPaint 和 OnPaintBackground 但这些对子控件没有影响 - 或者就表单边框而言(即使它们这样做了,它们本身也不够,因为我仍然留下一个白色的方块,我认为已经在其中绘制了“父级”)。
如何停止在屏幕上绘制控件或窗体,而只绘制位图?(例如,是否有某种方法可以在绘制树之前覆盖图形?)
*它需要以这种方式完成(而不是让控件渲染到屏幕),因为 Winforms 不支持真正的透明度,所以我需要在像素着色器中剪辑颜色编码的像素。
(确认一下,我并不是专门指 DirectX 纹理 - 我对(事实上更喜欢)一个简单的 System.Drawing 位图感到满意)
I am trying to integrate Winforms with a SharpDX project, in order to use Winforms (and eventually WPF via HostElement) in my 3D app.
I need to create or configure a Control or Form such that I can:
a. Render it to a texture (that I can display as a sprite*)
b. Filter its input to remove mouse/keyboard events when the control is not active.
I have tried subclassing Control and Form, to override the OnPaint and OnPaintBackground but these have no effect on the child controls - or for that matter the forms borders (and even if they did they are not sufficient on their own as I am still left with a white square where I presume the 'parent' has been drawn).
How can I stop a Control or Form painting to the screen and instead draw only to a bitmap? (Is there some way I can override Graphics before the tree is painted, for example?)
*It needs to be done this way (as opposed to letting the control render to the screen) as Winforms doesn't support true transparency, so I need to clip colour coded pixels in my pixel shader.
(To confirm, I don't mean a DirectX texture specifically - I am happy with (in fact would prefer) a simple System.Drawing Bitmap)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面是开始处理它的一种方法:
Here is one way to start going about it: