begin process at 2013 05 22 20:12:11
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

.NET

 > AJOUTER DES BOUTONS DYNAMIQUEMENT AVEC CHANGEMENT DE COULEURS POUR CES BOUTONS (SMARTDEVICE)

AJOUTER DES BOUTONS DYNAMIQUEMENT AVEC CHANGEMENT DE COULEURS POUR CES BOUTONS (SMARTDEVICE)


 Information sur la source

Note :
Aucune note
Catégorie :.NET Source .NET ( DotNet ) Classé sous :SmartDevice, Dynamique, Couleur, boutton, PDA Niveau :Débutant Date de création :06/06/2012 Vu / téléchargé :3 603 / 149

Auteur : cheMoor

Ecrire un message privé
Commentaire sur cette source (2)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
Ajouter des boutons dynamiquement avec changement de couleurs pour ces boutons (SmartDevice)

ce projet montre comment on peut ajouter des contrôles dynamiquement et de changer la proprité couleur.

ce projet est utilisé dans l'envirenment SmartDevice.

Youssef; che.moor

Source

  • using System;
  • using System.Linq;
  • using System.Collections.Generic;
  • using System.ComponentModel;
  • using System.Data;
  • using System.Drawing;
  • using System.Text;
  • using System.Windows.Forms;
  • namespace SmartDeviceProject1
  • {
  • public partial class Form1 : Form
  • {
  • public Form1()
  • {
  • InitializeComponent();
  • }
  • private void Form1_Load(object sender, EventArgs e)
  • {
  • int i;
  • int h;
  • int w;
  • int w_b = 0;
  • int h_b = 0;
  • string txt_dec;
  • w = Screen.PrimaryScreen.Bounds.Width;
  • h = Screen.PrimaryScreen.Bounds.Height;
  • List<Button> txb= new List<Button>();
  • Color myColor = new Color();
  • for (i = 0; i <= 100; i++)
  • {
  • Button xb = new Button();
  • Font fn = new Font("Tahoma", 6, FontStyle.Regular);
  • Size sz = new Size();
  • txt_dec = String.Format("{0:x6}", 16711680 + i * 2);//"F400A1"; //
  • myColor = HexToColor(txt_dec);
  • xb.BackColor = myColor;
  • sz.Height = 24;
  • sz.Width = 32;
  • xb.Size = sz;
  • xb.Text = "1_" + i;
  • xb.Click += new EventHandler(NewButton_YYY);
  • xb.KeyDown += new KeyEventHandler(NewButton_XXX);
  • xb.KeyUp+= new KeyEventHandler(NewButton_XXX);
  • this.Controls.Add(xb);
  • if (i != 0)
  • {
  • if (w_b + sz.Width >= w)
  • {
  • w_b = 0;
  • h_b =h_b+ sz.Height;
  • xb.Location = new Point(w_b, h_b);
  • }
  • else
  • xb.Location = new Point(txb[i - 1].Location.X + txb[i - 1].Width, txb[i - 1].Location.Y);
  • }
  • else
  • xb.Location = new Point(w_b, h_b);
  • xb.Font = fn;
  • txb.Add(xb);
  • w_b = w_b + sz.Width;
  • }
  • }
  • void NewButton_YYY(object sender, EventArgs e)
  • {
  • Button CurrentButton = (Button)sender;
  • CurrentButton.Text = CurrentButton.Text + "_2";
  • }
  • void NewButton_XXX(object sender, EventArgs e)
  • {
  • Button CurrentButton = (Button)sender;
  • Color c = new Color();
  • c = CurrentButton.ForeColor;
  • CurrentButton.ForeColor = CurrentButton.BackColor;
  • CurrentButton.BackColor = c;
  • }
  • private Color HexToColor(string sHex)
  • {
  • int iR = 0;
  • int iV = 0;
  • int iB = 0;
  • iR = Convert.ToInt32(sHex.Substring(0, 2),16);
  • iV = Convert.ToInt32(sHex.Substring(2, 2),16);
  • iB = Convert.ToInt32(sHex.Substring(4, 2),16);
  • return Color.FromArgb((int)iR, (int)iV, (int)iB);
  • }
  • }
  • }
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


namespace SmartDeviceProject1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            int i;
            int h;
            int w;
            int w_b = 0;
            int h_b = 0;

            string txt_dec;
            
            
            w = Screen.PrimaryScreen.Bounds.Width;
            h = Screen.PrimaryScreen.Bounds.Height;
            List<Button> txb= new List<Button>();

            Color myColor = new Color();

            for (i = 0; i <= 100; i++)
            {
                
                Button xb = new Button();
                Font fn = new Font("Tahoma", 6, FontStyle.Regular);
                Size sz = new Size();

                txt_dec = String.Format("{0:x6}", 16711680 + i * 2);//"F400A1"; //
                myColor = HexToColor(txt_dec);
                xb.BackColor = myColor;
                
               sz.Height = 24;
                sz.Width = 32;
                xb.Size = sz;
                
                xb.Text = "1_" + i;
                xb.Click += new EventHandler(NewButton_YYY);
                xb.KeyDown += new KeyEventHandler(NewButton_XXX);
                xb.KeyUp+= new KeyEventHandler(NewButton_XXX);
                
                this.Controls.Add(xb);
                if (i != 0)
                {
                    if (w_b + sz.Width >= w)
                    {
                        w_b = 0;
                        h_b =h_b+ sz.Height;
                        xb.Location = new Point(w_b, h_b);

                    }
                    else
                       xb.Location = new Point(txb[i - 1].Location.X + txb[i - 1].Width, txb[i - 1].Location.Y);
                }
                else
                    xb.Location = new Point(w_b, h_b);

                xb.Font = fn;
                txb.Add(xb);
                w_b = w_b + sz.Width;
            }
        }
        void NewButton_YYY(object sender, EventArgs e)
        {
            Button CurrentButton = (Button)sender;

            CurrentButton.Text = CurrentButton.Text + "_2";
        }

        void NewButton_XXX(object sender, EventArgs e)
        {
            Button CurrentButton = (Button)sender;
            Color c = new Color();
            c = CurrentButton.ForeColor;
            CurrentButton.ForeColor = CurrentButton.BackColor;
            CurrentButton.BackColor = c;
        }

        private Color HexToColor(string sHex)
        {
            int iR = 0;
            int iV = 0;
            int iB = 0;
            iR = Convert.ToInt32(sHex.Substring(0, 2),16);
            iV = Convert.ToInt32(sHex.Substring(2, 2),16);
            iB = Convert.ToInt32(sHex.Substring(4, 2),16);
            return  Color.FromArgb((int)iR, (int)iV, (int)iB);
        }
    }
}

 Conclusion

IMPORTANT

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources de la même categorie

UTILISER LA SOURIS POUR SCROLLER MON FLOWLAYOUTPANEL par SamsonB
Source .NET (Dotnet) APPEL C DEPUIS C# / APPEL C# DEPUIS C par Moomoon07
Source avec Zip Source .NET (Dotnet) UN PETIT LOGICIEL DE VISUALISATION DE PHOTO par okosa
Source avec Zip Source avec une capture Source .NET (Dotnet) PROBLÈME DU SAC À DOS : RÉSOLUTION PAR MINIMISATION par olivieram2
Source avec Zip Source avec une capture Source .NET (Dotnet) RESOLVER DU JEUX DE L'EMISSION DES CHIFFRES ET DES LETTRES D... par rabixpvb

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture Source .NET (Dotnet) VERSIONCHECKER par gta126
Source avec Zip Source avec une capture Source .NET (Dotnet) ORIONAPPLICATION par toutphp
Source avec Zip Source .NET (Dotnet) BALLON, CAREE ET IMAGE QUI TOURNENT, SE GONFLENT ET SE DGONF... par zertyx
Source avec Zip Source avec une capture Source .NET (Dotnet) DÉMINEUR JR par jrscofield
Source avec Zip Source avec une capture Source .NET (Dotnet) PANNEAUX DYNAMIQUES (MENU ASCENSSEUR) par Robert33

Commentaires et avis

Commentaire de tmcuh le 08/07/2012 19:26:21

n'existe-t-il pas un FlowLayoutPanel en smart? plutot que de s'ennuyer à calculer les positions de chaque controle

Commentaire de cheMoor le 08/07/2012 19:59:11

Bsr TMCUH,

je ne sais pas, mais je vais chercher et je te réponds!

cordialement

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

boutton paramètrable [ par mathmax ] Bonjour, Je cherche &#224; changer la couleur de mes boutons en fonction d'une variable. Je m'explique : j'ai une variable i, si celle ci vaux 1 je v EventTrigger click boutton changement de couleur windows [ par babyboo1107 ] Bonjour, voilà j'aimerais sans devoir passer par le gestionnaire du click du bouton faire ceci [code=cs] private void button1_Click(object sender, PDA wince et base de donnée oracle distante sur serveur [ par imanov2008 ] j'ai un pda avec code à barre contenant le windows CE et je suis entrain de développer une application C# .net qui récupère le code à barre et par wif solid brush [ par sakuramachine ] j'ai a dessiner ces carré et je dois assiger comme couleur a solid brush la couleur d'une variable = Couleur 1 je fais comment projet widget pour mon stage [ par ismalife ] Bonjour a toutes et à tous, J'ai 2 souci avec mon datagridView : le premier est de savoir comment aggrandir la largeur de mes colonnes ???? et le 2èm typage dynamique multiple [ par l0r3nz1 ] Bonjour, je fais une fonction qui peut prendre en argument un controle avec liste, genre comboBox ou ListTextBox. pour l'instant je suis decu, j'ai Changer couleur d'un string [ par kdesigner ] Bonjour j'aurais voulu savoir s'il était possible de changer la couleur basique noire d'une chaine en une autre couleur je m'explique: string str=" Création d'un fichier autorun [ par mr100kv ] Bonjour, En fait, je dois créer un fichier autorun pour PDA sous WM6.5. Le principe : ce fichier autorun, placé dans le répertoire 2577 d'une carte S comment modifier forme et couleur messagebox [ par adleni ] Salut! comment modifier la forme et couleur messagebox C# Changer la couleur de fond des cellules d'une colonne Excel [ par YuneSh ] SVP je veux savoir comment pourrais-je changer la couleur du contenu des cellules d'une colonne dans un fichier Excel ! Merci YùnéSh


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2013
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
2728293031  

Consulter la suite du CalendriCode

Photothèque

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,373 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales