enable full transparency of the png background in the form

Asked

Viewed 87 times

0

Well I have a form c# however I use a render png, which contains some shadows and smoke effects, the only way I found to give transparency was the key, but it does not get totally transparent, example image below.

inserir a descrição da imagem aqui

I was wondering, if there’s any way to make it totally transparent.

  • see if this link helps: https://stackoverflow.com/questions/4387680/transparent-background-on-winforms

  • the solution code is still not working, that effect is even with the Lime

1 answer

0

You can cancel the event where the Background is painted and fill in an image this way:

public SeuForm()
{
    InitializeComponent();
    FormBorderStyle = FormBorderStyle.None;
    StartPosition = FormStartPosition.CenterScreen;
}
protected override void OnPaintBackground(PaintEventArgs e)
{
    //Definir sua imagem.
    Image newImage = Properties.Resources
        ._0_cKbBcUPJTfpFwuQi_;

    //Posição e tamanho da imagem
    //Aconselho deixar o seu form do tamanho da imagem já design time, para facilitar o desenvolvimento
    //ou pode setar os tamanhos do form para o da imagem pelo codigo tambem(ex: this.Width = newImage.Width;)

    //Caso deseje centralizar a imagem automaticamente:
    //x = (Width - newImage.Width) / 2; y = (Height - newImage.Height) / 2;
    int x = 100;
    int y = 100;

    //Desenhar imagem
    e.Graphics.DrawImage(newImage, x, y, width, height);
}

Resultado

Not a good practice, but I see no other way to achieve the result you want in WF.

  • now the bakcground fira totalmente preto https://imgur.com/a/qR0QG

Browser other questions tagged

You are not signed in. Login or sign up in order to post.