IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Gestion de BackColor et la transparence


Sujet :

C#

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Juillet 2015
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Webmaster

    Informations forums :
    Inscription : Juillet 2015
    Messages : 3
    Points : 1
    Points
    1
    Par défaut Gestion de BackColor et la transparence
    Bonjour à tous, je rencontre actuellement un soucis avec Visual Studio 2013, je souhaite mettre en oeuvre mon projet mais j'ai un soucis lorsque je souhaite passer la valeur "BackColor" en "Transparent", un message d'erreur survient, j'ai tenté de regarder un peu partout sur internet mais rien à faire. je vous fournis l'image pour plus de précision et le code.

    http://zupimages.net/up/15/31/ir9l.jpg

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Le contrôle ne prend pas en charge les couleurs d'arrière-plan transparentes.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Security.Cryptography;
     
     
    namespace teraLauncher
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
                this.BackColor = Color.Transparent;
                InitializeComponent();
     
            }
     
     
     
            /// <summary> 
            /// 取得 MD5 編碼後的 Hex 字串 
            /// 加密後為 32 Bytes Hex String (16 Byte) 
            /// </summary> 
            /// <span  name="original" class="mceItemParam"></span>原始字串</param> 
            /// <returns></returns> 
     
            public static string GetMD5(string original)
            {
                MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
                byte[] b = md5.ComputeHash(Encoding.UTF8.GetBytes(original));
                return BitConverter.ToString(b).Replace("-", string.Empty).ToLower();
            }
     
     
            private void button1_Click(object sender, EventArgs e)
            {
     
                //this.Text = GetMD5(textBox2.Text);
                Process.Start("tera.exe","1 " + GetMD5(textBox2.Text) + " 0 1 " + textBox1.Text + " en");
     
            }
     
            private void Form1_Load(object sender, EventArgs e)
            {
     
            }
     
            private void label2_Click(object sender, EventArgs e)
            {
     
     
            }
     
            private void label1_Click(object sender, EventArgs e)
            {
     
     
            }
     
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
     
            }
     
            private void textBox2_TextChanged(object sender, EventArgs e)
            {
     
            }
        }
    }
    Cordialement.

  2. #2
    Membre éclairé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2010
    Messages
    479
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2010
    Messages : 479
    Points : 762
    Points
    762
    Par défaut
    Salut, je te propose ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    public Form1()
    {
        InitializeComponent();
        SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        this.BackColor = Color.Transparent;
        this.TransparencyKey = Color.Transparent; //ajouter cette ligne
    }
    protected override void OnPaintBackground(PaintEventArgs e) { /* Ignore */ } //et celle là
    Testé et ça fonctionne chez moi.

    A+

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Juillet 2015
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Webmaster

    Informations forums :
    Inscription : Juillet 2015
    Messages : 3
    Points : 1
    Points
    1
    Par défaut
    Bonjour lead8209, Cela n'a pas fonctionné, à savoir que j'utilise la fonction "BackgroundImage" pour afficher un arrière-plan "System.Drawing.Bitmap".

    http://zupimages.net/up/15/31/diyk.jpg

    Cordialement.

  4. #4
    Membre éclairé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2010
    Messages
    479
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2010
    Messages : 479
    Points : 762
    Points
    762
    Par défaut
    Ha... effectivement et est-ce que ton image st un png qui gère la transparence ? ou un Bitmap avec transparence ? C'est peut-être ça le problème ?

  5. #5
    Nouveau Candidat au Club
    Homme Profil pro
    Webmaster
    Inscrit en
    Juillet 2015
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Webmaster

    Informations forums :
    Inscription : Juillet 2015
    Messages : 3
    Points : 1
    Points
    1
    Par défaut
    Oui c'est un un png qui gère la transparence.

  6. #6
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour
    Pour render transparent -tout (y compris les controls + backgroundimage )-ce qui est sur ton form,tu as la prop Opacity...

    Si tu veux peindre un arriere-plan de couleur transparent sur le backgroundimage tu l'event paint du form en plus...

    code .cs:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
     
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
     
    namespace WinTransparent
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                SetStyle(ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer, true);
                this.BackgroundImage = WinTransparent.Properties.Resources.Tulips;
                this.BackgroundImageLayout = ImageLayout.Stretch;
     
                this.Opacity = 70.0;
    }
     
            private void Form1_Paint(object sender, PaintEventArgs e)
            {
                Graphics gr = e.Graphics;
                Rectangle rect = this.ClientRectangle;
                SolidBrush br = new SolidBrush(Color.FromArgb(70, Color.Magenta));
     
                gr.FillRectangle(br,rect);
     
            }
        }
    }
    bon code...

Discussions similaires

  1. [AC-2003] gestion transparence ACCESS
    Par jscaion dans le forum IHM
    Réponses: 0
    Dernier message: 16/04/2009, 12h14
  2. Réponses: 0
    Dernier message: 03/11/2008, 10h49
  3. Gestion de la transparence
    Par anarpunk dans le forum Delphi
    Réponses: 5
    Dernier message: 20/10/2006, 13h05
  4. [GD] Gestion de la transparence
    Par tclariss dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 27/09/2006, 12h55
  5. [Internet Explorer] Gestion transparence png
    Par LE NEINDRE dans le forum IE
    Réponses: 5
    Dernier message: 17/03/2006, 12h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo