5/5 (3 avis)
Snippet vu 12 200 fois - Téléchargée 34 fois
using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Data; using System.Windows.Forms; using System.Drawing.Text; namespace Crazyht.C.Windows.Forms { /// <summary> /// Combobox contenant les Fonts installé sur le système /// </summary> [ToolboxBitmap(typeof(Crazyht.C.Windows.Forms.ComboFont),"ComboFont.bmp")]public class ComboFont : System.Windows.Forms.ComboBox { public ComboFont () { InstalledFontCollection fonts =new System.Drawing.Text.InstalledFontCollection(); FontFamily [] fontfamill = fonts.Families; for (long i = fontfamill.GetLowerBound(0);i<=fontfamill.GetUpperBound(0);i++) this.Items.Add(fontfamill[i].Name); fontfamill = null; fonts = null; this.SelectedIndex = 0; } protected override void OnKeyPress (KeyPressEventArgs args) { Int32 key = Convert.ToInt32(args.KeyChar); if (!( (key == 13) || (key == 27) || (key==8))) { string sCherche = this.Text.ToLower(); foreach (Object obj in this.Items) { if ( obj.ToString().ToLower().StartsWith(sCherche)) { this.Text = obj.ToString(); this.SelectionStart = sCherche.Length; this.SelectionLength = obj.ToString().Length - sCherche.Length; this.SelectedItem = obj; args.Handled = true; break; } } } base.OnKeyPress(args); } } }
28 juin 2010 à 09:51
merci d'avance
15 mai 2003 à 12:12
15 mai 2003 à 09:02
votreComboBox.DataSource = (new InstalledFontCollection()).Families;
votreComboBox.DisplayMember = "Name";
Les objets Items que vous récupérez dans la Combo sont alors directement les objets Font.
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.