有没有办法让CF2.0中的图片透明? 我必须在文本框上放置一个小图像,但它必须是透明的,以便用户无论如何都可以看到文本。 你有好主意吗?
非常感谢您
twickl
编辑:
感谢您的回答,我会检查这些链接!
为了完成我的帖子,我想做的是:
我想显示一个小图像(该图像尚不存在,我必须制作它,所以我对所有格式完全开放),它是一个 X在文本框的右端。 通过单击 X,文本框中的文本将被删除...就像在 iPhone 上一样。 但我无法构建自己的控件,因为在我的项目中有很多文本框,它们都是带有 Windows 文本框的自定义控件,因此将它们全部切换为自定义控件需要大量的工作和测试。 所以我有一个想法,制作一个位于文本框上方的小面板、图片框等。 但它必须是透明的。 操作系统是Windows CE 5.0,上面有CF 2.0。
is there a way, to make a picture transparent in CF2.0? I have to lay a small Image over a textbox, but it has to be transparent so the User can see the text anyway. Do you have an Idea?
Thank you very much
twickl
Edit:
Thanks for your answers, I will check those links out!
To complete my Post, here is what I´m trying to do:
I want to show a small image (the image does not exist yet and I have to make ist, so I´m totaly open for all formats) that is an X on the right end of a textbox. By clicking that X the Text inside the textbox will be erased...like on the iPhone. But I can not build my own control becuse in my Project are so many TextBoxes that are allready custom Controls with the windows TextBox on it, that it will be to much work and testing to switch all of them to custom controls. So I have the Idea to make a small Panel, Picturebox, whatever, that lays above the Textbox. But it has to be transparent. The OS is Windows CE 5.0 with CF 2.0 on it.
发布评论
评论(2)
根据您需要的透明度类型,您可以选择以下任一选项:
1.) 如果您的图像的特定部分应完全透明,则可以使用 ImageAttributes.SetColorKey() 设置单一透明颜色,然后将其传递给 Graphics.DrawImage。 您的图像需要具有一种完全透明的颜色(例如 Color.Cyan)。
2.) 如果您希望整个图像部分透明,例如淡入/淡出效果,您可以 P/Invoke AlphaBlend() 函数,如演示 此处。
3.) 如果您有内置透明度信息的图像,例如需要在各种背景颜色上渲染的透明 PNG 图像,则这些先前的方法将不起作用,您需要使用基于 COM 的 IImage 界面。
.NETCF 的 COM 互操作记录在此页面(在该页面上搜索“IImage 接口”)。
选项 3 是最灵活的,但也涉及最多的实施工作。 如果您后续了解有关您想要透明绘制的图像类型和目标平台的更多信息,我们也许能够提供更多帮助。
Depending on what kind of transparency you need, you might choose any of these options:
1.) If you have an image with a specific portion that should be entirely transparent, you can use ImageAttributes.SetColorKey() to set a single transparent color and then pass this to Graphics.DrawImage. Your image will need to have one color (e.g. Color.Cyan) that will be drawn completely transparent.
2.) If you'd like the entire image to be partially transparent, e.g. for a fade in/fade out effect, you can P/Invoke the AlphaBlend() function, as demonstrated here.
3.) If you have an image with transparency information built in, e.g. a transparent PNG image that needs to be rendered on a variety of background colors, these previous methods will not work and you need to use the COM based IImage interface.
The COM interop from .NETCF is documented on this page (search for "IImage interface" on that page).
Option 3 is the most flexible, but it also involves the most implementation effort. If you follow up with more information about the kind of image you want to draw transparently and your target platform, we might be able to help more.
我通过从 PictureBox 派生一个类并处理 OnPaint 来做到这一点。 关键是传递给 DrawImage 的 ImageAttributes 对象。 我假设像素 0,0 是透明颜色,但您可以以不同的方式处理它。
I did it by deriving a class from PictureBox and handling OnPaint. The key is the ImageAttributes object passed to DrawImage. I'm assuming pixel 0,0 is the transparent color, but you could handle that differently.