Change TextBox font by RadioButton and CheckBox : TextBox « GUI « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net Tutorial » GUI » TextBox 
14.23.8.Change TextBox font by RadioButton and CheckBox
Change TextBox font by RadioButton and CheckBox
Imports System.Windows.Forms

public class RadioButtonControlFont
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class


Public Class Form1
    Public mysize As Integer
    Public mybold As Boolean
    Public myItalic As Boolean

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        CheckBox1.Checked = 1
    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgsHandles CheckBox1.CheckedChanged
        myItalic = Not myItalic
        TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Regular)
        If myItalic And mybold Then
            TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Italic)

        ElseIf myItalic Then
            TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Italic)
        ElseIf mybold Then

            TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Bold)
        End If

    End Sub

    Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgsHandles GroupBox1.Enter

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgsHandles MyBase.Load
        mybold = False
        myItalic = False
        mysize = 25

    End Sub

    Private Sub RadioButton1_CheckedChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgsHandles RadioButton1.CheckedChanged
        mysize = 36
        TextBox1.Font = New System.Drawing.Font("", mysize)

    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgsHandles RadioButton2.CheckedChanged
        mysize = 25
        TextBox1.Font = New System.Drawing.Font("", mysize)

    End Sub

    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgsHandles CheckBox2.CheckedChanged
        mybold = Not mybold
        TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Regular)
        If myItalic And mybold Then
            TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Bold)
        ElseIf myItalic Then
            TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Italic)
        ElseIf mybold Then
            TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Bold)
        End If

    End Sub
End Class
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        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.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.CheckBox1 = New System.Windows.Forms.CheckBox
        Me.CheckBox2 = New System.Windows.Forms.CheckBox
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.RadioButton1 = New System.Windows.Forms.RadioButton
        Me.RadioButton2 = New System.Windows.Forms.RadioButton
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'CheckBox1
        '
        Me.CheckBox1.AutoSize = True
        Me.CheckBox1.Location = New System.Drawing.Point(23034)
        Me.CheckBox1.Name = "CheckBox1"
        Me.CheckBox1.Size = New System.Drawing.Size(4816)
        Me.CheckBox1.TabIndex = 1
        Me.CheckBox1.Text = "Italic"
        Me.CheckBox1.UseVisualStyleBackColor = True
        '
        'CheckBox2
        '
        Me.CheckBox2.AutoSize = True
        Me.CheckBox2.Location = New System.Drawing.Point(23056)
        Me.CheckBox2.Name = "CheckBox2"
        Me.CheckBox2.Size = New System.Drawing.Size(4816)
        Me.CheckBox2.TabIndex = 2
        Me.CheckBox2.Text = "Bold"
        Me.CheckBox2.UseVisualStyleBackColor = True
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.RadioButton2)
        Me.GroupBox1.Controls.Add(Me.RadioButton1)
        Me.GroupBox1.Location = New System.Drawing.Point(22485)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(13277)
        Me.GroupBox1.TabIndex = 3
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Font size"
        '
        'RadioButton1
        '
        Me.RadioButton1.AutoSize = True
        Me.RadioButton1.Location = New System.Drawing.Point(620)
        Me.RadioButton1.Name = "RadioButton1"
        Me.RadioButton1.Size = New System.Drawing.Size(5916)
        Me.RadioButton1.TabIndex = 1
        Me.RadioButton1.TabStop = True
        Me.RadioButton1.Text = "Larger font"
        Me.RadioButton1.UseVisualStyleBackColor = True
        '
        'RadioButton2
        '
        Me.RadioButton2.AutoSize = True
        Me.RadioButton2.Location = New System.Drawing.Point(642)
        Me.RadioButton2.Name = "RadioButton2"
        Me.RadioButton2.Size = New System.Drawing.Size(5916)
        Me.RadioButton2.TabIndex = 2
        Me.RadioButton2.TabStop = True
        Me.RadioButton2.Text = "Smaller font"
        Me.RadioButton2.UseVisualStyleBackColor = True
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(1212)
        Me.TextBox1.Multiline = True
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(195150)
        Me.TextBox1.TabIndex = 4
        Me.TextBox1.Text = "www.java2s.com"
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(368174)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.CheckBox2)
        Me.Controls.Add(Me.CheckBox1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
    Friend WithEvents CheckBox2 As System.Windows.Forms.CheckBox
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

End Class
14.23.TextBox
14.23.1.Get input from TextBox and Set to LabelGet input from TextBox and Set to Label
14.23.2.Convert input value in a TextFieldConvert input value in a TextField
14.23.3.Inherit TextBox to create custom control based on TextBox
14.23.4.Display text file in a TextBoxDisplay text file in a TextBox
14.23.5.Numeric TextBoxNumeric TextBox
14.23.6.TextBox Text Changed EventTextBox Text Changed Event
14.23.7.Comprehensive Demo for TextBoxComprehensive Demo for TextBox
14.23.8.Change TextBox font by RadioButton and CheckBoxChange TextBox font by RadioButton and CheckBox
14.23.9.Get selected text in TextBoxGet selected text in TextBox
14.23.10.Create PasswordField by setting the TextBox.PasswordCharCreate PasswordField by setting the TextBox.PasswordChar
14.23.11.Copy selection text from a TextBox and paste to anotherCopy selection text from a TextBox and paste to another
14.23.12.Multiline Text BoxesMultiline Text Boxes
14.23.13.Disable TextBox Context MenuDisable TextBox Context Menu
14.23.14.Save text in TextBox to a file
14.23.15.Handles the Click event of a Button to change the background color of a TextBox.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.