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 7 2851
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
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
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
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
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
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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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;
|
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))
|
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...
|
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...
|
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()
...
|
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...
|
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 =...
|
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...
|
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...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
| |