Accueil > > > 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
Description
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
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
boutton paramètrable [ par mathmax ]
Bonjour, Je cherche à 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
|
Derniers Blogs
SIMULER FACILEMENT L'ENVOI DE MAILSIMULER FACILEMENT L'ENVOI DE MAIL par JeremyJeanson
il m'a été demandé, à plusieurs reprises, comment je faisais pour simuler l'envoi de mail lors de mes démos de Workflow Foundation. Ma solution est plutôt simple : j'utilise la configuration par défaut du SmtpClient et j'oriente les mails vers un dossier ...
Cliquez pour lire la suite de l'article par JeremyJeanson VOTEZ POUR LE TOP 10 DES INFLUENCEURS SHAREPOINT FRANCOPHONES !VOTEZ POUR LE TOP 10 DES INFLUENCEURS SHAREPOINT FRANCOPHONES ! par Patrick Guimonet
Si ce n'est déjà fait (comme plus de 600 personnes déjà), il est encore temps de voter pour le concours TOP 10 des influenceurs SharePoint francophones ! Il est organisé par harmon.ie et accessible ici : http://harmon.ie/top-...
Cliquez pour lire la suite de l'article par Patrick Guimonet [CONF'SHAREPOINT] DERNIER RAPPEL ! :-)[CONF'SHAREPOINT] DERNIER RAPPEL ! :-) par Patrick Guimonet
La Conf'SharePoint en chiffres c'est : 3 jours de SharePoint ! 4 parcours et 60 sessions 17 partenaires représentant toutes les fac...
Cliquez pour lire la suite de l'article par Patrick Guimonet [ #SHAREPOINT 2013 ] LES MODèLES DE SITES STANDARDS.[ #SHAREPOINT 2013 ] LES MODèLES DE SITES STANDARDS. par Patrick Guimonet
C'est un point peu mis en avant mais SharePoint 2013 a été l'occasion de remettre de l'ordre dans les modèles de sites. Tout d'abord, un certain nombre de modèles ont été tout simplement rendus obsolètes (cf. Fonctionnalités déco...
Cliquez pour lire la suite de l'article par Patrick Guimonet
Logiciels
Easy-Planning (4.5.0.11)EASY-PLANNING (4.5.0.11)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté a... Cliquez pour télécharger Easy-Planning CVEasy (3.1.0.51)CVEASY (3.1.0.51)PHMSD-CVEasy est un logiciel d'aide à la rédaction de CV d'une simplicité déconcertante.
PHMSD-C... Cliquez pour télécharger CVEasy LettresFaciles 2011 (8.6.0.31)LETTRESFACILES 2011 (8.6.0.31)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011 sDEVIS-FACTURES vlPRO (8.4.2.62)SDEVIS-FACTURES VLPRO (8.4.2.62)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO Devis-Factures PHMSD (2.1.0.11)DEVIS-FACTURES PHMSD (2.1.0.11)Configuration minimale
Nécessite Windows™ 2000, XP, Windows 7, 8, Vista (Service Pack à... Cliquez pour télécharger Devis-Factures PHMSD
|