473,703 Members | 2,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to preserve the old font properties while changing new one?

Hi All,

How to preserve the old font properties while changing new one?
I posted same question 2 months back, but I had very small time then.

eg. "Shopping for" is a text in RichTextBox and already formatted as
"Shopping" ---Bold
"for" -----Regular

Now I want to underline whole text by preserving old style i.e. Bold and
regular.
So that I should get result as follows

"Shopping" ---Bold + Underline
"for" -----Regular + Underline

When I press on UnderLine Button whole string becomes
Regular+Underli ne

I have written following code. You can just copy and paste it and thus can
be taste it.
So please tell me where is a mistake?
I have tried lot of things, but couldn't get the result.

Thanks in advance

Regards,
Sakharam Phapale

Public Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents cmdBold As System.Windows. Forms.Button
Friend WithEvents Label1 As System.Windows. Forms.Label
Friend WithEvents rtbData As System.Windows. Forms.RichTextB ox
Friend WithEvents cmbFontSize As System.Windows. Forms.ComboBox
Friend WithEvents cmbFontFamily As System.Windows. Forms.ComboBox
Friend WithEvents cmdUnderLine As System.Windows. Forms.Button
Friend WithEvents cmdItalic As System.Windows. Forms.Button
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.rtbData = New System.Windows. Forms.RichTextB ox()
Me.cmdBold = New System.Windows. Forms.Button()
Me.Label1 = New System.Windows. Forms.Label()
Me.cmdUnderLine = New System.Windows. Forms.Button()
Me.cmdItalic = New System.Windows. Forms.Button()
Me.cmbFontSize = New System.Windows. Forms.ComboBox( )
Me.cmbFontFamil y = New System.Windows. Forms.ComboBox( )
Me.SuspendLayou t()
'
'rtbData
'
Me.rtbData.Font = New System.Drawing. Font("Times New Roman", 11.25!,
System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.rtbData.Hide Selection = False
Me.rtbData.Loca tion = New System.Drawing. Point(24, 96)
Me.rtbData.Name = "rtbData"
Me.rtbData.Size = New System.Drawing. Size(592, 248)
Me.rtbData.TabI ndex = 1
Me.rtbData.Text = "Shopping for hourly and daily parking on this
web"
'
'cmdBold
'
Me.cmdBold.Font = New System.Drawing. Font("Arial", 12.0!,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0,
Byte))
Me.cmdBold.Loca tion = New System.Drawing. Point(344, 40)
Me.cmdBold.Name = "cmdBold"
Me.cmdBold.Size = New System.Drawing. Size(24, 24)
Me.cmdBold.TabI ndex = 2
Me.cmdBold.Text = "B"
'
'Label1
'
Me.Label1.Font = New System.Drawing. Font("Times New Roman", 11.25!,
System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.Label1.Locat ion = New System.Drawing. Point(32, 41)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing. Size(80, 24)
Me.Label1.TabIn dex = 3
Me.Label1.Text = "Font Name"
'
'cmdUnderLine
'
Me.cmdUnderLine .Font = New System.Drawing. Font("Arial", 12.0!,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0,
Byte))
Me.cmdUnderLine .Location = New System.Drawing. Point(376, 40)
Me.cmdUnderLine .Name = "cmdUnderLi ne"
Me.cmdUnderLine .Size = New System.Drawing. Size(24, 24)
Me.cmdUnderLine .TabIndex = 6
Me.cmdUnderLine .Text = "U"
'
'cmdItalic
'
Me.cmdItalic.Fo nt = New System.Drawing. Font("Arial", 12.0!,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0,
Byte))
Me.cmdItalic.Lo cation = New System.Drawing. Point(408, 40)
Me.cmdItalic.Na me = "cmdItalic"
Me.cmdItalic.Si ze = New System.Drawing. Size(24, 24)
Me.cmdItalic.Ta bIndex = 7
Me.cmdItalic.Te xt = "I"
'
'cmbFontSize
'
Me.cmbFontSize. Font = New System.Drawing. Font("Times New Roman",
9.75!, System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.cmbFontSize. Items.AddRange( New Object() {"8", "9", "10", "11",
"12", "14", "16", "18", "20", "22", "24", "26", "28", "36", "48", "72"})
Me.cmbFontSize. Location = New System.Drawing. Point(272, 40)
Me.cmbFontSize. Name = "cmbFontSiz e"
Me.cmbFontSize. Size = New System.Drawing. Size(56, 23)
Me.cmbFontSize. TabIndex = 21
'
'cmbFontFamily
'
Me.cmbFontFamil y.DropDownStyle =
System.Windows. Forms.ComboBoxS tyle.DropDownLi st
Me.cmbFontFamil y.Font = New System.Drawing. Font("Times New Roman",
9.75!, System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.cmbFontFamil y.Location = New System.Drawing. Point(120, 40)
Me.cmbFontFamil y.Name = "cmbFontFam ily"
Me.cmbFontFamil y.Size = New System.Drawing. Size(152, 23)
Me.cmbFontFamil y.TabIndex = 20
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(640, 365)
Me.Controls.Add Range(New System.Windows. Forms.Control()
{Me.cmbFontSize , Me.cmbFontFamil y, Me.cmdItalic, Me.cmdUnderLine , Me.Label1,
Me.cmdBold, Me.rtbData})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
cmbFontFamily.I tems.Clear()
Dim myFontFamily() As FontFamily
Dim objFontFamily As FontFamily
myFontFamily = objFontFamily.F amilies()
Dim i As Integer
For i = 0 To myFontFamily.Ge tUpperBound(0)
cmbFontFamily.I tems.Add(myFont Family(i).Name)
Next
cmbFontFamily.S electedIndex = 0
cmbFontSize.Sel ectedIndex = 0
End Sub

'Change Font Family

Private Sub cmbFontFamily_S electedIndexCha nged(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
cmbFontFamily.S electedIndexCha nged
Try
Dim fOld As Font = rtbData.Selecti onFont
Dim fontFamily As New FontFamily(cmbF ontFamily.Text)
If fOld Is Nothing Then
Else
rtbData.Selecti onFont = New Font(fontFamily , fOld.Size)
Dim fNew As Font = rtbData.Selecti onFont
rtbData.Selecti onFont = New Font(fNew, fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
End Sub

'Change font size

Private Sub cmbFontSize_Sel ectedIndexChang ed(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
cmbFontSize.Sel ectedIndexChang ed
Try
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld.FontF amily,
CSng(cmbFontSiz e.Text), fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
End Sub

'Change Bold format

Private Sub cmdBold_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdBold.Click
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld, fOld.Style +
(IIf(fOld.Bold, FontStyle.Bold * -1, FontStyle.Bold) ))
End If
End Sub

'Change Underline format

Private Sub cmdUnderLine_Cl ick(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdUnderLine.Cl ick
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld, fOld.Style +
(IIf(fOld.Under line, FontStyle.Under line * -1, FontStyle.Under line)))
End If
End Sub

'Change Italic format

Private Sub cmdItalic_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdItalic.Click
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld, fOld.Style +
(IIf(fOld.Itali c, FontStyle.Itali c * -1, FontStyle.Itali c)))
End If
End Sub

Private Sub rtbData_Selecti onChanged(ByVal sender As Object, ByVal e As
System.EventArg s) Handles rtbData.Selecti onChanged
If rtbData.Selecti onFont Is Nothing Then Exit Sub
cmbFontFamily.T ext = rtbData.Selecti onFont.FontFami ly.Name
cmbFontSize.Tex t = rtbData.Selecti onFont.Size.ToS tring
End Sub

End Class
Nov 21 '05 #1
7 2968
Sakharam,

You told you posted it two months ago and you forgot it.

Do you know this link
http://groups.google.com/groups?hl=e...t.languages.vb

I hope this helps?

Cor

"Sakharam Phapale"
...
Hi All,

How to preserve the old font properties while changing new one?
I posted same question 2 months back, but I had very small time then.

eg. "Shopping for" is a text in RichTextBox and already formatted as
"Shopping" ---Bold
"for" -----Regular

Now I want to underline whole text by preserving old style i.e. Bold and
regular.
So that I should get result as follows

"Shopping" ---Bold + Underline
"for" -----Regular + Underline

When I press on UnderLine Button whole string becomes
Regular+Underli ne

I have written following code. You can just copy and paste it and thus can
be taste it.
So please tell me where is a mistake?
I have tried lot of things, but couldn't get the result.

Thanks in advance

Regards,
Sakharam Phapale

Public Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents cmdBold As System.Windows. Forms.Button
Friend WithEvents Label1 As System.Windows. Forms.Label
Friend WithEvents rtbData As System.Windows. Forms.RichTextB ox
Friend WithEvents cmbFontSize As System.Windows. Forms.ComboBox
Friend WithEvents cmbFontFamily As System.Windows. Forms.ComboBox
Friend WithEvents cmdUnderLine As System.Windows. Forms.Button
Friend WithEvents cmdItalic As System.Windows. Forms.Button
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.rtbData = New System.Windows. Forms.RichTextB ox()
Me.cmdBold = New System.Windows. Forms.Button()
Me.Label1 = New System.Windows. Forms.Label()
Me.cmdUnderLine = New System.Windows. Forms.Button()
Me.cmdItalic = New System.Windows. Forms.Button()
Me.cmbFontSize = New System.Windows. Forms.ComboBox( )
Me.cmbFontFamil y = New System.Windows. Forms.ComboBox( )
Me.SuspendLayou t()
'
'rtbData
'
Me.rtbData.Font = New System.Drawing. Font("Times New Roman",
11.25!,
System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.rtbData.Hide Selection = False
Me.rtbData.Loca tion = New System.Drawing. Point(24, 96)
Me.rtbData.Name = "rtbData"
Me.rtbData.Size = New System.Drawing. Size(592, 248)
Me.rtbData.TabI ndex = 1
Me.rtbData.Text = "Shopping for hourly and daily parking on this
web"
'
'cmdBold
'
Me.cmdBold.Font = New System.Drawing. Font("Arial", 12.0!,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0,
Byte))
Me.cmdBold.Loca tion = New System.Drawing. Point(344, 40)
Me.cmdBold.Name = "cmdBold"
Me.cmdBold.Size = New System.Drawing. Size(24, 24)
Me.cmdBold.TabI ndex = 2
Me.cmdBold.Text = "B"
'
'Label1
'
Me.Label1.Font = New System.Drawing. Font("Times New Roman", 11.25!,
System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.Label1.Locat ion = New System.Drawing. Point(32, 41)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing. Size(80, 24)
Me.Label1.TabIn dex = 3
Me.Label1.Text = "Font Name"
'
'cmdUnderLine
'
Me.cmdUnderLine .Font = New System.Drawing. Font("Arial", 12.0!,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0,
Byte))
Me.cmdUnderLine .Location = New System.Drawing. Point(376, 40)
Me.cmdUnderLine .Name = "cmdUnderLi ne"
Me.cmdUnderLine .Size = New System.Drawing. Size(24, 24)
Me.cmdUnderLine .TabIndex = 6
Me.cmdUnderLine .Text = "U"
'
'cmdItalic
'
Me.cmdItalic.Fo nt = New System.Drawing. Font("Arial", 12.0!,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0,
Byte))
Me.cmdItalic.Lo cation = New System.Drawing. Point(408, 40)
Me.cmdItalic.Na me = "cmdItalic"
Me.cmdItalic.Si ze = New System.Drawing. Size(24, 24)
Me.cmdItalic.Ta bIndex = 7
Me.cmdItalic.Te xt = "I"
'
'cmbFontSize
'
Me.cmbFontSize. Font = New System.Drawing. Font("Times New Roman",
9.75!, System.Drawing. FontStyle.Regul ar,
System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.cmbFontSize. Items.AddRange( New Object() {"8", "9", "10", "11",
"12", "14", "16", "18", "20", "22", "24", "26", "28", "36", "48", "72"})
Me.cmbFontSize. Location = New System.Drawing. Point(272, 40)
Me.cmbFontSize. Name = "cmbFontSiz e"
Me.cmbFontSize. Size = New System.Drawing. Size(56, 23)
Me.cmbFontSize. TabIndex = 21
'
'cmbFontFamily
'
Me.cmbFontFamil y.DropDownStyle =
System.Windows. Forms.ComboBoxS tyle.DropDownLi st
Me.cmbFontFamil y.Font = New System.Drawing. Font("Times New Roman",
9.75!, System.Drawing. FontStyle.Regul ar,
System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.cmbFontFamil y.Location = New System.Drawing. Point(120, 40)
Me.cmbFontFamil y.Name = "cmbFontFam ily"
Me.cmbFontFamil y.Size = New System.Drawing. Size(152, 23)
Me.cmbFontFamil y.TabIndex = 20
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(640, 365)
Me.Controls.Add Range(New System.Windows. Forms.Control()
{Me.cmbFontSize , Me.cmbFontFamil y, Me.cmdItalic, Me.cmdUnderLine ,
Me.Label1,
Me.cmdBold, Me.rtbData})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
cmbFontFamily.I tems.Clear()
Dim myFontFamily() As FontFamily
Dim objFontFamily As FontFamily
myFontFamily = objFontFamily.F amilies()
Dim i As Integer
For i = 0 To myFontFamily.Ge tUpperBound(0)
cmbFontFamily.I tems.Add(myFont Family(i).Name)
Next
cmbFontFamily.S electedIndex = 0
cmbFontSize.Sel ectedIndex = 0
End Sub

'Change Font Family

Private Sub cmbFontFamily_S electedIndexCha nged(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
cmbFontFamily.S electedIndexCha nged
Try
Dim fOld As Font = rtbData.Selecti onFont
Dim fontFamily As New FontFamily(cmbF ontFamily.Text)
If fOld Is Nothing Then
Else
rtbData.Selecti onFont = New Font(fontFamily , fOld.Size)
Dim fNew As Font = rtbData.Selecti onFont
rtbData.Selecti onFont = New Font(fNew, fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
End Sub

'Change font size

Private Sub cmbFontSize_Sel ectedIndexChang ed(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
cmbFontSize.Sel ectedIndexChang ed
Try
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld.FontF amily,
CSng(cmbFontSiz e.Text), fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
End Sub

'Change Bold format

Private Sub cmdBold_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdBold.Click
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld, fOld.Style +
(IIf(fOld.Bold, FontStyle.Bold * -1, FontStyle.Bold) ))
End If
End Sub

'Change Underline format

Private Sub cmdUnderLine_Cl ick(ByVal sender As System.Object, ByVal e
As
System.EventArg s) Handles cmdUnderLine.Cl ick
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld, fOld.Style +
(IIf(fOld.Under line, FontStyle.Under line * -1, FontStyle.Under line)))
End If
End Sub

'Change Italic format

Private Sub cmdItalic_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdItalic.Click
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld, fOld.Style +
(IIf(fOld.Itali c, FontStyle.Itali c * -1, FontStyle.Itali c)))
End If
End Sub

Private Sub rtbData_Selecti onChanged(ByVal sender As Object, ByVal e As
System.EventArg s) Handles rtbData.Selecti onChanged
If rtbData.Selecti onFont Is Nothing Then Exit Sub
cmbFontFamily.T ext = rtbData.Selecti onFont.FontFami ly.Name
cmbFontSize.Tex t = rtbData.Selecti onFont.Size.ToS tring
End Sub

End Class

Nov 21 '05 #2
Hi Cor,

I posted it, but even that time I didn't got answer.
That's why I have posted it again.

Thanks and regards
Sakharam Phapale
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:Oq******** ********@tk2msf tngp13.phx.gbl. ..
Sakharam,

You told you posted it two months ago and you forgot it.

Do you know this link
http://groups.google.com/groups?hl=e...t.languages.vb
I hope this helps?

Cor

"Sakharam Phapale"
..
Hi All,

How to preserve the old font properties while changing new one?
I posted same question 2 months back, but I had very small time then.

eg. "Shopping for" is a text in RichTextBox and already formatted as
"Shopping" ---Bold
"for" -----Regular

Now I want to underline whole text by preserving old style i.e. Bold and
regular.
So that I should get result as follows

"Shopping" ---Bold + Underline
"for" -----Regular + Underline

When I press on UnderLine Button whole string becomes
Regular+Underli ne

I have written following code. You can just copy and paste it and thus can be taste it.
So please tell me where is a mistake?
I have tried lot of things, but couldn't get the result.

Thanks in advance

Regards,
Sakharam Phapale

Public Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents cmdBold As System.Windows. Forms.Button
Friend WithEvents Label1 As System.Windows. Forms.Label
Friend WithEvents rtbData As System.Windows. Forms.RichTextB ox
Friend WithEvents cmbFontSize As System.Windows. Forms.ComboBox
Friend WithEvents cmbFontFamily As System.Windows. Forms.ComboBox
Friend WithEvents cmdUnderLine As System.Windows. Forms.Button
Friend WithEvents cmdItalic As System.Windows. Forms.Button
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.rtbData = New System.Windows. Forms.RichTextB ox()
Me.cmdBold = New System.Windows. Forms.Button()
Me.Label1 = New System.Windows. Forms.Label()
Me.cmdUnderLine = New System.Windows. Forms.Button()
Me.cmdItalic = New System.Windows. Forms.Button()
Me.cmbFontSize = New System.Windows. Forms.ComboBox( )
Me.cmbFontFamil y = New System.Windows. Forms.ComboBox( )
Me.SuspendLayou t()
'
'rtbData
'
Me.rtbData.Font = New System.Drawing. Font("Times New Roman",
11.25!,
System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.rtbData.Hide Selection = False
Me.rtbData.Loca tion = New System.Drawing. Point(24, 96)
Me.rtbData.Name = "rtbData"
Me.rtbData.Size = New System.Drawing. Size(592, 248)
Me.rtbData.TabI ndex = 1
Me.rtbData.Text = "Shopping for hourly and daily parking on this
web"
'
'cmdBold
'
Me.cmdBold.Font = New System.Drawing. Font("Arial", 12.0!,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0, Byte))
Me.cmdBold.Loca tion = New System.Drawing. Point(344, 40)
Me.cmdBold.Name = "cmdBold"
Me.cmdBold.Size = New System.Drawing. Size(24, 24)
Me.cmdBold.TabI ndex = 2
Me.cmdBold.Text = "B"
'
'Label1
'
Me.Label1.Font = New System.Drawing. Font("Times New Roman", 11.25!, System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.Label1.Locat ion = New System.Drawing. Point(32, 41)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing. Size(80, 24)
Me.Label1.TabIn dex = 3
Me.Label1.Text = "Font Name"
'
'cmdUnderLine
'
Me.cmdUnderLine .Font = New System.Drawing. Font("Arial", 12.0!,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0, Byte))
Me.cmdUnderLine .Location = New System.Drawing. Point(376, 40)
Me.cmdUnderLine .Name = "cmdUnderLi ne"
Me.cmdUnderLine .Size = New System.Drawing. Size(24, 24)
Me.cmdUnderLine .TabIndex = 6
Me.cmdUnderLine .Text = "U"
'
'cmdItalic
'
Me.cmdItalic.Fo nt = New System.Drawing. Font("Arial", 12.0!,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0, Byte))
Me.cmdItalic.Lo cation = New System.Drawing. Point(408, 40)
Me.cmdItalic.Na me = "cmdItalic"
Me.cmdItalic.Si ze = New System.Drawing. Size(24, 24)
Me.cmdItalic.Ta bIndex = 7
Me.cmdItalic.Te xt = "I"
'
'cmbFontSize
'
Me.cmbFontSize. Font = New System.Drawing. Font("Times New Roman",
9.75!, System.Drawing. FontStyle.Regul ar,
System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.cmbFontSize. Items.AddRange( New Object() {"8", "9", "10", "11",
"12", "14", "16", "18", "20", "22", "24", "26", "28", "36", "48", "72"})
Me.cmbFontSize. Location = New System.Drawing. Point(272, 40)
Me.cmbFontSize. Name = "cmbFontSiz e"
Me.cmbFontSize. Size = New System.Drawing. Size(56, 23)
Me.cmbFontSize. TabIndex = 21
'
'cmbFontFamily
'
Me.cmbFontFamil y.DropDownStyle =
System.Windows. Forms.ComboBoxS tyle.DropDownLi st
Me.cmbFontFamil y.Font = New System.Drawing. Font("Times New Roman", 9.75!, System.Drawing. FontStyle.Regul ar,
System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.cmbFontFamil y.Location = New System.Drawing. Point(120, 40)
Me.cmbFontFamil y.Name = "cmbFontFam ily"
Me.cmbFontFamil y.Size = New System.Drawing. Size(152, 23)
Me.cmbFontFamil y.TabIndex = 20
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(640, 365)
Me.Controls.Add Range(New System.Windows. Forms.Control()
{Me.cmbFontSize , Me.cmbFontFamil y, Me.cmdItalic, Me.cmdUnderLine ,
Me.Label1,
Me.cmdBold, Me.rtbData})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
cmbFontFamily.I tems.Clear()
Dim myFontFamily() As FontFamily
Dim objFontFamily As FontFamily
myFontFamily = objFontFamily.F amilies()
Dim i As Integer
For i = 0 To myFontFamily.Ge tUpperBound(0)
cmbFontFamily.I tems.Add(myFont Family(i).Name)
Next
cmbFontFamily.S electedIndex = 0
cmbFontSize.Sel ectedIndex = 0
End Sub

'Change Font Family

Private Sub cmbFontFamily_S electedIndexCha nged(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
cmbFontFamily.S electedIndexCha nged
Try
Dim fOld As Font = rtbData.Selecti onFont
Dim fontFamily As New FontFamily(cmbF ontFamily.Text)
If fOld Is Nothing Then
Else
rtbData.Selecti onFont = New Font(fontFamily , fOld.Size)
Dim fNew As Font = rtbData.Selecti onFont
rtbData.Selecti onFont = New Font(fNew, fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
End Sub

'Change font size

Private Sub cmbFontSize_Sel ectedIndexChang ed(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
cmbFontSize.Sel ectedIndexChang ed
Try
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld.FontF amily,
CSng(cmbFontSiz e.Text), fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
End Sub

'Change Bold format

Private Sub cmdBold_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdBold.Click
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld, fOld.Style +
(IIf(fOld.Bold, FontStyle.Bold * -1, FontStyle.Bold) ))
End If
End Sub

'Change Underline format

Private Sub cmdUnderLine_Cl ick(ByVal sender As System.Object, ByVal e
As
System.EventArg s) Handles cmdUnderLine.Cl ick
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld, fOld.Style +
(IIf(fOld.Under line, FontStyle.Under line * -1, FontStyle.Under line)))
End If
End Sub

'Change Italic format

Private Sub cmdItalic_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdItalic.Click
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld, fOld.Style +
(IIf(fOld.Itali c, FontStyle.Itali c * -1, FontStyle.Itali c)))
End If
End Sub

Private Sub rtbData_Selecti onChanged(ByVal sender As Object, ByVal e As System.EventArg s) Handles rtbData.Selecti onChanged
If rtbData.Selecti onFont Is Nothing Then Exit Sub
cmbFontFamily.T ext = rtbData.Selecti onFont.FontFami ly.Name
cmbFontSize.Tex t = rtbData.Selecti onFont.Size.ToS tring
End Sub

End Class


Nov 21 '05 #3
Hi Cor,

Following was our discussion on this issue.
But it was incomplete for my requirement.

Thanks and regards
Sakharam Phapale
From: Sakharam Phapale (sp******@annet site.com)
Subject: Re: How to preserve font properties while changing some other
properties.
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
Date: 2004-10-05 05:44:43 PST

Hello,

Your solution works fine for font style. But what about following situation,
I want to change font of richTextBox contents, which is having multiple
styles.
look at following example

richTextBox.Tex t = "This is just a test example"
"This" ---Times New Roman, Bold, 10
"is"-------arial, Regular,8
"just"-----Courier, Regular,9

Now, I select "This is just" in richTextBox and want to change the font size
to 10 of selected text.

How to accomplish this?
I have written following code. But it doesn't work properly in above
scenario.

Private sub ChangeFont(Font Size as integer)
Dim fOld As Font = rtbData.Selecti onFont

rtbData.Selecti onFont = New Font(fOld.FontF amily, FontSize,
fOld.Style)

End Sub

In above scenario fOld returns as Nothing so I can't used this.
Thanks and Regards
Sakharam Phapale
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Sakharam,

To show you the use of the boolean "OR" in this, see this old snippet from
me.

\\\
Me.Label1.Font = New Font(Me.Label1. Font, Me.Label1.Font. Style Or
FontStyle.Bold)
///

I hope this helps?

Cor


----------------------------------------------------------------------------
----



"Cor Ligthert" <no************ @planet.nl> wrote in message
news:Oq******** ********@tk2msf tngp13.phx.gbl. .. Sakharam,

You told you posted it two months ago and you forgot it.

Do you know this link
http://groups.google.com/groups?hl=e...t.languages.vb
I hope this helps?

Cor

"Sakharam Phapale"
..
Hi All,

How to preserve the old font properties while changing new one?
I posted same question 2 months back, but I had very small time then.

eg. "Shopping for" is a text in RichTextBox and already formatted as
"Shopping" ---Bold
"for" -----Regular

Now I want to underline whole text by preserving old style i.e. Bold and
regular.
So that I should get result as follows

"Shopping" ---Bold + Underline
"for" -----Regular + Underline

When I press on UnderLine Button whole string becomes
Regular+Underli ne

I have written following code. You can just copy and paste it and thus can be taste it.
So please tell me where is a mistake?
I have tried lot of things, but couldn't get the result.

Thanks in advance

Regards,
Sakharam Phapale

Public Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents cmdBold As System.Windows. Forms.Button
Friend WithEvents Label1 As System.Windows. Forms.Label
Friend WithEvents rtbData As System.Windows. Forms.RichTextB ox
Friend WithEvents cmbFontSize As System.Windows. Forms.ComboBox
Friend WithEvents cmbFontFamily As System.Windows. Forms.ComboBox
Friend WithEvents cmdUnderLine As System.Windows. Forms.Button
Friend WithEvents cmdItalic As System.Windows. Forms.Button
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.rtbData = New System.Windows. Forms.RichTextB ox()
Me.cmdBold = New System.Windows. Forms.Button()
Me.Label1 = New System.Windows. Forms.Label()
Me.cmdUnderLine = New System.Windows. Forms.Button()
Me.cmdItalic = New System.Windows. Forms.Button()
Me.cmbFontSize = New System.Windows. Forms.ComboBox( )
Me.cmbFontFamil y = New System.Windows. Forms.ComboBox( )
Me.SuspendLayou t()
'
'rtbData
'
Me.rtbData.Font = New System.Drawing. Font("Times New Roman",
11.25!,
System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.rtbData.Hide Selection = False
Me.rtbData.Loca tion = New System.Drawing. Point(24, 96)
Me.rtbData.Name = "rtbData"
Me.rtbData.Size = New System.Drawing. Size(592, 248)
Me.rtbData.TabI ndex = 1
Me.rtbData.Text = "Shopping for hourly and daily parking on this
web"
'
'cmdBold
'
Me.cmdBold.Font = New System.Drawing. Font("Arial", 12.0!,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0, Byte))
Me.cmdBold.Loca tion = New System.Drawing. Point(344, 40)
Me.cmdBold.Name = "cmdBold"
Me.cmdBold.Size = New System.Drawing. Size(24, 24)
Me.cmdBold.TabI ndex = 2
Me.cmdBold.Text = "B"
'
'Label1
'
Me.Label1.Font = New System.Drawing. Font("Times New Roman", 11.25!, System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.Label1.Locat ion = New System.Drawing. Point(32, 41)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing. Size(80, 24)
Me.Label1.TabIn dex = 3
Me.Label1.Text = "Font Name"
'
'cmdUnderLine
'
Me.cmdUnderLine .Font = New System.Drawing. Font("Arial", 12.0!,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0, Byte))
Me.cmdUnderLine .Location = New System.Drawing. Point(376, 40)
Me.cmdUnderLine .Name = "cmdUnderLi ne"
Me.cmdUnderLine .Size = New System.Drawing. Size(24, 24)
Me.cmdUnderLine .TabIndex = 6
Me.cmdUnderLine .Text = "U"
'
'cmdItalic
'
Me.cmdItalic.Fo nt = New System.Drawing. Font("Arial", 12.0!,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0, Byte))
Me.cmdItalic.Lo cation = New System.Drawing. Point(408, 40)
Me.cmdItalic.Na me = "cmdItalic"
Me.cmdItalic.Si ze = New System.Drawing. Size(24, 24)
Me.cmdItalic.Ta bIndex = 7
Me.cmdItalic.Te xt = "I"
'
'cmbFontSize
'
Me.cmbFontSize. Font = New System.Drawing. Font("Times New Roman",
9.75!, System.Drawing. FontStyle.Regul ar,
System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.cmbFontSize. Items.AddRange( New Object() {"8", "9", "10", "11",
"12", "14", "16", "18", "20", "22", "24", "26", "28", "36", "48", "72"})
Me.cmbFontSize. Location = New System.Drawing. Point(272, 40)
Me.cmbFontSize. Name = "cmbFontSiz e"
Me.cmbFontSize. Size = New System.Drawing. Size(56, 23)
Me.cmbFontSize. TabIndex = 21
'
'cmbFontFamily
'
Me.cmbFontFamil y.DropDownStyle =
System.Windows. Forms.ComboBoxS tyle.DropDownLi st
Me.cmbFontFamil y.Font = New System.Drawing. Font("Times New Roman", 9.75!, System.Drawing. FontStyle.Regul ar,
System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.cmbFontFamil y.Location = New System.Drawing. Point(120, 40)
Me.cmbFontFamil y.Name = "cmbFontFam ily"
Me.cmbFontFamil y.Size = New System.Drawing. Size(152, 23)
Me.cmbFontFamil y.TabIndex = 20
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(640, 365)
Me.Controls.Add Range(New System.Windows. Forms.Control()
{Me.cmbFontSize , Me.cmbFontFamil y, Me.cmdItalic, Me.cmdUnderLine ,
Me.Label1,
Me.cmdBold, Me.rtbData})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
cmbFontFamily.I tems.Clear()
Dim myFontFamily() As FontFamily
Dim objFontFamily As FontFamily
myFontFamily = objFontFamily.F amilies()
Dim i As Integer
For i = 0 To myFontFamily.Ge tUpperBound(0)
cmbFontFamily.I tems.Add(myFont Family(i).Name)
Next
cmbFontFamily.S electedIndex = 0
cmbFontSize.Sel ectedIndex = 0
End Sub

'Change Font Family

Private Sub cmbFontFamily_S electedIndexCha nged(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
cmbFontFamily.S electedIndexCha nged
Try
Dim fOld As Font = rtbData.Selecti onFont
Dim fontFamily As New FontFamily(cmbF ontFamily.Text)
If fOld Is Nothing Then
Else
rtbData.Selecti onFont = New Font(fontFamily , fOld.Size)
Dim fNew As Font = rtbData.Selecti onFont
rtbData.Selecti onFont = New Font(fNew, fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
End Sub

'Change font size

Private Sub cmbFontSize_Sel ectedIndexChang ed(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
cmbFontSize.Sel ectedIndexChang ed
Try
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld.FontF amily,
CSng(cmbFontSiz e.Text), fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
End Sub

'Change Bold format

Private Sub cmdBold_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdBold.Click
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld, fOld.Style +
(IIf(fOld.Bold, FontStyle.Bold * -1, FontStyle.Bold) ))
End If
End Sub

'Change Underline format

Private Sub cmdUnderLine_Cl ick(ByVal sender As System.Object, ByVal e
As
System.EventArg s) Handles cmdUnderLine.Cl ick
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld, fOld.Style +
(IIf(fOld.Under line, FontStyle.Under line * -1, FontStyle.Under line)))
End If
End Sub

'Change Italic format

Private Sub cmdItalic_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdItalic.Click
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld, fOld.Style +
(IIf(fOld.Itali c, FontStyle.Itali c * -1, FontStyle.Itali c)))
End If
End Sub

Private Sub rtbData_Selecti onChanged(ByVal sender As Object, ByVal e As System.EventArg s) Handles rtbData.Selecti onChanged
If rtbData.Selecti onFont Is Nothing Then Exit Sub
cmbFontFamily.T ext = rtbData.Selecti onFont.FontFami ly.Name
cmbFontSize.Tex t = rtbData.Selecti onFont.Size.ToS tring
End Sub

End Class


Nov 21 '05 #4
Hi All,

I have written following code to achieve the result.
It sets the font property character by character.
But I don't think that it's feasible solution because it selects character
and changes it's property looks awkward as compare to normal.
Please comment on this solution or offer a good one.
Private Sub UnderLineSelect edText()
Dim intCounter As Integer
For intCounter = rtbData.Selecti onStart To rtbData.Selecti onStart +
rtbData.Selecti onLength - 1
rtbData.Select( intCounter, 1)
Dim fOld As Font = rtbData.Selecti onFont
Dim fStyle As FontStyle = fOld.Style + (IIf(fOld.Under line,
FontStyle.Under line * -1, FontStyle.Under line))
rtbData.Selecti onFont = New Font(fOld.FontF amily, fOld.Size,
fStyle)
Next
rtbData.Selecti onLength = 0
End Sub

Thanks and regards,
Sakharam Phapale
"Sakharam Phapale" <sp******@annet site.com> wrote in message
news:u%******** **********@TK2M SFTNGP14.phx.gb l...
Hi Cor,

Following was our discussion on this issue.
But it was incomplete for my requirement.

Thanks and regards
Sakharam Phapale
From: Sakharam Phapale (sp******@annet site.com)
Subject: Re: How to preserve font properties while changing some other
properties.
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
Date: 2004-10-05 05:44:43 PST

Hello,

Your solution works fine for font style. But what about following situation, I want to change font of richTextBox contents, which is having multiple
styles.
look at following example

richTextBox.Tex t = "This is just a test example"
"This" ---Times New Roman, Bold, 10
"is"-------arial, Regular,8
"just"-----Courier, Regular,9

Now, I select "This is just" in richTextBox and want to change the font size to 10 of selected text.

How to accomplish this?
I have written following code. But it doesn't work properly in above
scenario.

Private sub ChangeFont(Font Size as integer)
Dim fOld As Font = rtbData.Selecti onFont

rtbData.Selecti onFont = New Font(fOld.FontF amily, FontSize,
fOld.Style)

End Sub

In above scenario fOld returns as Nothing so I can't used this.
Thanks and Regards
Sakharam Phapale
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Sakharam,

To show you the use of the boolean "OR" in this, see this old snippet from
me.

\\\
Me.Label1.Font = New Font(Me.Label1. Font, Me.Label1.Font. Style Or
FontStyle.Bold)
///

I hope this helps?

Cor
--------------------------------------------------------------------------

-- ----



"Cor Ligthert" <no************ @planet.nl> wrote in message
news:Oq******** ********@tk2msf tngp13.phx.gbl. ..
Sakharam,

You told you posted it two months ago and you forgot it.

Do you know this link

http://groups.google.com/groups?hl=e...t.languages.vb

I hope this helps?

Cor

"Sakharam Phapale"
..
Hi All,

How to preserve the old font properties while changing new one?
I posted same question 2 months back, but I had very small time then.

eg. "Shopping for" is a text in RichTextBox and already formatted as
"Shopping" ---Bold
"for" -----Regular

Now I want to underline whole text by preserving old style i.e. Bold and regular.
So that I should get result as follows

"Shopping" ---Bold + Underline
"for" -----Regular + Underline

When I press on UnderLine Button whole string becomes
Regular+Underli ne

I have written following code. You can just copy and paste it and thus

can be taste it.
So please tell me where is a mistake?
I have tried lot of things, but couldn't get the result.

Thanks in advance

Regards,
Sakharam Phapale

Public Class Form1
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents cmdBold As System.Windows. Forms.Button
Friend WithEvents Label1 As System.Windows. Forms.Label
Friend WithEvents rtbData As System.Windows. Forms.RichTextB ox
Friend WithEvents cmbFontSize As System.Windows. Forms.ComboBox
Friend WithEvents cmbFontFamily As System.Windows. Forms.ComboBox
Friend WithEvents cmdUnderLine As System.Windows. Forms.Button
Friend WithEvents cmdItalic As System.Windows. Forms.Button
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.rtbData = New System.Windows. Forms.RichTextB ox()
Me.cmdBold = New System.Windows. Forms.Button()
Me.Label1 = New System.Windows. Forms.Label()
Me.cmdUnderLine = New System.Windows. Forms.Button()
Me.cmdItalic = New System.Windows. Forms.Button()
Me.cmbFontSize = New System.Windows. Forms.ComboBox( )
Me.cmbFontFamil y = New System.Windows. Forms.ComboBox( )
Me.SuspendLayou t()
'
'rtbData
'
Me.rtbData.Font = New System.Drawing. Font("Times New Roman",
11.25!,
System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.rtbData.Hide Selection = False
Me.rtbData.Loca tion = New System.Drawing. Point(24, 96)
Me.rtbData.Name = "rtbData"
Me.rtbData.Size = New System.Drawing. Size(592, 248)
Me.rtbData.TabI ndex = 1
Me.rtbData.Text = "Shopping for hourly and daily parking on this web"
'
'cmdBold
'
Me.cmdBold.Font = New System.Drawing. Font("Arial", 12.0!,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0, Byte))
Me.cmdBold.Loca tion = New System.Drawing. Point(344, 40)
Me.cmdBold.Name = "cmdBold"
Me.cmdBold.Size = New System.Drawing. Size(24, 24)
Me.cmdBold.TabI ndex = 2
Me.cmdBold.Text = "B"
'
'Label1
'
Me.Label1.Font = New System.Drawing. Font("Times New Roman", 11.25!, System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.Label1.Locat ion = New System.Drawing. Point(32, 41)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing. Size(80, 24)
Me.Label1.TabIn dex = 3
Me.Label1.Text = "Font Name"
'
'cmdUnderLine
'
Me.cmdUnderLine .Font = New System.Drawing. Font("Arial", 12.0!,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0, Byte))
Me.cmdUnderLine .Location = New System.Drawing. Point(376, 40)
Me.cmdUnderLine .Name = "cmdUnderLi ne"
Me.cmdUnderLine .Size = New System.Drawing. Size(24, 24)
Me.cmdUnderLine .TabIndex = 6
Me.cmdUnderLine .Text = "U"
'
'cmdItalic
'
Me.cmdItalic.Fo nt = New System.Drawing. Font("Arial", 12.0!,
System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0, Byte))
Me.cmdItalic.Lo cation = New System.Drawing. Point(408, 40)
Me.cmdItalic.Na me = "cmdItalic"
Me.cmdItalic.Si ze = New System.Drawing. Size(24, 24)
Me.cmdItalic.Ta bIndex = 7
Me.cmdItalic.Te xt = "I"
'
'cmbFontSize
'
Me.cmbFontSize. Font = New System.Drawing. Font("Times New Roman", 9.75!, System.Drawing. FontStyle.Regul ar,
System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.cmbFontSize. Items.AddRange( New Object() {"8", "9", "10", "11", "12", "14", "16", "18", "20", "22", "24", "26", "28", "36", "48", "72"}) Me.cmbFontSize. Location = New System.Drawing. Point(272, 40)
Me.cmbFontSize. Name = "cmbFontSiz e"
Me.cmbFontSize. Size = New System.Drawing. Size(56, 23)
Me.cmbFontSize. TabIndex = 21
'
'cmbFontFamily
'
Me.cmbFontFamil y.DropDownStyle =
System.Windows. Forms.ComboBoxS tyle.DropDownLi st
Me.cmbFontFamil y.Font = New System.Drawing. Font("Times New Roman", 9.75!, System.Drawing. FontStyle.Regul ar,
System.Drawing. GraphicsUnit.Po int,
CType(0, Byte))
Me.cmbFontFamil y.Location = New System.Drawing. Point(120, 40)
Me.cmbFontFamil y.Name = "cmbFontFam ily"
Me.cmbFontFamil y.Size = New System.Drawing. Size(152, 23)
Me.cmbFontFamil y.TabIndex = 20
'
'Form1
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(640, 365)
Me.Controls.Add Range(New System.Windows. Forms.Control()
{Me.cmbFontSize , Me.cmbFontFamil y, Me.cmdItalic, Me.cmdUnderLine ,
Me.Label1,
Me.cmdBold, Me.rtbData})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
cmbFontFamily.I tems.Clear()
Dim myFontFamily() As FontFamily
Dim objFontFamily As FontFamily
myFontFamily = objFontFamily.F amilies()
Dim i As Integer
For i = 0 To myFontFamily.Ge tUpperBound(0)
cmbFontFamily.I tems.Add(myFont Family(i).Name)
Next
cmbFontFamily.S electedIndex = 0
cmbFontSize.Sel ectedIndex = 0
End Sub

'Change Font Family

Private Sub cmbFontFamily_S electedIndexCha nged(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
cmbFontFamily.S electedIndexCha nged
Try
Dim fOld As Font = rtbData.Selecti onFont
Dim fontFamily As New FontFamily(cmbF ontFamily.Text)
If fOld Is Nothing Then
Else
rtbData.Selecti onFont = New Font(fontFamily , fOld.Size)
Dim fNew As Font = rtbData.Selecti onFont
rtbData.Selecti onFont = New Font(fNew, fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
End Sub

'Change font size

Private Sub cmbFontSize_Sel ectedIndexChang ed(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
cmbFontSize.Sel ectedIndexChang ed
Try
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld.FontF amily,
CSng(cmbFontSiz e.Text), fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Messa ge)
End Try
End Sub

'Change Bold format

Private Sub cmdBold_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdBold.Click
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld, fOld.Style +
(IIf(fOld.Bold, FontStyle.Bold * -1, FontStyle.Bold) ))
End If
End Sub

'Change Underline format

Private Sub cmdUnderLine_Cl ick(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdUnderLine.Cl ick
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld, fOld.Style +
(IIf(fOld.Under line, FontStyle.Under line * -1, FontStyle.Under line)))
End If
End Sub

'Change Italic format

Private Sub cmdItalic_Click (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles cmdItalic.Click
Dim fOld As Font = rtbData.Selecti onFont
If fOld Is Nothing Then

Else
rtbData.Selecti onFont = New Font(fOld, fOld.Style +
(IIf(fOld.Itali c, FontStyle.Itali c * -1, FontStyle.Itali c)))
End If
End Sub

Private Sub rtbData_Selecti onChanged(ByVal sender As Object, ByVal
e As System.EventArg s) Handles rtbData.Selecti onChanged
If rtbData.Selecti onFont Is Nothing Then Exit Sub
cmbFontFamily.T ext = rtbData.Selecti onFont.FontFami ly.Name
cmbFontSize.Tex t = rtbData.Selecti onFont.Size.ToS tring
End Sub

End Class



Nov 21 '05 #5
Sakharam,

At that time you did not ask as that it was for a rich textbox. (As you now
again not, when you look at your code and you know that it is about a
richtextbox than probably rtb is richtextbox)

I gave you an answer and than you said that it was correct for your purpose.
However than you came with a new question. The rich text box is not a
control I am often doing things with; nevertheless, there are enough in this
newsgroup who do. Therefore did I not answer on that question.

But when you ask again your question in a mystirious way, you will again
probably get an answer that does not help you to reach your goal.

I see however as well that you now again back to your old coding with the
IIF to set the font properties and not just the OR to add the font enums as
I advised you, so why are you asking for help?

Cor
Nov 21 '05 #6
Hi Cor,

I am very sorry, I made mistake by not mentioning RichTextBox control.
All of you peoples are very helpful and Since, I am not so strong in
english,
might not able to explain cleanly.

Thanks for your replies.
Sakharam Phapale

Note : Given solution works only when, whole text is having same font
properties.
for e.g.(As per my understanding Label.Text is either Bold or Regular)

But in RichTextBox some part of text can have Bold and other Regular.
In this situation given solution does not work.
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Sakharam,

At that time you did not ask as that it was for a rich textbox. (As you now again not, when you look at your code and you know that it is about a
richtextbox than probably rtb is richtextbox)

I gave you an answer and than you said that it was correct for your purpose. However than you came with a new question. The rich text box is not a
control I am often doing things with; nevertheless, there are enough in this newsgroup who do. Therefore did I not answer on that question.

But when you ask again your question in a mystirious way, you will again
probably get an answer that does not help you to reach your goal.

I see however as well that you now again back to your old coding with the
IIF to set the font properties and not just the OR to add the font enums as I advised you, so why are you asking for help?

Cor

Nov 21 '05 #7
Sakharam,

When I was you I would make a new message with in the subject the text "in a
RichTextBox"

Cor

"Sakharam Phapale"
Hi Cor,

I am very sorry, I made mistake by not mentioning RichTextBox control.
All of you peoples are very helpful and Since, I am not so strong in
english,
might not able to explain cleanly.

Thanks for your replies.
Sakharam Phapale

Note : Given solution works only when, whole text is having same font
properties.
for e.g.(As per my understanding Label.Text is either Bold or Regular)

But in RichTextBox some part of text can have Bold and other Regular.
In this situation given solution does not work.
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Sakharam,

At that time you did not ask as that it was for a rich textbox. (As you

now
again not, when you look at your code and you know that it is about a
richtextbox than probably rtb is richtextbox)

I gave you an answer and than you said that it was correct for your

purpose.
However than you came with a new question. The rich text box is not a
control I am often doing things with; nevertheless, there are enough in

this
newsgroup who do. Therefore did I not answer on that question.

But when you ask again your question in a mystirious way, you will again
probably get an answer that does not help you to reach your goal.

I see however as well that you now again back to your old coding with the
IIF to set the font properties and not just the OR to add the font enums

as
I advised you, so why are you asking for help?

Cor


Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
19483
by: Fabian Neumann | last post by:
Hi! I got a problem with font-family inheritance. Let's say I have CSS definitions like: p { font:normal 10pt Verdana; } strong { font:normal 14pt inherit;
0
1341
by: Jan Keller | last post by:
Hello all, I am using an XmlTextReader and a DataSet to populate a DataGrid: ds = New DataSet xr = New XmlTextReader(path) ds.ReadXml(xr) xr.Close() dv = New DataView(ds.Tables.Item(0))
1
2639
by: Jon Pope | last post by:
I'm maintaining an internal tool within my organization. Some of my users have resized their system font size by changing the DPI setting from 96DPI to 120DPI (by right-clicking the desktop and selecting Properties|Settings|Advanced|General). My problem is this: my splash screen form gets resized after the user performs this action, and as a consequence it looks "funny": the image remains the same size but the form is wider, so parts...
4
8984
by: Larry | last post by:
Although there are font attribute properties for the items in a ListView component, the complier tells me that they are read-only. Is there any way to get access and change the font poperties of individual items in the listview item collection; or is there another control I should consider using? My work around for the moment is to use a sub item and show the listview columns but this takes up more space than I would like and isn't quite...
3
1849
by: Sakharam Phapale | last post by:
Hi All, I am using a richTextBox control for text editing purpose. I have written following procedure which change the font style of richTextBox. Dim f as font = rtbData.selectionFont() rtbData.SelectionFont = New Font(f, f.Style + (IIf(f.Bold, FontStyle.Bold * -1, FontStyle.Bold)))
0
1398
by: the.tinapatel | last post by:
Guys, I want the user to be able to select font (such as Bold, Italic, underline) and stuff like that from a dropdown list) and then I wanna apply these properties to all my page (all text). Now I'm doing something like this: string font = string.Empty; switch(ddl2.SelectedItem.Text) {
0
1364
by: nitehawk416 | last post by:
I want to change the font of my rich text box to a font I downloaded. In the properties the font isn't there, so I tried changing it through the code with this variable declaration Font MUDFONT = new Font("MUD 10",8, FontStyle.Regular); and then calling it in the text changed function private void DisplayBox_TextChanged(object sender, EventArgs e) { DisplayBox.Font = MUDFONT;
6
2855
by: andrew.ames | last post by:
Hi I have a pretty basic windows application created in Visual Studio 2005 and VB.NET. I set my Form's font to Arial 8.25pt, so when i added a label and a button they automatically have a font of Arial and 8.25pt. Great.
2
3389
by: sudhivns | last post by:
Hi, I'm using the Webbrowser control in UI to display certain HTML formatted text. While displaying i have used the fixed font/color in HTML tag text. But wanted to display the text format comply with Windows System wide settings (Display properties/Appearance/ Windows & Buttons etc). Any class/API thru which i can get the System Font/Color/Windows & Buttons details. With these details i can set my control properties. Thanks In...
0
8760
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6592
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5923
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3125
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2458
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2070
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.