Combobox Police et Taille dans un Richtextbox vb

Résolu
Gabilach Messages postés 200 Date d'inscription mercredi 2 mars 2011 Statut Membre Dernière intervention 28 septembre 2014 - 15 août 2011 à 19:55
Gabilach Messages postés 200 Date d'inscription mercredi 2 mars 2011 Statut Membre Dernière intervention 28 septembre 2014 - 18 août 2011 à 16:25
Bonjour, cela fait longtemps que je cherche à faire 2 combobox :
- Le 1er (combobox1) pour la police de mon richtextbox.
- Le 2ème (combobox2) pour la taille dans mon richtextbox encore.
Concernant la police j'ai le code pour récuperer toutes les polices installer dans le system, j'ai aussi récuperer un code permettant de modifier la police mais sur certaines polices j'ai une erreur : La police 'xxxxx' ne prend pas en charge le style 'Regular'

Le code pour changer la police est :

Dim ComboFonts As System.Drawing.Font
        ComboFonts = RichTextBox1.SelectionFont
        RichTextBox1.SelectionFont = New System.Drawing.Font(ComboBox1.Text, RichTextBox1.SelectionFont.Size, RichTextBox1.SelectionFont.Style)


Merci d'avance

Gabilach...

25 réponses

Utilisateur anonyme
17 août 2011 à 16:41
Dans ce cas, il te suffit de n'ajouter dans ta ComboBox que les polices qui peuvent être "regular" :
Dim fonts As New InstalledFontCollection
Dim font_f() As FontFamily = fonts.Families()
For Each ft As FontFamily In font_f
    If ft.IsStyleAvailable(FontStyle.Regular) Then
         ComboBox1.Items.Add(ft.Name)
    End If
Next

Bonne soirée.
3
Gabilach Messages postés 200 Date d'inscription mercredi 2 mars 2011 Statut Membre Dernière intervention 28 septembre 2014
17 août 2011 à 17:41
Ta technique marche Banana :-) le code finale est :

Dans form load :
Dim fonts As New InstalledFontCollection
        Dim font_f() As FontFamily = fonts.Families()
        For Each ft As FontFamily In font_f
            If ft.IsStyleAvailable(FontStyle.Regular) Then
                ComboBox1.Items.Add(ft.Name)
            End If
        Next


Dans combobox :
Dim ComboFonts As System.Drawing.Font
        ComboFonts = RichTextBox1.SelectionFont
        RichTextBox1.SelectionFont = New System.Drawing.Font(ComboBox1.Text, RichTextBox1.SelectionFont.Size, RichTextBox1.SelectionFont.Style)


Donc Merci à vous !!! :D Euh sinon je cherchais aussi à appliquer la taille se trouvant également dans un combobox (combobox2)

Merci

Gabilach...
3
Utilisateur anonyme
17 août 2011 à 18:22
Fabrique une combobox2 (à ce sujet, prend l'habitude de nommer tes contrôles genre cmbTaillePolice) puis remplace RichTextBox1.SelectionFont.Size par convert.toint32(Combobox2.text)
Bonne prog.
3
Gabilach Messages postés 200 Date d'inscription mercredi 2 mars 2011 Statut Membre Dernière intervention 28 septembre 2014
17 août 2011 à 21:38
Tous marche à merveille je vous remercie beaucoup !!!

Code Finale pour la police :

Dim ComboFonts As System.Drawing.Font
        ComboFonts = RichTextBox1.SelectionFont
        RichTextBox1.SelectionFont = New System.Drawing.Font(ComboBox1.Text, Convert.ToInt32(ComboBox2.Text), RichTextBox1.SelectionFont.Style)



Gabilach...
3

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Utilisateur anonyme
15 août 2011 à 20:28
Tu dois tester si le style existe :
   Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim mafont = New Font(ComboBox1.Text, RichTextBox1.SelectionFont.Size, GraphicsUnit.Pixel)
        Dim mafontf As FontFamily = mafont.FontFamily
        If mafontf.IsStyleAvailable(FontStyle.Regular) Then
            RichTextBox1.SelectionFont = New Font(mafont, FontStyle.Regular)
        End If
    End Sub
0
Gabilach Messages postés 200 Date d'inscription mercredi 2 mars 2011 Statut Membre Dernière intervention 28 septembre 2014
15 août 2011 à 20:52
J'ai malheuresement toujours la même erreur me disant : La police 'xxxxx' ne prend pas en charge le style 'Regular'

Je m'embrouille

Gabilach...
0
Utilisateur anonyme
16 août 2011 à 14:05
Re,
Es-tu sûr d'avoir placé le code au bon endroit ?
Voir le code en entier pourrait servir à te dépanner.
Bonne prog.
0
Utilisateur anonyme
16 août 2011 à 14:17
Salut Gabi
as tu essayé le FontDialog?
ça me parait plus adapté.

A+


CF2i - Guadeloupe
Ingénierie Informatique
0
Gabilach Messages postés 200 Date d'inscription mercredi 2 mars 2011 Statut Membre Dernière intervention 28 septembre 2014
16 août 2011 à 14:53
Banana32 j'ai bien mis le code au bonne endroit pourtant :

Acive : j'ai déjà un Fontdialog mais ce n'est pas asser rapide à mon goût ! Merci quand même

Sinon je cherche aussi comment faire un combobox ( combobox2 ) pour la taille.
Gabilach...
0
Utilisateur anonyme
16 août 2011 à 14:58
Re:
Tu compliques un peu et je ne suis pas sur que ce soit plus rapide...


CF2i - Guadeloupe
Ingénierie Informatique
0
Gabilach Messages postés 200 Date d'inscription mercredi 2 mars 2011 Statut Membre Dernière intervention 28 septembre 2014
16 août 2011 à 15:04
Bah je prefère quand même passer par les combobox

Gabilach...
0
Utilisateur anonyme
16 août 2011 à 16:42
Re:
Testé, fonctionne sous vb2010...
Mets dans une Form 4 combobox, un textbox et tu fais un copier/coller de ça:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("Jaune")
ComboBox1.Items.Add("Rouge")
ComboBox1.Items.Add("Bleu")
ComboBox1.Items.Add("Noir")
ComboBox1.Text = ComboBox1.Items.Item(1)

ComboBox2.Items.Add("Arial")
ComboBox2.Items.Add("Times New Roman")
ComboBox2.Items.Add("Microsoft Sans Serif")
ComboBox2.Text = ComboBox2.Items.Item(1)

ComboBox3.Items.Add("10")
ComboBox3.Items.Add("12")
ComboBox3.Items.Add("16")
ComboBox3.Items.Add("18")
ComboBox3.Text = ComboBox3.Items.Item(1)

ComboBox4.Items.Add("Italic")
ComboBox4.Items.Add("Bold")
ComboBox4.Items.Add("Regular")
ComboBox4.Text = ComboBox4.Items.Item(2)

TextBox1.Text = "Mon texte..."

End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Select Case ComboBox1.SelectedIndex
Case 0
TextBox1.ForeColor = System.Drawing.Color.Yellow
Case 1
TextBox1.ForeColor = System.Drawing.Color.Red
Case 2
TextBox1.ForeColor = System.Drawing.Color.Blue
Case 3
TextBox1.ForeColor = System.Drawing.Color.Black
End Select
End Sub

Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
TextBox1.Font = New Font(ComboBox2.Items.Item(ComboBox2.SelectedIndex).ToString, TextBox1.Font.Size, TextBox1.Font.Style)
End Sub

Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
If ComboBox4.Text "Bold" Then TextBox1.Font New System.Drawing.Font("", (Int(ComboBox3.Text)), Drawing.FontStyle.Bold)
If ComboBox4.Text "Italic" Then TextBox1.Font New System.Drawing.Font("", (Int(ComboBox3.Text)), Drawing.FontStyle.Italic)
If ComboBox4.Text "Regular" Then TextBox1.Font New System.Drawing.Font("", (Int(ComboBox3.Text)), Drawing.FontStyle.Regular)
End Sub

Private Sub ComboBox4_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox4.SelectedIndexChanged
If ComboBox4.Text "Regular" Then TextBox1.Font New System.Drawing.Font("", (Int(ComboBox3.Text)), Drawing.FontStyle.Regular)
If ComboBox4.Text "Italic" Then TextBox1.Font New System.Drawing.Font("", (Int(ComboBox3.Text)), Drawing.FontStyle.Italic)
If ComboBox4.Text "Bold" Then TextBox1.Font New System.Drawing.Font("", (Int(ComboBox3.Text)), Drawing.FontStyle.Bold)
End Sub


CF2i - Guadeloupe
Ingénierie Informatique
0
Gabilach Messages postés 200 Date d'inscription mercredi 2 mars 2011 Statut Membre Dernière intervention 28 septembre 2014
16 août 2011 à 17:35
La taille de police ne marche pas, et la police nonplus car à l'ouverture de la form je relève toutes les polices installé :

Dim fonts As New InstalledFontCollection
        Dim font_f() As FontFamily = fonts.Families()
        For Each ft As FontFamily In font_f
            ComboBox1.Items.Add(ft.Name)
        Next


Merci quand même... je pense que personne ne trouvera la bonne solution


Gabilach...
0
Utilisateur anonyme
16 août 2011 à 17:39
Écoute j'ai VB2010 et ça fonctionne normalement (ce que je viens de faire)...
Envoie ton code on va voir...



CF2i - Guadeloupe
Ingénierie Informatique
0
Gabilach Messages postés 200 Date d'inscription mercredi 2 mars 2011 Statut Membre Dernière intervention 28 septembre 2014
16 août 2011 à 21:50
Je ne veut pas modifiée le style de la police mais la taille si tu n'a pas compris et j'ai une erreur 249 en rentrant le code pour la police.


Gabilach...
0
Utilisateur anonyme
16 août 2011 à 22:06
J'ai demandé à voir le code complet...
Mais rien ne vient
0
Gabilach Messages postés 200 Date d'inscription mercredi 2 mars 2011 Statut Membre Dernière intervention 28 septembre 2014
17 août 2011 à 00:49
Excuse moi ^^' :

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim fonts As New InstalledFontCollection
        Dim font_f() As FontFamily = fonts.Families()
        For Each ft As FontFamily In font_f
            ComboBox1.Items.Add(ft.Name)
        Next
End Sub


Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim mafont = New Font(ComboBox1.Text, RichTextBox1.SelectionFont.Size, GraphicsUnit.Pixel)
        Dim mafontf As FontFamily = mafont.FontFamily
        If mafontf.IsStyleAvailable(FontStyle.Regular) Then
            RichTextBox1.SelectionFont = New Font(mafont, FontStyle.Regular)
        End If
    End Sub


Te faut quelque chose d'autre ?



Gabilach...
0
Utilisateur anonyme
17 août 2011 à 14:45
Et ton erreur apparaît sur toutes les polices ou seulement sur une partie ?
Quel est le texte de l'exception levée ? (on ne peut pas la lire sur l'image que tu as mis tantôt)
0
Gabilach Messages postés 200 Date d'inscription mercredi 2 mars 2011 Statut Membre Dernière intervention 28 septembre 2014
17 août 2011 à 16:14
Mon erreur apparait sur certaines polices seulement, l'exception est ArgumentEception :

L'exception System.ArgumentException n'a pas été gérée
  Message=La police 'Vivaldi' ne prend pas en charge le style 'Regular'.
  Source=System.Drawing
  StackTrace:
       à System.Drawing.Font.CreateNativeFont()
       à System.Drawing.Font.Initialize(FontFamily family, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
       à System.Drawing.Font.Initialize(String familyName, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
       à System.Drawing.Font..ctor(String familyName, Single emSize, GraphicsUnit unit)
       à WordGL.Form1.ComboBox1_SelectedIndexChanged(Object sender, EventArgs e) dans G:\WordGL\WordGL\Form1.vb:ligne 983
       à System.Windows.Forms.ComboBox.OnSelectedIndexChanged(EventArgs e)
       à System.Windows.Forms.ComboBox.WmReflectCommand(Message& m)
       à System.Windows.Forms.ComboBox.WndProc(Message& m)
       à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       à System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       à System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
       à System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)
       à System.Windows.Forms.Control.WmCommand(Message& m)
       à System.Windows.Forms.Control.WndProc(Message& m)
       à System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       à System.Windows.Forms.Form.WndProc(Message& m)
       à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       à System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       à System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
       à System.Windows.Forms.Control.DefWndProc(Message& m)
       à System.Windows.Forms.Control.WmCommand(Message& m)
       à System.Windows.Forms.Control.WndProc(Message& m)
       à System.Windows.Forms.ComboBox.WndProc(Message& m)
       à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       à System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       à System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
       à System.Windows.Forms.ComboBox.DefChildWndProc(Message& m)
       à System.Windows.Forms.ComboBox.ChildWndProc(Message& m)
       à System.Windows.Forms.ComboBox.ComboBoxChildNativeWindow.WndProc(Message& m)
       à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       à Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       à WordGL.My.MyApplication.Main(String[] Args) dans 17d14f5c-a337-4978-8281-53493378c1071.vb:ligne 81
       à System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       à System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       à System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
       à System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
       à System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       à System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
       à System.Activator.CreateInstance(ActivationContext activationContext)
       à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       à System.Threading.ThreadHelper.ThreadStart()
  InnerException: 


Merci de l'aide...

Gabilach...
0
Utilisateur anonyme
17 août 2011 à 16:18
Mais c'est écrit:
La police 'Vivaldi' ne prend pas en charge le style 'Regular'.

Il faudrait mettre un filtre du genre
If Police = "Vivaldi" Then (Pas de style regular)

Non?


CF2i - Guadeloupe
Ingénierie Informatique
0
Rejoignez-nous