fontを設定する 斜体 太字 取り消し線 下線 


テキストボックスに文字を入力してCheckBoxでfontを設定する
form
テキストボックスはMultLineにすると複数行にすることができます。
テキストボックス2に数値を入力してフォーカスアウトすると指定したサイズに変更できる。
大きな数字を入力すると大きすぎるので表示は画面では確認できない。
IsNumericは1e1とするとバグるが今回は気にしないことにする。

TextBox1.Font.Boldはリードオンリーであり設定には使えない。
状態を見たりすることはできる。
サンプルソース
—————————————————————————————————————
Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If TextBox1.Font.Bold = False Then
MessageBox.Show(“boldは設定されていません”)
End If
End Sub
End Class
—————————————————————————————————————

サンプルソース
—————————————————————————————————————
Public Class Form1

Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style Xor FontStyle.Bold)
End Sub

Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged
TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style Xor FontStyle.Italic)
End Sub

Private Sub CheckBox3_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox3.CheckedChanged
TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style Xor FontStyle.Underline)
End Sub

Private Sub CheckBox4_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox4.CheckedChanged
TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style Xor FontStyle.Underline)
End Sub

Private Sub TextBox2_LostFocus(sender As Object, e As EventArgs) Handles TextBox2.LostFocus
If TextBox2.Text <> “” And IsNumeric(TextBox2.Text) Then
TextBox1.Font = New Font(“MS UI Gothic”, CSng(TextBox2.Text), FontStyle.Regular)
End If

End Sub

End Class
—————————————————————————————————————

シェアする

  • このエントリーをはてなブックマークに追加

フォローする

Translate »