如何在 Visual Studio 表单设计器中呈现 .NET Compact Framework 自定义控件的位图属性?

发布于 2024-09-24 20:49:32 字数 494 浏览 1 评论 0原文

我有一个具有位图属性的自定义控件(继承自 control;面向 .NET Compact Framework v2)。

目前,表单设计器上的控件实例将仅绘制选定的背景颜色并在顶部写入 namespace.control.name

在属性编辑器中选择图像后,如何让表单设计器呈现图像?

编辑:该控件相当基本,但我重写了onpaintonpaintbackground

Edit2:努力确定因为我写了一个更简单的控件。它只是一个位图属性和对 onpaint 中的 graphics.drawimage 的调用(所以是一个便宜的 imagebutton)。这也无法渲染。我什至进行了一项检查,以确保它不会尝试渲染空图像并且从不刷新或任何其他内容,但没有运气。

I have a custom control (inheriting from control; targeting .NET Compact Framework v2) that has a bitmap property.

Currently an instance of the control on the form designer will only paint the selected background color and writes the namespace.control.name overtop.

How can I have the image be rendered by the form designer after it's selected in the property editor?

Edit: The control is fairly basic but I am overriding onpaint and onpaintbackground

Edit2: In an effort to determine the cause I wrote a much simpler control. It's just a bitmap property and a call to graphics.drawimage in onpaint (so a cheap imagebutton). This too fails to render. I even included a check to make sure it wasn't trying to render a null image and never refreshing or anything, but no luck.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜尕妞 2024-10-01 20:49:32

您是否手动绘画(即覆盖 OnPaint 并绘制该位图)?一般来说,设计器中的渲染对于一个非常基本的控制应该起作用。

如果设计器遇到无法处理的问题(例如 P/Invoke),您将得到带有控件名称的框,因此您通常必须“保护”设备特定代码不被设计器调用。

尝试取消功能,直到它开始正确渲染,以找出失败的地方(因为您无法以任何其他方式真正调试这个东西)。

Are you manually painting (i.e. overriding OnPaint and drawing that Bitmap out)? Generally speaking rendering in the designer for a very basic control should work.

You'll get the box with the control name if the designer hits something that it can't handle (a P/Invoke fore example) and so often you have to "protect" the device specific code from being called by the designer.

Try backing out functionality until it starts rendering properly to figure out where it's failing (becasue you can't really debug this stuff any other way).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文