How to make a transparent image in CF 2.0 without third-party libraries?

Is there a way to make the image transparent in CF2.0? I have to lay a small image above the text box, but it must be transparent so that 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 these links! To complete my post, here is what I am trying to do:

I want to show a small image (the image does not exist yet, and I need to do ist, so I'm completely open to all formats), which is the X at the right end of the text box. By clicking this X, the text inside the text box will be deleted ... like on the iPhone. But I can’t create my own control, because in my project there are so many TextBoxes that are already custom controls with TextBox windows on it, that there will be a lot of work and testing to switch all of them to user controls. Therefore, I have an idea to create a small panel, Picturebox, anything that lies above the text box. But it must be transparent. OS - Windows CE 5.0 with CF 2.0 on it.

+4
source share
2 answers

I did this by deriving the class from the PictureBox and processing OnPaint. The key is the ImageAttributes object passed to DrawImage. I assume that a pixel of 0.0 is a transparent color, but you can handle it differently.

public partial class TransparentPictureBox : PictureBox { private Color tColor; public TransparentPictureBox() { InitializeComponent(); } public new Image Image { get { return base.Image; } set { if (value == base.Image) return; if (value != null) { Bitmap bmp = new Bitmap(value); tColor = bmp.GetPixel(0, 0); this.Width = value.Width; this.Height = value.Height; } base.Image = value; } } protected override void OnPaint(PaintEventArgs e) { e.Graphics.Clear(this.BackColor); if (Image == null) return; ImageAttributes attr = new ImageAttributes(); // Set the transparency color. attr.SetColorKey(tColor, tColor); Rectangle dstRect = new Rectangle(0, 0, base.Image.Width, base.Image.Height); e.Graphics.DrawImage(base.Image, dstRect, 0, 0, base.Image.Width, base.Image.Height, GraphicsUnit.Pixel, attr); } } 
+3
source

Depending on what transparency you need, you can choose any of these options:

1.) If you have an image with a specific part that needs to be completely transparent, you can use ImageAttributes.SetColorKey () to set one transparent color, and then pass it to Graphics.DrawImage. Your image should have one color (e.g. Color.Cyan), which will be completely transparent.

2.) If you want the whole image to be partially transparent, for example. for the fade in / fade out effect, you can P / call the AlphaBlend () function, as shown here .

3.) If you have an image with built-in transparency information, for example, a transparent PNG image that should be displayed on different color schemes, these previous methods will not work, and you need to use the COM IImage interface. The COM interaction from .NETCF is documented on this page (look for the "IImage interface" on this page).

Option 3 is the most flexible, but it also includes most implementation efforts. If you follow more information about what kind of image you want to transparently draw on the target platform, we can help more.

+8
source

All Articles