Compact Framework 上使用 GDI 进行绘图控件
我需要在 Compact Framework 应用程序中绘制一个文本框,但直接使用 Graphics 对象。
我找到了 Control.DrawToBitmap 方法,我可以使用它来使用 GDI 进行绘图,但它在 Compact Framework 上不可用。
有什么提示吗?
I need to draw a textbox in a Compact Framework app, but using directly a Graphics object.
I've found the Control.DrawToBitmap method, which I could use for drawing with GDI, but it's not available on Compact Framework.
Any hints?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Control.DrawToBitmap() 是通过向控件发送 WM_PRINT 来让它在内存设备上下文中绘制自身来实现的。如果您使用非标准控件,则程序员很可能没有实现此消息。我也不认为它是由标准 Windows Mobile 控件实现的。
那么你唯一的其他办法就是复制屏幕上的像素。 Graphics.CopyFromScreen() 是不行的,您必须 P/Invoke BitBlt() API 函数。可能有用的示例代码可在 此线程。 以及 pinvoke.net
Control.DrawToBitmap() is implemented by sending WM_PRINT to the control to let it draw itself in a memory device context. If you are using non-standard controls, the odds are great that the programmer did not implement this message. I don't think it is implemented by the standard Windows Mobile controls either.
Your only other recourse then is to copy the pixels off the screen. Graphics.CopyFromScreen() is a no-go, you'll have to P/Invoke the BitBlt() API function. Possibly useful sample code is available in this thread. and at pinvoke.net
通常,您只需继承:Control,重写 OnPaint 并使用参数提供的图形对象。你试过这个了吗?
Well typically you just inherit from : Control, override OnPaint and use the graphics object provided by the arguments. Have you tried this yet?
我不知道这是否可行......但从技术上讲,您可以使用反射来调用控件的 OnPaint 方法,并在一组新的 PaintEventArgs 中传入您自己的图形对象 (Graphics.FromImage)。
它很难看……但它可能有效。
I have no idea if this would work.... but technically you could use reflection to call into the control's OnPaint method and pass in your own graphics object (Graphics.FromImage) in a new set of PaintEventArgs.
It's ugly as hell..... but it might work.