Friday, September 20, 2013

Color and Font Style


Target: 
Enter text on textbox and change the color and font style using Radio Button for Font Color and Checkbox for Font Style. 


Parts: 




Codes: 

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


Public Class frmForm1


"CHECK BOXES'
    Private Sub CheckBox1_CheckedChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkBold.CheckedChanged

      txtRichTextBox1.SelectionFont = New Font (txtRichTextBox1.Font, txtRichTextBox1.SelectionFont.Style Xor FontStyle.Bold)
End Sub



    Private Sub CheckBox2_CheckedChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkItalic.CheckedChanged

     txtRichTextBox1.SelectionFont = New Font (txtRichTextBox1.Font. txtRichTextBox1.SelectionFont.Style Xor FontStyle.Italic)
End Sub


    Private Sub CheckBox3_CheckedChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkUnderlined.CheckedChanged

      txtRichTextBox1.SelectionFont = New Font(txtRichTextBox1.Font, txtRichTextBox1.SelectionFont.Style Xor FontStyle.Underline)
End Sub


    Private Sub CheckBox4_CheckedChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkStrikeout.CheckedChanged

        txtRichTextBox1.SelectionFont = New Font(txtRichTextBox1.Font, txtRichTextBox1.SelectionFont.Style Xor FontStyle.Strikeout)
End Sub



'Radio Buttons'
    Private Sub RadioButton1_CheckedChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radRed.CheckedChanged


        txtRichTextBox1.SelectAll()
        txtRichTextBox1.SelectionColor = Color.Red
 End Sub


    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radBlue.CheckedChanged
        txtRichTextBox1.SelectAll()
        txtRichTextBox1.SelectionColor = Color.Blue
  End Sub


    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radGreen.CheckedChanged
        txtRichTextBox1.SelectAll()
        txtRichTextBox1.SelectionColor = Color.Green
End Sub


    Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radOrange.CheckedChanged
        txtRichTextBox1.SelectAll()
        txtRichTextBox1.SelectionColor = Color.Orange
End Sub


    Private Sub  RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radBlack.CheckedChanged
        txtRichTextBox1.SelectAll()
        txtRichTextBox1.SelectionColor = Color.Black
End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub


    Private Sub txtRichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRichTextBox1.TextChanged

    End Sub
End Class

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

Test it! 

No comments:

Post a Comment