Make font Bold

T

trevor.niemack

I have just done an application that will allow you to insert XML into
a text box then do an xpath query to return the values against the
node. I am just a beginner so for me this is really cool but I want to
be able to get the nodes that returned information to be highlighted.
This is an example of my code at current:
Imports System.Xml

Public Class Form1
Dim used As Boolean
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim xmlstring As String = TextBox1.Text
'"<root><item>Trevor</item><item>Niemack</item><item>27 years
old</item><item>Married</item><item>Employed</item></root>"
Dim doc As New XmlDocument
doc.LoadXml(xmlstring)
Dim node As XmlNode

If used = True Then
used = False
End If
For Each node In doc.SelectNodes(TextBox3.Text)
ListBox1.Items.Add(node.InnerText)
used = True
Next

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
ListBox1.Items.Clear()
used = False
End Sub
End Class
 
C

Cerebrus

Hi Trevor,

You'll need to use a RichTextBox control if you want to show the
returned nodes in Bold. A simple TextBox won't do. You can drag it onto
your form from the Toolbox.

HTH,

Regards,

Cerebrus.
 
T

trevor.niemack

Thank you for the suggestion but now that I have inserted the
richtextbox I still am not sure of how to only bold selected nodes.
 
C

Cerebrus

I'm sorry, I assumed you would have worked out that logic... Never
mind, here is one possible way :

1. You'll have to search for that particular word in the Text of the
RichTextBox(RTB), using the IndexOf method.
When you do find it, store the index position :

Dim idx as integer = RTB.Text.IndexOf(wordToFind, 0)

2. Select that particular word.

RTB.Select(idx, wordToFind.Length)

3. Make changes to it's Font :

RTB.SelectionFont = New Font(RTB.Font, FontStyle.Underline)

I guess that should do it. I've typed it here itself, so please watch
for syntax.

Regards,

Cerebrus.
 
P

Peter Proost

Hi have a look at the SelectionFont property of the richtextbox that should
do what you want

Greetz Peter
 
P

Peter Proost

I can now see that my post was a bit late and Cerebrus already answered, but
that's because I forget to press F5 before posting :)

Greetz Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top