Picture box fond transparent

catamenia Messages postés 119 Date d'inscription mercredi 15 octobre 2003 Statut Membre Dernière intervention 21 juillet 2009 - 2 mars 2006 à 13:29
Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 - 3 mars 2006 à 13:51
bonjours,

Je voudrais faire glisser sur un control un picturebox avec un fond transparent pour que l'on voit que la forme de l'image du picturebox

quel sont les solutions?

merci
A voir également:

3 réponses

Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 41
3 mars 2006 à 01:06
Salut, c'est plus simple de dessiner directement sur la forme, sinon c'est possible mais faut utiliser un bitmap avec une couleur de fond unie ( pas un jpg ).


Bitmap bmp = new Bitmap( "image.bmp" );
bmp.MakeTransparent( bmp.GetPixel( 0, 0 ) ); // Le pixel 0 devient la couleur transparente.


MyPictureBox pb = new MyPictureBox( );
pb.Image = bmp;


this.BackgroundImage = new Bitmap( "background.jpg" );
this.Controls.Add( pb );



// ..


public class MyPictureBox : PictureBox
{
public MyPictureBox( )
{
this.SetStyle
(
ControlStyles.UserPaint |
ControlStyles.SupportsTransparentBackColor,
true
);


this.BackColor = Color.Transparent;
}
}
0
catamenia Messages postés 119 Date d'inscription mercredi 15 octobre 2003 Statut Membre Dernière intervention 21 juillet 2009
3 mars 2006 à 07:19
j'ai deja essayé se genre de manipulation mais le probleme est que la transparence est la couleur de la form.
Si le control transaparent passe sur un autre control j'aimerai voir se control par transparence
0
Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 41
3 mars 2006 à 13:51
C'est possible si tu créer ta propre PictureBox.


Et dans ta forme tu dois aussi rajouter :

this.ResizeRedraw = true;
Bitmap bmp = new Bitmap( "image.bmp" );
bmp.MakeTransparent( bmp.GetPixel( 0, 0 ) );
MyPictureBox pb1 = new MyPictureBox( );
pb1.Image = bmp;


public class MyPictureBox : UserControl
{
private const int WS_EX_TRANSPARENT = 0x00000020;


private Image image = null;


public Image Image { get { return image; } set { image = value; } }


public MyPictureBox( ) : base( )
{


}

protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= WS_EX_TRANSPARENT;
return cp;
}
}


protected override void OnPaintBackground( PaintEventArgs e )
{
// vide.
}

protected override void OnPaint( PaintEventArgs e )
{
//base.OnPaint( e );


if ( image == null )
return;


e.Graphics.DrawImage( image, this.ClientRectangle );
}
}
0