473,387 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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+Underline

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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.RichTextBox
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.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.rtbData = New System.Windows.Forms.RichTextBox()
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.cmbFontFamily = New System.Windows.Forms.ComboBox()
Me.SuspendLayout()
'
'rtbData
'
Me.rtbData.Font = New System.Drawing.Font("Times New Roman", 11.25!,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.rtbData.HideSelection = False
Me.rtbData.Location = New System.Drawing.Point(24, 96)
Me.rtbData.Name = "rtbData"
Me.rtbData.Size = New System.Drawing.Size(592, 248)
Me.rtbData.TabIndex = 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.Point, CType(0,
Byte))
Me.cmdBold.Location = New System.Drawing.Point(344, 40)
Me.cmdBold.Name = "cmdBold"
Me.cmdBold.Size = New System.Drawing.Size(24, 24)
Me.cmdBold.TabIndex = 2
Me.cmdBold.Text = "B"
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Times New Roman", 11.25!,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(32, 41)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(80, 24)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Font Name"
'
'cmdUnderLine
'
Me.cmdUnderLine.Font = New System.Drawing.Font("Arial", 12.0!,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0,
Byte))
Me.cmdUnderLine.Location = New System.Drawing.Point(376, 40)
Me.cmdUnderLine.Name = "cmdUnderLine"
Me.cmdUnderLine.Size = New System.Drawing.Size(24, 24)
Me.cmdUnderLine.TabIndex = 6
Me.cmdUnderLine.Text = "U"
'
'cmdItalic
'
Me.cmdItalic.Font = New System.Drawing.Font("Arial", 12.0!,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0,
Byte))
Me.cmdItalic.Location = New System.Drawing.Point(408, 40)
Me.cmdItalic.Name = "cmdItalic"
Me.cmdItalic.Size = New System.Drawing.Size(24, 24)
Me.cmdItalic.TabIndex = 7
Me.cmdItalic.Text = "I"
'
'cmbFontSize
'
Me.cmbFontSize.Font = New System.Drawing.Font("Times New Roman",
9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
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 = "cmbFontSize"
Me.cmbFontSize.Size = New System.Drawing.Size(56, 23)
Me.cmbFontSize.TabIndex = 21
'
'cmbFontFamily
'
Me.cmbFontFamily.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cmbFontFamily.Font = New System.Drawing.Font("Times New Roman",
9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.cmbFontFamily.Location = New System.Drawing.Point(120, 40)
Me.cmbFontFamily.Name = "cmbFontFamily"
Me.cmbFontFamily.Size = New System.Drawing.Size(152, 23)
Me.cmbFontFamily.TabIndex = 20
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(640, 365)
Me.Controls.AddRange(New System.Windows.Forms.Control()
{Me.cmbFontSize, Me.cmbFontFamily, 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(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
cmbFontFamily.Items.Clear()
Dim myFontFamily() As FontFamily
Dim objFontFamily As FontFamily
myFontFamily = objFontFamily.Families()
Dim i As Integer
For i = 0 To myFontFamily.GetUpperBound(0)
cmbFontFamily.Items.Add(myFontFamily(i).Name)
Next
cmbFontFamily.SelectedIndex = 0
cmbFontSize.SelectedIndex = 0
End Sub

'Change Font Family

Private Sub cmbFontFamily_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cmbFontFamily.SelectedIndexChanged
Try
Dim fOld As Font = rtbData.SelectionFont
Dim fontFamily As New FontFamily(cmbFontFamily.Text)
If fOld Is Nothing Then
Else
rtbData.SelectionFont = New Font(fontFamily, fOld.Size)
Dim fNew As Font = rtbData.SelectionFont
rtbData.SelectionFont = New Font(fNew, fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

'Change font size

Private Sub cmbFontSize_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cmbFontSize.SelectedIndexChanged
Try
Dim fOld As Font = rtbData.SelectionFont
If fOld Is Nothing Then

Else
rtbData.SelectionFont = New Font(fOld.FontFamily,
CSng(cmbFontSize.Text), fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

'Change Bold format

Private Sub cmdBold_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdBold.Click
Dim fOld As Font = rtbData.SelectionFont
If fOld Is Nothing Then

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

'Change Underline format

Private Sub cmdUnderLine_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdUnderLine.Click
Dim fOld As Font = rtbData.SelectionFont
If fOld Is Nothing Then

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

'Change Italic format

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

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

Private Sub rtbData_SelectionChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles rtbData.SelectionChanged
If rtbData.SelectionFont Is Nothing Then Exit Sub
cmbFontFamily.Text = rtbData.SelectionFont.FontFamily.Name
cmbFontSize.Text = rtbData.SelectionFont.Size.ToString
End Sub

End Class
Nov 21 '05 #1
7 2919
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+Underline

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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.RichTextBox
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.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.rtbData = New System.Windows.Forms.RichTextBox()
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.cmbFontFamily = New System.Windows.Forms.ComboBox()
Me.SuspendLayout()
'
'rtbData
'
Me.rtbData.Font = New System.Drawing.Font("Times New Roman",
11.25!,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.rtbData.HideSelection = False
Me.rtbData.Location = New System.Drawing.Point(24, 96)
Me.rtbData.Name = "rtbData"
Me.rtbData.Size = New System.Drawing.Size(592, 248)
Me.rtbData.TabIndex = 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.Point, CType(0,
Byte))
Me.cmdBold.Location = New System.Drawing.Point(344, 40)
Me.cmdBold.Name = "cmdBold"
Me.cmdBold.Size = New System.Drawing.Size(24, 24)
Me.cmdBold.TabIndex = 2
Me.cmdBold.Text = "B"
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Times New Roman", 11.25!,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(32, 41)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(80, 24)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Font Name"
'
'cmdUnderLine
'
Me.cmdUnderLine.Font = New System.Drawing.Font("Arial", 12.0!,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0,
Byte))
Me.cmdUnderLine.Location = New System.Drawing.Point(376, 40)
Me.cmdUnderLine.Name = "cmdUnderLine"
Me.cmdUnderLine.Size = New System.Drawing.Size(24, 24)
Me.cmdUnderLine.TabIndex = 6
Me.cmdUnderLine.Text = "U"
'
'cmdItalic
'
Me.cmdItalic.Font = New System.Drawing.Font("Arial", 12.0!,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0,
Byte))
Me.cmdItalic.Location = New System.Drawing.Point(408, 40)
Me.cmdItalic.Name = "cmdItalic"
Me.cmdItalic.Size = New System.Drawing.Size(24, 24)
Me.cmdItalic.TabIndex = 7
Me.cmdItalic.Text = "I"
'
'cmbFontSize
'
Me.cmbFontSize.Font = New System.Drawing.Font("Times New Roman",
9.75!, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point,
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 = "cmbFontSize"
Me.cmbFontSize.Size = New System.Drawing.Size(56, 23)
Me.cmbFontSize.TabIndex = 21
'
'cmbFontFamily
'
Me.cmbFontFamily.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cmbFontFamily.Font = New System.Drawing.Font("Times New Roman",
9.75!, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.cmbFontFamily.Location = New System.Drawing.Point(120, 40)
Me.cmbFontFamily.Name = "cmbFontFamily"
Me.cmbFontFamily.Size = New System.Drawing.Size(152, 23)
Me.cmbFontFamily.TabIndex = 20
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(640, 365)
Me.Controls.AddRange(New System.Windows.Forms.Control()
{Me.cmbFontSize, Me.cmbFontFamily, 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(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
cmbFontFamily.Items.Clear()
Dim myFontFamily() As FontFamily
Dim objFontFamily As FontFamily
myFontFamily = objFontFamily.Families()
Dim i As Integer
For i = 0 To myFontFamily.GetUpperBound(0)
cmbFontFamily.Items.Add(myFontFamily(i).Name)
Next
cmbFontFamily.SelectedIndex = 0
cmbFontSize.SelectedIndex = 0
End Sub

'Change Font Family

Private Sub cmbFontFamily_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cmbFontFamily.SelectedIndexChanged
Try
Dim fOld As Font = rtbData.SelectionFont
Dim fontFamily As New FontFamily(cmbFontFamily.Text)
If fOld Is Nothing Then
Else
rtbData.SelectionFont = New Font(fontFamily, fOld.Size)
Dim fNew As Font = rtbData.SelectionFont
rtbData.SelectionFont = New Font(fNew, fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

'Change font size

Private Sub cmbFontSize_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cmbFontSize.SelectedIndexChanged
Try
Dim fOld As Font = rtbData.SelectionFont
If fOld Is Nothing Then

Else
rtbData.SelectionFont = New Font(fOld.FontFamily,
CSng(cmbFontSize.Text), fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

'Change Bold format

Private Sub cmdBold_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdBold.Click
Dim fOld As Font = rtbData.SelectionFont
If fOld Is Nothing Then

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

'Change Underline format

Private Sub cmdUnderLine_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles cmdUnderLine.Click
Dim fOld As Font = rtbData.SelectionFont
If fOld Is Nothing Then

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

'Change Italic format

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

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

Private Sub rtbData_SelectionChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles rtbData.SelectionChanged
If rtbData.SelectionFont Is Nothing Then Exit Sub
cmbFontFamily.Text = rtbData.SelectionFont.FontFamily.Name
cmbFontSize.Text = rtbData.SelectionFont.Size.ToString
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****************@tk2msftngp13.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+Underline

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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.RichTextBox
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.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.rtbData = New System.Windows.Forms.RichTextBox()
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.cmbFontFamily = New System.Windows.Forms.ComboBox()
Me.SuspendLayout()
'
'rtbData
'
Me.rtbData.Font = New System.Drawing.Font("Times New Roman",
11.25!,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.rtbData.HideSelection = False
Me.rtbData.Location = New System.Drawing.Point(24, 96)
Me.rtbData.Name = "rtbData"
Me.rtbData.Size = New System.Drawing.Size(592, 248)
Me.rtbData.TabIndex = 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.Point, CType(0, Byte))
Me.cmdBold.Location = New System.Drawing.Point(344, 40)
Me.cmdBold.Name = "cmdBold"
Me.cmdBold.Size = New System.Drawing.Size(24, 24)
Me.cmdBold.TabIndex = 2
Me.cmdBold.Text = "B"
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Times New Roman", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(32, 41)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(80, 24)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Font Name"
'
'cmdUnderLine
'
Me.cmdUnderLine.Font = New System.Drawing.Font("Arial", 12.0!,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.cmdUnderLine.Location = New System.Drawing.Point(376, 40)
Me.cmdUnderLine.Name = "cmdUnderLine"
Me.cmdUnderLine.Size = New System.Drawing.Size(24, 24)
Me.cmdUnderLine.TabIndex = 6
Me.cmdUnderLine.Text = "U"
'
'cmdItalic
'
Me.cmdItalic.Font = New System.Drawing.Font("Arial", 12.0!,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.cmdItalic.Location = New System.Drawing.Point(408, 40)
Me.cmdItalic.Name = "cmdItalic"
Me.cmdItalic.Size = New System.Drawing.Size(24, 24)
Me.cmdItalic.TabIndex = 7
Me.cmdItalic.Text = "I"
'
'cmbFontSize
'
Me.cmbFontSize.Font = New System.Drawing.Font("Times New Roman",
9.75!, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point,
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 = "cmbFontSize"
Me.cmbFontSize.Size = New System.Drawing.Size(56, 23)
Me.cmbFontSize.TabIndex = 21
'
'cmbFontFamily
'
Me.cmbFontFamily.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cmbFontFamily.Font = New System.Drawing.Font("Times New Roman", 9.75!, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.cmbFontFamily.Location = New System.Drawing.Point(120, 40)
Me.cmbFontFamily.Name = "cmbFontFamily"
Me.cmbFontFamily.Size = New System.Drawing.Size(152, 23)
Me.cmbFontFamily.TabIndex = 20
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(640, 365)
Me.Controls.AddRange(New System.Windows.Forms.Control()
{Me.cmbFontSize, Me.cmbFontFamily, 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(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
cmbFontFamily.Items.Clear()
Dim myFontFamily() As FontFamily
Dim objFontFamily As FontFamily
myFontFamily = objFontFamily.Families()
Dim i As Integer
For i = 0 To myFontFamily.GetUpperBound(0)
cmbFontFamily.Items.Add(myFontFamily(i).Name)
Next
cmbFontFamily.SelectedIndex = 0
cmbFontSize.SelectedIndex = 0
End Sub

'Change Font Family

Private Sub cmbFontFamily_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cmbFontFamily.SelectedIndexChanged
Try
Dim fOld As Font = rtbData.SelectionFont
Dim fontFamily As New FontFamily(cmbFontFamily.Text)
If fOld Is Nothing Then
Else
rtbData.SelectionFont = New Font(fontFamily, fOld.Size)
Dim fNew As Font = rtbData.SelectionFont
rtbData.SelectionFont = New Font(fNew, fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

'Change font size

Private Sub cmbFontSize_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cmbFontSize.SelectedIndexChanged
Try
Dim fOld As Font = rtbData.SelectionFont
If fOld Is Nothing Then

Else
rtbData.SelectionFont = New Font(fOld.FontFamily,
CSng(cmbFontSize.Text), fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

'Change Bold format

Private Sub cmdBold_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdBold.Click
Dim fOld As Font = rtbData.SelectionFont
If fOld Is Nothing Then

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

'Change Underline format

Private Sub cmdUnderLine_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles cmdUnderLine.Click
Dim fOld As Font = rtbData.SelectionFont
If fOld Is Nothing Then

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

'Change Italic format

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

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

Private Sub rtbData_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rtbData.SelectionChanged
If rtbData.SelectionFont Is Nothing Then Exit Sub
cmbFontFamily.Text = rtbData.SelectionFont.FontFamily.Name
cmbFontSize.Text = rtbData.SelectionFont.Size.ToString
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******@annetsite.com)
Subject: Re: How to preserve font properties while changing some other
properties.
Newsgroups: microsoft.public.dotnet.languages.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.Text = "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(FontSize as integer)
Dim fOld As Font = rtbData.SelectionFont

rtbData.SelectionFont = New Font(fOld.FontFamily, 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****************@TK2MSFTNGP12.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****************@tk2msftngp13.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+Underline

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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.RichTextBox
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.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.rtbData = New System.Windows.Forms.RichTextBox()
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.cmbFontFamily = New System.Windows.Forms.ComboBox()
Me.SuspendLayout()
'
'rtbData
'
Me.rtbData.Font = New System.Drawing.Font("Times New Roman",
11.25!,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.rtbData.HideSelection = False
Me.rtbData.Location = New System.Drawing.Point(24, 96)
Me.rtbData.Name = "rtbData"
Me.rtbData.Size = New System.Drawing.Size(592, 248)
Me.rtbData.TabIndex = 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.Point, CType(0, Byte))
Me.cmdBold.Location = New System.Drawing.Point(344, 40)
Me.cmdBold.Name = "cmdBold"
Me.cmdBold.Size = New System.Drawing.Size(24, 24)
Me.cmdBold.TabIndex = 2
Me.cmdBold.Text = "B"
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Times New Roman", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(32, 41)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(80, 24)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Font Name"
'
'cmdUnderLine
'
Me.cmdUnderLine.Font = New System.Drawing.Font("Arial", 12.0!,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.cmdUnderLine.Location = New System.Drawing.Point(376, 40)
Me.cmdUnderLine.Name = "cmdUnderLine"
Me.cmdUnderLine.Size = New System.Drawing.Size(24, 24)
Me.cmdUnderLine.TabIndex = 6
Me.cmdUnderLine.Text = "U"
'
'cmdItalic
'
Me.cmdItalic.Font = New System.Drawing.Font("Arial", 12.0!,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.cmdItalic.Location = New System.Drawing.Point(408, 40)
Me.cmdItalic.Name = "cmdItalic"
Me.cmdItalic.Size = New System.Drawing.Size(24, 24)
Me.cmdItalic.TabIndex = 7
Me.cmdItalic.Text = "I"
'
'cmbFontSize
'
Me.cmbFontSize.Font = New System.Drawing.Font("Times New Roman",
9.75!, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point,
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 = "cmbFontSize"
Me.cmbFontSize.Size = New System.Drawing.Size(56, 23)
Me.cmbFontSize.TabIndex = 21
'
'cmbFontFamily
'
Me.cmbFontFamily.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cmbFontFamily.Font = New System.Drawing.Font("Times New Roman", 9.75!, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.cmbFontFamily.Location = New System.Drawing.Point(120, 40)
Me.cmbFontFamily.Name = "cmbFontFamily"
Me.cmbFontFamily.Size = New System.Drawing.Size(152, 23)
Me.cmbFontFamily.TabIndex = 20
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(640, 365)
Me.Controls.AddRange(New System.Windows.Forms.Control()
{Me.cmbFontSize, Me.cmbFontFamily, 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(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
cmbFontFamily.Items.Clear()
Dim myFontFamily() As FontFamily
Dim objFontFamily As FontFamily
myFontFamily = objFontFamily.Families()
Dim i As Integer
For i = 0 To myFontFamily.GetUpperBound(0)
cmbFontFamily.Items.Add(myFontFamily(i).Name)
Next
cmbFontFamily.SelectedIndex = 0
cmbFontSize.SelectedIndex = 0
End Sub

'Change Font Family

Private Sub cmbFontFamily_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cmbFontFamily.SelectedIndexChanged
Try
Dim fOld As Font = rtbData.SelectionFont
Dim fontFamily As New FontFamily(cmbFontFamily.Text)
If fOld Is Nothing Then
Else
rtbData.SelectionFont = New Font(fontFamily, fOld.Size)
Dim fNew As Font = rtbData.SelectionFont
rtbData.SelectionFont = New Font(fNew, fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

'Change font size

Private Sub cmbFontSize_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cmbFontSize.SelectedIndexChanged
Try
Dim fOld As Font = rtbData.SelectionFont
If fOld Is Nothing Then

Else
rtbData.SelectionFont = New Font(fOld.FontFamily,
CSng(cmbFontSize.Text), fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

'Change Bold format

Private Sub cmdBold_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdBold.Click
Dim fOld As Font = rtbData.SelectionFont
If fOld Is Nothing Then

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

'Change Underline format

Private Sub cmdUnderLine_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles cmdUnderLine.Click
Dim fOld As Font = rtbData.SelectionFont
If fOld Is Nothing Then

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

'Change Italic format

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

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

Private Sub rtbData_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rtbData.SelectionChanged
If rtbData.SelectionFont Is Nothing Then Exit Sub
cmbFontFamily.Text = rtbData.SelectionFont.FontFamily.Name
cmbFontSize.Text = rtbData.SelectionFont.Size.ToString
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 UnderLineSelectedText()
Dim intCounter As Integer
For intCounter = rtbData.SelectionStart To rtbData.SelectionStart +
rtbData.SelectionLength - 1
rtbData.Select(intCounter, 1)
Dim fOld As Font = rtbData.SelectionFont
Dim fStyle As FontStyle = fOld.Style + (IIf(fOld.Underline,
FontStyle.Underline * -1, FontStyle.Underline))
rtbData.SelectionFont = New Font(fOld.FontFamily, fOld.Size,
fStyle)
Next
rtbData.SelectionLength = 0
End Sub

Thanks and regards,
Sakharam Phapale
"Sakharam Phapale" <sp******@annetsite.com> wrote in message
news:u%******************@TK2MSFTNGP14.phx.gbl...
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******@annetsite.com)
Subject: Re: How to preserve font properties while changing some other
properties.
Newsgroups: microsoft.public.dotnet.languages.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.Text = "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(FontSize as integer)
Dim fOld As Font = rtbData.SelectionFont

rtbData.SelectionFont = New Font(fOld.FontFamily, 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****************@TK2MSFTNGP12.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****************@tk2msftngp13.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+Underline

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.
InitializeComponent()

'Add any initialization after the InitializeComponent() 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.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'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.RichTextBox
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.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.rtbData = New System.Windows.Forms.RichTextBox()
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.cmbFontFamily = New System.Windows.Forms.ComboBox()
Me.SuspendLayout()
'
'rtbData
'
Me.rtbData.Font = New System.Drawing.Font("Times New Roman",
11.25!,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.rtbData.HideSelection = False
Me.rtbData.Location = New System.Drawing.Point(24, 96)
Me.rtbData.Name = "rtbData"
Me.rtbData.Size = New System.Drawing.Size(592, 248)
Me.rtbData.TabIndex = 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.Point, CType(0, Byte))
Me.cmdBold.Location = New System.Drawing.Point(344, 40)
Me.cmdBold.Name = "cmdBold"
Me.cmdBold.Size = New System.Drawing.Size(24, 24)
Me.cmdBold.TabIndex = 2
Me.cmdBold.Text = "B"
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Times New Roman", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(32, 41)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(80, 24)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Font Name"
'
'cmdUnderLine
'
Me.cmdUnderLine.Font = New System.Drawing.Font("Arial", 12.0!,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.cmdUnderLine.Location = New System.Drawing.Point(376, 40)
Me.cmdUnderLine.Name = "cmdUnderLine"
Me.cmdUnderLine.Size = New System.Drawing.Size(24, 24)
Me.cmdUnderLine.TabIndex = 6
Me.cmdUnderLine.Text = "U"
'
'cmdItalic
'
Me.cmdItalic.Font = New System.Drawing.Font("Arial", 12.0!,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.cmdItalic.Location = New System.Drawing.Point(408, 40)
Me.cmdItalic.Name = "cmdItalic"
Me.cmdItalic.Size = New System.Drawing.Size(24, 24)
Me.cmdItalic.TabIndex = 7
Me.cmdItalic.Text = "I"
'
'cmbFontSize
'
Me.cmbFontSize.Font = New System.Drawing.Font("Times New Roman", 9.75!, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point,
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 = "cmbFontSize"
Me.cmbFontSize.Size = New System.Drawing.Size(56, 23)
Me.cmbFontSize.TabIndex = 21
'
'cmbFontFamily
'
Me.cmbFontFamily.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cmbFontFamily.Font = New System.Drawing.Font("Times New Roman", 9.75!, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.cmbFontFamily.Location = New System.Drawing.Point(120, 40)
Me.cmbFontFamily.Name = "cmbFontFamily"
Me.cmbFontFamily.Size = New System.Drawing.Size(152, 23)
Me.cmbFontFamily.TabIndex = 20
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(640, 365)
Me.Controls.AddRange(New System.Windows.Forms.Control()
{Me.cmbFontSize, Me.cmbFontFamily, 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(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
cmbFontFamily.Items.Clear()
Dim myFontFamily() As FontFamily
Dim objFontFamily As FontFamily
myFontFamily = objFontFamily.Families()
Dim i As Integer
For i = 0 To myFontFamily.GetUpperBound(0)
cmbFontFamily.Items.Add(myFontFamily(i).Name)
Next
cmbFontFamily.SelectedIndex = 0
cmbFontSize.SelectedIndex = 0
End Sub

'Change Font Family

Private Sub cmbFontFamily_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cmbFontFamily.SelectedIndexChanged
Try
Dim fOld As Font = rtbData.SelectionFont
Dim fontFamily As New FontFamily(cmbFontFamily.Text)
If fOld Is Nothing Then
Else
rtbData.SelectionFont = New Font(fontFamily, fOld.Size)
Dim fNew As Font = rtbData.SelectionFont
rtbData.SelectionFont = New Font(fNew, fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

'Change font size

Private Sub cmbFontSize_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cmbFontSize.SelectedIndexChanged
Try
Dim fOld As Font = rtbData.SelectionFont
If fOld Is Nothing Then

Else
rtbData.SelectionFont = New Font(fOld.FontFamily,
CSng(cmbFontSize.Text), fOld.Style)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

'Change Bold format

Private Sub cmdBold_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdBold.Click
Dim fOld As Font = rtbData.SelectionFont
If fOld Is Nothing Then

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

'Change Underline format

Private Sub cmdUnderLine_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdUnderLine.Click
Dim fOld As Font = rtbData.SelectionFont
If fOld Is Nothing Then

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

'Change Italic format

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

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

Private Sub rtbData_SelectionChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles rtbData.SelectionChanged
If rtbData.SelectionFont Is Nothing Then Exit Sub
cmbFontFamily.Text = rtbData.SelectionFont.FontFamily.Name
cmbFontSize.Text = rtbData.SelectionFont.Size.ToString
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****************@TK2MSFTNGP10.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****************@TK2MSFTNGP10.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
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
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
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...
4
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...
3
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() ...
0
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...
0
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 =...
6
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.