Post by bobowk on Jun 26, 2016 16:31:24 GMT 10
0
When I click bold for the first time and type text and change the text size the text goes to ftontstyle.regular
ALTHOUGH! When I type text, highlight it and then bold it and change the size it stays bold... Here is my whole forms code so you see
ALTHOUGH! When I type text, highlight it and then bold it and change the size it stays bold... Here is my whole forms code so you see
Option Strict On
Imports System.Drawing.Font
Imports System.Drawing.FontFamily
Imports System.Drawing.FontConverter
Imports System.Runtime.InteropServices
Imports System.Windows.Controls
Imports NetSpell.SpellChecker
Public Class Form1
Dim CurrentFont As FontFamily
Dim CurrentSize As Single
Dim CurrentForeColor As Color
Dim Docname As String
Private Sub Combofont()
'Function to load fonts into ComboBox
ComboBox1.DrawMode = DrawMode.OwnerDrawFixed
ComboBox1.Font = New Font("Verdana, 10pt", 10)
Dim objFontFamily As FontFamily
Dim objFontCollection As System.Drawing.Text.FontCollection
objFontCollection = New System.Drawing.Text.InstalledFontCollection()
For Each objFontFamily In objFontCollection.Families
ComboBox1.Items.Add(objFontFamily.Name)
Next
End Sub
Private Sub ComboBox1_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
'Draws the fonts to the ComboBox
e.DrawBackground()
If (e.State And DrawItemState.Focus) <> 0 Then
e.DrawFocusRectangle()
End If
Dim objBrush As Brush = Nothing
Try
objBrush = New SolidBrush(e.ForeColor)
Dim _FontName As String = CStr(ComboBox1.Items(e.Index))
Dim _font As Font
Dim _fontfamily = New FontFamily(_FontName)
If _fontfamily.IsStyleAvailable(FontStyle.Regular) Then
_font = New Font(_fontfamily, 10, FontStyle.Regular)
ElseIf _fontfamily.IsStyleAvailable(FontStyle.Bold) Then
_font = New Font(_fontfamily, 10, FontStyle.Bold)
ElseIf _fontfamily.IsStyleAvailable(FontStyle.Italic) Then
_font = New Font(_fontfamily, 10, FontStyle.Italic)
End If
e.Graphics.DrawString(_FontName, _font, objBrush, e.Bounds)
Catch ex As Exception
Finally
If objBrush IsNot Nothing Then
objBrush.Dispose()
End If
objBrush = Nothing
End Try
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
RichTextBox1.SelectionFont = New Font(ComboBox1.Text, CInt(ComboBox2.Text), RichTextBox1.SelectionFont.Style)
CFS()
End Sub
Private Sub ComboBox1_SelectedValueChanged(sender As Object, e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Combofont()
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont.FontFamily, CInt(ComboBox2.Text), RichTextBox1.SelectionFont.Style)
CFS()
End Sub
Public Sub CFS()
Try
CurrentFont = RichTextBox1.SelectionFont.FontFamily
CurrentForeColor = RichTextBox1.SelectionColor
CurrentSize = RichTextBox1.SelectionFont.Size
ComboBox1.Text = CurrentFont.Name.ToString
ComboBox2.Text = CurrentSize.ToString
If RichTextBox1.SelectionFont.Style = FontStyle.Bold Then
ButtonBold.BackColor = Color.Gainsboro
Else
ButtonBold.BackColor = Color.WhiteSmoke
End If
If RichTextBox1.SelectionFont.Style = FontStyle.Italic Then
ButtonItalic.BackColor = Color.Gainsboro
Else
ButtonItalic.BackColor = Color.WhiteSmoke
End If
If RichTextBox1.SelectionFont.Style = FontStyle.Underline Then
ButtonUnderlined.BackColor = Color.Gainsboro
Else
ButtonUnderlined.BackColor = Color.WhiteSmoke
End If
If RichTextBox1.SelectionFont.Style = FontStyle.Strikeout Then
ButtonStrikeout.BackColor = Color.Gainsboro
Else
ButtonStrikeout.BackColor = Color.WhiteSmoke
End If
Panel2.BackColor = RichTextBox1.SelectionColor
If RichTextBox1.SelectionAlignment = HorizontalAlignment.Left Then
ButtonLeft.BackColor = Color.Gainsboro
Else
ButtonLeft.BackColor = Color.WhiteSmoke
End If
If RichTextBox1.SelectionAlignment = HorizontalAlignment.Center Then
ButtonCenter.BackColor = Color.Gainsboro
Else
ButtonCenter.BackColor = Color.WhiteSmoke
End If
If RichTextBox1.SelectionAlignment = HorizontalAlignment.Right Then
ButtonRight.BackColor = Color.Gainsboro
Else
ButtonRight.BackColor = Color.WhiteSmoke
End If
Catch ex As Exception
End Try
End Sub
Public Sub UpdateProperties()
'Updates the properties for the selected text
Try
CurrentFont = RichTextBox1.SelectionFont.FontFamily
CurrentForeColor = RichTextBox1.SelectionColor
CurrentSize = RichTextBox1.SelectionFont.Size
ColorDialog1.Color = CurrentForeColor
Panel2.BackColor = RichTextBox1.SelectionColor
If RichTextBox1.SelectionFont.Style = FontStyle.Bold Then
ButtonBold.BackColor = Color.Gainsboro
Else
ButtonBold.BackColor = Color.WhiteSmoke
End If
If RichTextBox1.SelectionFont.Style = FontStyle.Italic Then
ButtonItalic.BackColor = Color.Gainsboro
Else
ButtonItalic.BackColor = Color.WhiteSmoke
End If
If RichTextBox1.SelectionFont.Style = FontStyle.Underline Then
ButtonUnderlined.BackColor = Color.Gainsboro
Else
ButtonUnderlined.BackColor = Color.WhiteSmoke
End If
If RichTextBox1.SelectionFont.Style = FontStyle.Strikeout Then
ButtonStrikeout.BackColor = Color.Gainsboro
Else
ButtonStrikeout.BackColor = Color.WhiteSmoke
End If
If RichTextBox1.SelectionAlignment = HorizontalAlignment.Left Then
ButtonLeft.BackColor = Color.Gainsboro
Else
ButtonLeft.BackColor = Color.WhiteSmoke
End If
If RichTextBox1.SelectionAlignment = HorizontalAlignment.Center Then
ButtonCenter.BackColor = Color.Gainsboro
Else
ButtonCenter.BackColor = Color.WhiteSmoke
End If
If RichTextBox1.SelectionAlignment = HorizontalAlignment.Right Then
ButtonRight.BackColor = Color.Gainsboro
Else
ButtonRight.BackColor = Color.WhiteSmoke
End If
Catch ex As Exception
End Try
End Sub
Private Sub ButtonBold_Click(sender As System.Object, e As System.EventArgs) Handles ButtonBold.Click
Dim font_style_set As New Font(RichTextBox1.SelectionFont, RichTextBox1.SelectionFont.Style Xor FontStyle.Bold)
If RichTextBox1.SelectionFont IsNot Nothing Then
RichTextBox1.SelectionFont = font_style_set
If ButtonBold.BackColor = Color.WhiteSmoke Then
ButtonBold.BackColor = Color.Gainsboro
Else
ButtonBold.BackColor = Color.WhiteSmoke
End If
Else
RichTextBox1.SelectionFont = font_style_set
If ButtonBold.BackColor = Color.WhiteSmoke Then
ButtonBold.BackColor = Color.Gainsboro
Else
ButtonBold.BackColor = Color.WhiteSmoke
End If
End If
End Sub
Private Sub ButtonItalic_Click(sender As System.Object, e As System.EventArgs) Handles ButtonItalic.Click
Dim font_style_set As New Font(RichTextBox1.SelectionFont, RichTextBox1.SelectionFont.Style Xor FontStyle.Italic)
RichTextBox1.SelectionFont = font_style_set
If ButtonItalic.BackColor = Color.WhiteSmoke Then
ButtonItalic.BackColor = Color.Gainsboro
Else
ButtonItalic.BackColor = Color.WhiteSmoke
End If
End Sub
Private Sub ButtonUnderlined_Click(sender As System.Object, e As System.EventArgs) Handles ButtonUnderlined.Click
Dim font_style_set As New Font(RichTextBox1.SelectionFont, RichTextBox1.SelectionFont.Style Xor FontStyle.Underline)
RichTextBox1.SelectionFont = font_style_set
If ButtonUnderlined.BackColor = Color.WhiteSmoke Then
ButtonUnderlined.BackColor = Color.Gainsboro
Else
ButtonUnderlined.BackColor = Color.WhiteSmoke
End If
End Sub
Private Sub ButtonStrikeout_Click(sender As System.Object, e As System.EventArgs) Handles ButtonStrikeout.Click
Dim font_style_set As New Font(RichTextBox1.SelectionFont, RichTextBox1.SelectionFont.Style Xor FontStyle.Strikeout)
RichTextBox1.SelectionFont = font_style_set
If ButtonStrikeout.BackColor = Color.WhiteSmoke Then
ButtonStrikeout.BackColor = Color.Gainsboro
Else
ButtonStrikeout.BackColor = Color.WhiteSmoke
End If
End Sub
Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
End Sub
Private Sub RichTextBox1_SelectionChanged(sender As Object, e As EventArgs)
CFS()
End Sub
Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
CurrentForeColor = ColorDialog1.Color
RichTextBox1.SelectionColor = CurrentForeColor
UpdateProperties()
End If
UpdateProperties()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs)
End Sub
Private Sub ButtonLeft_Click(sender As Object, e As EventArgs) Handles ButtonLeft.Click
RichTextBox1.SelectionAlignment = HorizontalAlignment.Left
UpdateProperties()
End Sub
Private Sub ButtonCenter_Click(sender As Object, e As EventArgs) Handles ButtonCenter.Click
RichTextBox1.SelectionAlignment = HorizontalAlignment.Center
UpdateProperties()
End Sub
Private Sub ButtonRight_Click(sender As Object, e As EventArgs) Handles ButtonRight.Click
RichTextBox1.SelectionAlignment = HorizontalAlignment.Right
UpdateProperties()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Spelling1.Text = RichTextBox1.Text
ToolStripLabel1.Text = "WordCount : " & Spelling1.WordCount.ToString
End Sub
Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
Spelling1.Text = RichTextBox1.Text
Spelling1.SpellCheck()
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
End Sub
Private Sub PrintToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PrintToolStripMenuItem.Click
PrintDialog1.ShowDialog()
End Sub
Private Sub PrintPreviewToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PrintPreviewToolStripMenuItem.Click
PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
End Sub
End Class
Last Edit: Jul 17, 2016 22:09:20 GMT 10 by Nathan Lecompte