> Est ce possible ?
comment ?
des idées ??
> Est ce possible ?
comment ?
des idées ??
> Est ce possible ?
comment ?
des idées ??
> Est ce possible ?
> comment ?
> des idées ??
En voici une simple, mais il peut y avoir plusieurs façon de procéder :
'***
Public Class Form1
Inherits System.Windows.Forms.Form
Private m_motsCles As Hashtable
#Region " Code généré par le Concepteur Windows Form "
Public Sub New()
MyBase.New()
'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
'Ajoutez une initialisation quelconque après l'appel
InitializeComponent()
End Sub
'La méthode substituée Dispose du formulaire pour nettoyer la liste des
composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer
'REMARQUE : la procédure suivante est requise par le Concepteur Windows
Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'RichTextBox1
'
Me.RichTextBox1.Location = New System.Drawing.Point(8, 8)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.Size = New System.Drawing.Size(416, 256)
Me.RichTextBox1.TabIndex = 0
Me.RichTextBox1.Text = "RichTextBox1 test Test RichTextBox"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(352, 272)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(72, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(432, 302)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.RichTextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' pour les besoins de l'exemple, j'ai employé une Hashtable
hard-codée,
' il est évidemment préférable de conserver la liste de mots en
dehors du programme (table de pilotage, .config, autre fichiers..)
' afin de permettre la modification de celle-ci sans devoir modifié
le code.
m_motsCles = New Hashtable(3)
m_motsCles.Add("SELECT", Color.Blue)
m_motsCles.Add("FROM", Color.Red)
m_motsCles.Add("WHERE", Color.Green)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RichTextBox1.SuspendLayout()
For Each entry As DictionaryEntry In m_motsCles
ChangeWordColorRecusively(RichTextBox1, entry.Key, entry.Value,
0)
Next
RichTextBox1.ResumeLayout()
End Sub
Private Sub ChangeWordColorRecusively(ByVal rtb As RichTextBox, ByVal
keyword As String, ByVal keywordColor As Color, ByVal startIndex As Int32)
Dim keywordPosition As Int32 = rtb.Find(keyword, startIndex,
RichTextBoxFinds.WholeWord)
If (keywordPosition > -1) Then
rtb.Select(keywordPosition, keyword.Length)
rtb.SelectionColor = keywordColor
ChangeWordColorRecusively(rtb, keyword, keywordColor,
keywordPosition + keyword.Length)
End If
End Sub
End Class
'***
En espérant que ça t'inspires.. :O)
--
Cordialement
Yanick
MVP pour Visual Basic
> Est ce possible ?
> comment ?
> des idées ??
En voici une simple, mais il peut y avoir plusieurs façon de procéder :
'***
Public Class Form1
Inherits System.Windows.Forms.Form
Private m_motsCles As Hashtable
#Region " Code généré par le Concepteur Windows Form "
Public Sub New()
MyBase.New()
'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
'Ajoutez une initialisation quelconque après l'appel
InitializeComponent()
End Sub
'La méthode substituée Dispose du formulaire pour nettoyer la liste des
composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer
'REMARQUE : la procédure suivante est requise par le Concepteur Windows
Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'RichTextBox1
'
Me.RichTextBox1.Location = New System.Drawing.Point(8, 8)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.Size = New System.Drawing.Size(416, 256)
Me.RichTextBox1.TabIndex = 0
Me.RichTextBox1.Text = "RichTextBox1 test Test RichTextBox"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(352, 272)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(72, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(432, 302)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.RichTextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' pour les besoins de l'exemple, j'ai employé une Hashtable
hard-codée,
' il est évidemment préférable de conserver la liste de mots en
dehors du programme (table de pilotage, .config, autre fichiers..)
' afin de permettre la modification de celle-ci sans devoir modifié
le code.
m_motsCles = New Hashtable(3)
m_motsCles.Add("SELECT", Color.Blue)
m_motsCles.Add("FROM", Color.Red)
m_motsCles.Add("WHERE", Color.Green)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RichTextBox1.SuspendLayout()
For Each entry As DictionaryEntry In m_motsCles
ChangeWordColorRecusively(RichTextBox1, entry.Key, entry.Value,
0)
Next
RichTextBox1.ResumeLayout()
End Sub
Private Sub ChangeWordColorRecusively(ByVal rtb As RichTextBox, ByVal
keyword As String, ByVal keywordColor As Color, ByVal startIndex As Int32)
Dim keywordPosition As Int32 = rtb.Find(keyword, startIndex,
RichTextBoxFinds.WholeWord)
If (keywordPosition > -1) Then
rtb.Select(keywordPosition, keyword.Length)
rtb.SelectionColor = keywordColor
ChangeWordColorRecusively(rtb, keyword, keywordColor,
keywordPosition + keyword.Length)
End If
End Sub
End Class
'***
En espérant que ça t'inspires.. :O)
--
Cordialement
Yanick
MVP pour Visual Basic
> Est ce possible ?
> comment ?
> des idées ??
En voici une simple, mais il peut y avoir plusieurs façon de procéder :
'***
Public Class Form1
Inherits System.Windows.Forms.Form
Private m_motsCles As Hashtable
#Region " Code généré par le Concepteur Windows Form "
Public Sub New()
MyBase.New()
'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
'Ajoutez une initialisation quelconque après l'appel
InitializeComponent()
End Sub
'La méthode substituée Dispose du formulaire pour nettoyer la liste des
composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer
'REMARQUE : la procédure suivante est requise par le Concepteur Windows
Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'RichTextBox1
'
Me.RichTextBox1.Location = New System.Drawing.Point(8, 8)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.Size = New System.Drawing.Size(416, 256)
Me.RichTextBox1.TabIndex = 0
Me.RichTextBox1.Text = "RichTextBox1 test Test RichTextBox"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(352, 272)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(72, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(432, 302)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.RichTextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' pour les besoins de l'exemple, j'ai employé une Hashtable
hard-codée,
' il est évidemment préférable de conserver la liste de mots en
dehors du programme (table de pilotage, .config, autre fichiers..)
' afin de permettre la modification de celle-ci sans devoir modifié
le code.
m_motsCles = New Hashtable(3)
m_motsCles.Add("SELECT", Color.Blue)
m_motsCles.Add("FROM", Color.Red)
m_motsCles.Add("WHERE", Color.Green)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RichTextBox1.SuspendLayout()
For Each entry As DictionaryEntry In m_motsCles
ChangeWordColorRecusively(RichTextBox1, entry.Key, entry.Value,
0)
Next
RichTextBox1.ResumeLayout()
End Sub
Private Sub ChangeWordColorRecusively(ByVal rtb As RichTextBox, ByVal
keyword As String, ByVal keywordColor As Color, ByVal startIndex As Int32)
Dim keywordPosition As Int32 = rtb.Find(keyword, startIndex,
RichTextBoxFinds.WholeWord)
If (keywordPosition > -1) Then
rtb.Select(keywordPosition, keyword.Length)
rtb.SelectionColor = keywordColor
ChangeWordColorRecusively(rtb, keyword, keywordColor,
keywordPosition + keyword.Length)
End If
End Sub
End Class
'***
En espérant que ça t'inspires.. :O)
--
Cordialement
Yanick
MVP pour Visual Basic
> Est ce possible ?
> comment ?
> des idées ??
En voici une simple, mais il peut y avoir plusieurs façon de procéder :
'***
Public Class Form1
Inherits System.Windows.Forms.Form
Private m_motsCles As Hashtable
#Region " Code généré par le Concepteur Windows Form "
Public Sub New()
MyBase.New()
'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
'Ajoutez une initialisation quelconque après l'appel
InitializeComponent()
End Sub
'La méthode substituée Dispose du formulaire pour nettoyer la liste des
composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer
'REMARQUE : la procédure suivante est requise par le Concepteur Windows
Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'RichTextBox1
'
Me.RichTextBox1.Location = New System.Drawing.Point(8, 8)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.Size = New System.Drawing.Size(416, 256)
Me.RichTextBox1.TabIndex = 0
Me.RichTextBox1.Text = "RichTextBox1 test Test RichTextBox"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(352, 272)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(72, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(432, 302)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.RichTextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' pour les besoins de l'exemple, j'ai employé une Hashtable
hard-codée,
' il est évidemment préférable de conserver la liste de mots en
dehors du programme (table de pilotage, .config, autre fichiers..)
' afin de permettre la modification de celle-ci sans devoir modifié
le code.
m_motsCles = New Hashtable(3)
m_motsCles.Add("SELECT", Color.Blue)
m_motsCles.Add("FROM", Color.Red)
m_motsCles.Add("WHERE", Color.Green)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RichTextBox1.SuspendLayout()
For Each entry As DictionaryEntry In m_motsCles
ChangeWordColorRecusively(RichTextBox1, entry.Key, entry.Value,
0)
Next
RichTextBox1.ResumeLayout()
End Sub
Private Sub ChangeWordColorRecusively(ByVal rtb As RichTextBox, ByVal
keyword As String, ByVal keywordColor As Color, ByVal startIndex As Int32)
Dim keywordPosition As Int32 = rtb.Find(keyword, startIndex,
RichTextBoxFinds.WholeWord)
If (keywordPosition > -1) Then
rtb.Select(keywordPosition, keyword.Length)
rtb.SelectionColor = keywordColor
ChangeWordColorRecusively(rtb, keyword, keywordColor,
keywordPosition + keyword.Length)
End If
End Sub
End Class
'***
En espérant que ça t'inspires.. :O)
--
Cordialement
Yanick
MVP pour Visual Basic
> Est ce possible ?
> comment ?
> des idées ??
En voici une simple, mais il peut y avoir plusieurs façon de procéder :
'***
Public Class Form1
Inherits System.Windows.Forms.Form
Private m_motsCles As Hashtable
#Region " Code généré par le Concepteur Windows Form "
Public Sub New()
MyBase.New()
'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
'Ajoutez une initialisation quelconque après l'appel
InitializeComponent()
End Sub
'La méthode substituée Dispose du formulaire pour nettoyer la liste des
composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer
'REMARQUE : la procédure suivante est requise par le Concepteur Windows
Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'RichTextBox1
'
Me.RichTextBox1.Location = New System.Drawing.Point(8, 8)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.Size = New System.Drawing.Size(416, 256)
Me.RichTextBox1.TabIndex = 0
Me.RichTextBox1.Text = "RichTextBox1 test Test RichTextBox"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(352, 272)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(72, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(432, 302)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.RichTextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' pour les besoins de l'exemple, j'ai employé une Hashtable
hard-codée,
' il est évidemment préférable de conserver la liste de mots en
dehors du programme (table de pilotage, .config, autre fichiers..)
' afin de permettre la modification de celle-ci sans devoir modifié
le code.
m_motsCles = New Hashtable(3)
m_motsCles.Add("SELECT", Color.Blue)
m_motsCles.Add("FROM", Color.Red)
m_motsCles.Add("WHERE", Color.Green)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RichTextBox1.SuspendLayout()
For Each entry As DictionaryEntry In m_motsCles
ChangeWordColorRecusively(RichTextBox1, entry.Key, entry.Value,
0)
Next
RichTextBox1.ResumeLayout()
End Sub
Private Sub ChangeWordColorRecusively(ByVal rtb As RichTextBox, ByVal
keyword As String, ByVal keywordColor As Color, ByVal startIndex As Int32)
Dim keywordPosition As Int32 = rtb.Find(keyword, startIndex,
RichTextBoxFinds.WholeWord)
If (keywordPosition > -1) Then
rtb.Select(keywordPosition, keyword.Length)
rtb.SelectionColor = keywordColor
ChangeWordColorRecusively(rtb, keyword, keywordColor,
keywordPosition + keyword.Length)
End If
End Sub
End Class
'***
En espérant que ça t'inspires.. :O)
--
Cordialement
Yanick
MVP pour Visual Basic
> Est ce possible ?
> comment ?
> des idées ??
En voici une simple, mais il peut y avoir plusieurs façon de procéder :
'***
Public Class Form1
Inherits System.Windows.Forms.Form
Private m_motsCles As Hashtable
#Region " Code généré par le Concepteur Windows Form "
Public Sub New()
MyBase.New()
'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
'Ajoutez une initialisation quelconque après l'appel
InitializeComponent()
End Sub
'La méthode substituée Dispose du formulaire pour nettoyer la liste des
composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer
'REMARQUE : la procédure suivante est requise par le Concepteur Windows
Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'RichTextBox1
'
Me.RichTextBox1.Location = New System.Drawing.Point(8, 8)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.Size = New System.Drawing.Size(416, 256)
Me.RichTextBox1.TabIndex = 0
Me.RichTextBox1.Text = "RichTextBox1 test Test RichTextBox"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(352, 272)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(72, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(432, 302)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.RichTextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' pour les besoins de l'exemple, j'ai employé une Hashtable
hard-codée,
' il est évidemment préférable de conserver la liste de mots en
dehors du programme (table de pilotage, .config, autre fichiers..)
' afin de permettre la modification de celle-ci sans devoir modifié
le code.
m_motsCles = New Hashtable(3)
m_motsCles.Add("SELECT", Color.Blue)
m_motsCles.Add("FROM", Color.Red)
m_motsCles.Add("WHERE", Color.Green)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RichTextBox1.SuspendLayout()
For Each entry As DictionaryEntry In m_motsCles
ChangeWordColorRecusively(RichTextBox1, entry.Key, entry.Value,
0)
Next
RichTextBox1.ResumeLayout()
End Sub
Private Sub ChangeWordColorRecusively(ByVal rtb As RichTextBox, ByVal
keyword As String, ByVal keywordColor As Color, ByVal startIndex As Int32)
Dim keywordPosition As Int32 = rtb.Find(keyword, startIndex,
RichTextBoxFinds.WholeWord)
If (keywordPosition > -1) Then
rtb.Select(keywordPosition, keyword.Length)
rtb.SelectionColor = keywordColor
ChangeWordColorRecusively(rtb, keyword, keywordColor,
keywordPosition + keyword.Length)
End If
End Sub
End Class
'***
En espérant que ça t'inspires.. :O)
--
Cordialement
Yanick
MVP pour Visual Basic
juste une dernière question : avec le bouton ça marche nickel !! k'ai fait
un
évenement sur keypress et je teste sur l'espace (pourchanger la couleur)
Private Sub RichTextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles RichTextBox1.KeyPress
Select Case e.KeyChar
Case " "
RichTextBox1.SuspendLayout()
For Each entry As DictionaryEntry In m_motsCles
ChangeWordColorRecusively(RichTextBox1, entry.Key, entry.Value,
0)
Next
RichTextBox1.ResumeLayout()
End Select
mais il n'arrive pas à sortir de la récursivité dans
ChangeWordColorRecusively !!
bref, si vous voyez rapidement le problème, sinon j'y passerais le temps
nécessaire !!
En tout cas merci !!
"Zoury" a écrit :> Est ce possible ?
> comment ?
> des idées ??
En voici une simple, mais il peut y avoir plusieurs façon de procéder :
'***
Public Class Form1
Inherits System.Windows.Forms.Form
Private m_motsCles As Hashtable
#Region " Code généré par le Concepteur Windows Form "
Public Sub New()
MyBase.New()
'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
'Ajoutez une initialisation quelconque après l'appel
InitializeComponent()
End Sub
'La méthode substituée Dispose du formulaire pour nettoyer la liste
des
composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer
'REMARQUE : la procédure suivante est requise par le Concepteur
Windows
Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'RichTextBox1
'
Me.RichTextBox1.Location = New System.Drawing.Point(8, 8)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.Size = New System.Drawing.Size(416, 256)
Me.RichTextBox1.TabIndex = 0
Me.RichTextBox1.Text = "RichTextBox1 test Test RichTextBox"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(352, 272)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(72, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(432, 302)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.RichTextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' pour les besoins de l'exemple, j'ai employé une Hashtable
hard-codée,
' il est évidemment préférable de conserver la liste de mots en
dehors du programme (table de pilotage, .config, autre fichiers..)
' afin de permettre la modification de celle-ci sans devoir
modifié
le code.
m_motsCles = New Hashtable(3)
m_motsCles.Add("SELECT", Color.Blue)
m_motsCles.Add("FROM", Color.Red)
m_motsCles.Add("WHERE", Color.Green)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RichTextBox1.SuspendLayout()
For Each entry As DictionaryEntry In m_motsCles
ChangeWordColorRecusively(RichTextBox1, entry.Key,
entry.Value,
0)
Next
RichTextBox1.ResumeLayout()
End Sub
Private Sub ChangeWordColorRecusively(ByVal rtb As RichTextBox, ByVal
keyword As String, ByVal keywordColor As Color, ByVal startIndex As
Int32)
Dim keywordPosition As Int32 = rtb.Find(keyword, startIndex,
RichTextBoxFinds.WholeWord)
If (keywordPosition > -1) Then
rtb.Select(keywordPosition, keyword.Length)
rtb.SelectionColor = keywordColor
ChangeWordColorRecusively(rtb, keyword, keywordColor,
keywordPosition + keyword.Length)
End If
End Sub
End Class
'***
En espérant que ça t'inspires.. :O)
--
Cordialement
Yanick
MVP pour Visual Basic
juste une dernière question : avec le bouton ça marche nickel !! k'ai fait
un
évenement sur keypress et je teste sur l'espace (pourchanger la couleur)
Private Sub RichTextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles RichTextBox1.KeyPress
Select Case e.KeyChar
Case " "
RichTextBox1.SuspendLayout()
For Each entry As DictionaryEntry In m_motsCles
ChangeWordColorRecusively(RichTextBox1, entry.Key, entry.Value,
0)
Next
RichTextBox1.ResumeLayout()
End Select
mais il n'arrive pas à sortir de la récursivité dans
ChangeWordColorRecusively !!
bref, si vous voyez rapidement le problème, sinon j'y passerais le temps
nécessaire !!
En tout cas merci !!
"Zoury" a écrit :
> Est ce possible ?
> comment ?
> des idées ??
En voici une simple, mais il peut y avoir plusieurs façon de procéder :
'***
Public Class Form1
Inherits System.Windows.Forms.Form
Private m_motsCles As Hashtable
#Region " Code généré par le Concepteur Windows Form "
Public Sub New()
MyBase.New()
'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
'Ajoutez une initialisation quelconque après l'appel
InitializeComponent()
End Sub
'La méthode substituée Dispose du formulaire pour nettoyer la liste
des
composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer
'REMARQUE : la procédure suivante est requise par le Concepteur
Windows
Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'RichTextBox1
'
Me.RichTextBox1.Location = New System.Drawing.Point(8, 8)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.Size = New System.Drawing.Size(416, 256)
Me.RichTextBox1.TabIndex = 0
Me.RichTextBox1.Text = "RichTextBox1 test Test RichTextBox"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(352, 272)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(72, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(432, 302)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.RichTextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' pour les besoins de l'exemple, j'ai employé une Hashtable
hard-codée,
' il est évidemment préférable de conserver la liste de mots en
dehors du programme (table de pilotage, .config, autre fichiers..)
' afin de permettre la modification de celle-ci sans devoir
modifié
le code.
m_motsCles = New Hashtable(3)
m_motsCles.Add("SELECT", Color.Blue)
m_motsCles.Add("FROM", Color.Red)
m_motsCles.Add("WHERE", Color.Green)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RichTextBox1.SuspendLayout()
For Each entry As DictionaryEntry In m_motsCles
ChangeWordColorRecusively(RichTextBox1, entry.Key,
entry.Value,
0)
Next
RichTextBox1.ResumeLayout()
End Sub
Private Sub ChangeWordColorRecusively(ByVal rtb As RichTextBox, ByVal
keyword As String, ByVal keywordColor As Color, ByVal startIndex As
Int32)
Dim keywordPosition As Int32 = rtb.Find(keyword, startIndex,
RichTextBoxFinds.WholeWord)
If (keywordPosition > -1) Then
rtb.Select(keywordPosition, keyword.Length)
rtb.SelectionColor = keywordColor
ChangeWordColorRecusively(rtb, keyword, keywordColor,
keywordPosition + keyword.Length)
End If
End Sub
End Class
'***
En espérant que ça t'inspires.. :O)
--
Cordialement
Yanick
MVP pour Visual Basic
juste une dernière question : avec le bouton ça marche nickel !! k'ai fait
un
évenement sur keypress et je teste sur l'espace (pourchanger la couleur)
Private Sub RichTextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles RichTextBox1.KeyPress
Select Case e.KeyChar
Case " "
RichTextBox1.SuspendLayout()
For Each entry As DictionaryEntry In m_motsCles
ChangeWordColorRecusively(RichTextBox1, entry.Key, entry.Value,
0)
Next
RichTextBox1.ResumeLayout()
End Select
mais il n'arrive pas à sortir de la récursivité dans
ChangeWordColorRecusively !!
bref, si vous voyez rapidement le problème, sinon j'y passerais le temps
nécessaire !!
En tout cas merci !!
"Zoury" a écrit :> Est ce possible ?
> comment ?
> des idées ??
En voici une simple, mais il peut y avoir plusieurs façon de procéder :
'***
Public Class Form1
Inherits System.Windows.Forms.Form
Private m_motsCles As Hashtable
#Region " Code généré par le Concepteur Windows Form "
Public Sub New()
MyBase.New()
'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
'Ajoutez une initialisation quelconque après l'appel
InitializeComponent()
End Sub
'La méthode substituée Dispose du formulaire pour nettoyer la liste
des
composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer
'REMARQUE : la procédure suivante est requise par le Concepteur
Windows
Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'RichTextBox1
'
Me.RichTextBox1.Location = New System.Drawing.Point(8, 8)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.Size = New System.Drawing.Size(416, 256)
Me.RichTextBox1.TabIndex = 0
Me.RichTextBox1.Text = "RichTextBox1 test Test RichTextBox"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(352, 272)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(72, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(432, 302)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.RichTextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' pour les besoins de l'exemple, j'ai employé une Hashtable
hard-codée,
' il est évidemment préférable de conserver la liste de mots en
dehors du programme (table de pilotage, .config, autre fichiers..)
' afin de permettre la modification de celle-ci sans devoir
modifié
le code.
m_motsCles = New Hashtable(3)
m_motsCles.Add("SELECT", Color.Blue)
m_motsCles.Add("FROM", Color.Red)
m_motsCles.Add("WHERE", Color.Green)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RichTextBox1.SuspendLayout()
For Each entry As DictionaryEntry In m_motsCles
ChangeWordColorRecusively(RichTextBox1, entry.Key,
entry.Value,
0)
Next
RichTextBox1.ResumeLayout()
End Sub
Private Sub ChangeWordColorRecusively(ByVal rtb As RichTextBox, ByVal
keyword As String, ByVal keywordColor As Color, ByVal startIndex As
Int32)
Dim keywordPosition As Int32 = rtb.Find(keyword, startIndex,
RichTextBoxFinds.WholeWord)
If (keywordPosition > -1) Then
rtb.Select(keywordPosition, keyword.Length)
rtb.SelectionColor = keywordColor
ChangeWordColorRecusively(rtb, keyword, keywordColor,
keywordPosition + keyword.Length)
End If
End Sub
End Class
'***
En espérant que ça t'inspires.. :O)
--
Cordialement
Yanick
MVP pour Visual Basic
> personnellement j'avais utilisé l'event texte_changed pour modifier en
temps réel les couleurs de texte.
Mais c'est une usine à gaz ...
J'ai testé le code de Zouru qui chez moi, plante pour explosion de la pile
^^
> personnellement j'avais utilisé l'event texte_changed pour modifier en
temps réel les couleurs de texte.
Mais c'est une usine à gaz ...
J'ai testé le code de Zouru qui chez moi, plante pour explosion de la pile
^^
> personnellement j'avais utilisé l'event texte_changed pour modifier en
temps réel les couleurs de texte.
Mais c'est une usine à gaz ...
J'ai testé le code de Zouru qui chez moi, plante pour explosion de la pile
^^