Hi,
How to make the picturebox as transparent .When i set the property to transparent in netcf 2.0 i can't make it.So how to do this
.NET Compact Framework
Hi,
How to make the picturebox as transparent .When i set the property to transparent in netcf 2.0 i can't make it.So how to do this
Hi Senthil,
I'm not 100% sure, you can make a picturebox transparent.
But you shall definitly have a look at this post by Alex Yaknin(http://blog.opennetcf.org/ayakhnin/PermaLink,guid,0b5a9c02-0a44-4d5e-85f9-949cab4ad8f3.aspx). He shows in his provided sample, how to create transparent and blended elemts.
Cheers, Peter
Thanks peter.
Since i am using device with widows mobile 2003 SE i am not having AlphaBlend API .So is there is any other way to solve it.
Below you find a quick and dirty Transparent picturebox descendant, it assumes your transparentcolor is Fuchsia so change that if you need, or readout the bottomleft pixel to determine the transparentcolor, and it gets the background color from the parent control (if available).
public class TransparentPictureBox : PictureBox
{
protected override void OnPaint(PaintEventArgs e)
{
ImageAttributes ia = new ImageAttributes();
ia.SetColorKey(Color.Fuchsia,Color.Fuchsia);
using (Brush brush=new SolidBrush(Parent==null BackColor : Parent.BackColor) )
{
e.Graphics.FillRectangle(brush, ClientRectangle);
}
e.Graphics.DrawImage(Image, new Rectangle(0, 0, Image.Width, Image.Height), 0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel, ia);
}
}
Hi,
You have to check the post a bit further. You are correct, that the sample is mostly based on the AlphaBlend API, which is only supported by CE 5.0 and therefore only in Windows Mobile 5 & 6.
But look at the following snippet in the ImageButton.cs:
public void Paint(Graphics gx)
{
if (!pushed || imageDown == null)
{
ImageAttributes attrib = new ImageAttributes();
Color color = GetTransparentColor(image);
attrib.SetColorKey(color, color);
gx.DrawImage(image, clientArea, 0, 0, clientArea.Width, clientArea.Height, GraphicsUnit.Pixel, attrib);
}
else
{
ImageAttributes attrib = new ImageAttributes();
Color color = GetTransparentColor(imageDown);
attrib.SetColorKey(color, color);
gx.DrawImage(imageDown, clientArea, 0, 0, clientArea.Width,
clientArea.Height, GraphicsUnit.Pixel, attrib);
}
}
private Color GetTransparentColor(Bitmap image)
{
return image.GetPixel(0, 0);
}
...
You should recognize, that it is only handled with the ImageAttributes, which are present in the .NET Compact Framework 1.0 and 2.0. The according Graphics-function is present in the .NET CF 1.0 and 2.0 as well.
By that, the function shall work for you, if you only want to have a color transparent (like the slider in the sample, which is surrounded by pink).
Hope this helps.
Cheers, Peter