vbnet怎么设置字体 vb设置字体为宋体的代码

VB.NET文本框中的文本格式进行相应的设置太晚了,想不出什么好方法了 。
发上来看看吧 。
首先建立一个TextBox,我这里名字为TextBox2
然后放一个groupbox,在里头放两个Checkbox,checkbox1为粗体,checkbox2为斜体 。
代码:
Dim Bold As Boolean
Dim Italic As Boolean
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
Bold = True
If Italic Then
TextBox2.Font = New Font(TextBox2.Font, FontStyle.Bold Or FontStyle.Italic)
Else
TextBox2.Font = New Font(TextBox2.Font, FontStyle.Bold)
End If
Else
Bold = False
If Italic Then
TextBox2.Font = New Font(TextBox2.Font, FontStyle.Italic)
Else
TextBox2.Font = New Font(TextBox2.Font, 0)
End If
End If
End Sub
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
If CheckBox2.Checked Then
Italic = True
If Bold Then
TextBox2.Font = New Font(TextBox2.Font, FontStyle.Italic Or FontStyle.Bold)
Else
TextBox2.Font = New Font(TextBox2.Font, FontStyle.Italic)
End If
Else
Italic = False
If Bold Then
TextBox2.Font = New Font(TextBox2.Font, FontStyle.Bold)
Else
TextBox2.Font = New Font(TextBox2.Font, 0)
End If
End If
End Sub
可以等等别人回答 , 看看有没有更好的方法 。
VB.NET,如何用代码实现改变字体、颜色、加粗,以及恢复默认?1、2和3:你怎么改的,就怎么恢复默认
3:textbox1.font=new font(字体名称,字体大?。中? , 字形有加粗常规倾斜下划线等几种 。
(*高分寻求*)有关vb.net的字体设置的小小问题 。多多指教!先谢谢啦?。?/h2>'新建一个VB.NET 项目vbnet怎么设置字体 , 把原来所有代码删vbnet怎么设置字体了vbnet怎么设置字体,把下面vbnet怎么设置字体的代码复制贴上去解OK了
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的 。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表 。
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)
【vbnet怎么设置字体 vb设置字体为宋体的代码】End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程 。
'不要使用代码编辑器修改它 。
Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
Friend WithEvents RadioButton3 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton4 As System.Windows.Forms.RadioButton
Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
Friend WithEvents CheckBox2 As System.Windows.Forms.CheckBox
Friend WithEvents CheckBox3 As System.Windows.Forms.CheckBox
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
System.Diagnostics.DebuggerStepThrough() Private Sub InitializeComponent()
Me.RadioButton1 = New System.Windows.Forms.RadioButton
Me.RadioButton2 = New System.Windows.Forms.RadioButton
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.GroupBox2 = New System.Windows.Forms.GroupBox
Me.RadioButton3 = New System.Windows.Forms.RadioButton
Me.RadioButton4 = New System.Windows.Forms.RadioButton
Me.CheckBox1 = New System.Windows.Forms.CheckBox
Me.CheckBox2 = New System.Windows.Forms.CheckBox
Me.CheckBox3 = New System.Windows.Forms.CheckBox
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.GroupBox1.SuspendLayout()
Me.GroupBox2.SuspendLayout()
Me.SuspendLayout()
'
'RadioButton1
'
Me.RadioButton1.Location = New System.Drawing.Point(16, 24)
Me.RadioButton1.Name = "RadioButton1"
Me.RadioButton1.Size = New System.Drawing.Size(56, 24)
Me.RadioButton1.TabIndex = 1
Me.RadioButton1.Text = "红色"
'
'RadioButton2
'
Me.RadioButton2.Location = New System.Drawing.Point(72, 24)
Me.RadioButton2.Name = "RadioButton2"
Me.RadioButton2.Size = New System.Drawing.Size(48, 24)
Me.RadioButton2.TabIndex = 2
Me.RadioButton2.Text = "蓝色"
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.RadioButton2)
Me.GroupBox1.Controls.Add(Me.RadioButton1)
Me.GroupBox1.Location = New System.Drawing.Point(16, 144)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(128, 56)
Me.GroupBox1.TabIndex = 5
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "颜色"
'
'GroupBox2
'
Me.GroupBox2.Controls.Add(Me.RadioButton3)
Me.GroupBox2.Controls.Add(Me.RadioButton4)
Me.GroupBox2.Location = New System.Drawing.Point(176, 144)
Me.GroupBox2.Name = "GroupBox2"
Me.GroupBox2.Size = New System.Drawing.Size(136, 56)
Me.GroupBox2.TabIndex = 6
Me.GroupBox2.TabStop = False
Me.GroupBox2.Text = "字号"
'
'RadioButton3
'
Me.RadioButton3.Location = New System.Drawing.Point(16, 24)
Me.RadioButton3.Name = "RadioButton3"
Me.RadioButton3.Size = New System.Drawing.Size(56, 24)
Me.RadioButton3.TabIndex = 2
Me.RadioButton3.Text = "30号"
'
'RadioButton4
'
Me.RadioButton4.Location = New System.Drawing.Point(72, 24)
Me.RadioButton4.Name = "RadioButton4"
Me.RadioButton4.Size = New System.Drawing.Size(48, 24)
Me.RadioButton4.TabIndex = 1
Me.RadioButton4.Text = "40号"
'
'CheckBox1
'
Me.CheckBox1.Location = New System.Drawing.Point(32, 208)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.Size = New System.Drawing.Size(80, 32)
Me.CheckBox1.TabIndex = 7
Me.CheckBox1.Text = "加粗"
'
'CheckBox2
'
Me.CheckBox2.Location = New System.Drawing.Point(120, 208)
Me.CheckBox2.Name = "CheckBox2"
Me.CheckBox2.Size = New System.Drawing.Size(80, 32)
Me.CheckBox2.TabIndex = 8
Me.CheckBox2.Text = "斜体"
'
'CheckBox3
'
Me.CheckBox3.Location = New System.Drawing.Point(200, 208)
Me.CheckBox3.Name = "CheckBox3"
Me.CheckBox3.Size = New System.Drawing.Size(80, 32)
Me.CheckBox3.TabIndex = 9
Me.CheckBox3.Text = "下划线"
'
'TextBox1
'
Me.TextBox1.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.TextBox1.Location = New System.Drawing.Point(8, 16)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.TextBox1.Size = New System.Drawing.Size(320, 112)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "话说天下大势vbnet怎么设置字体,分久必合,合久必分 。"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(88, 256)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(152, 32)
Me.Button1.TabIndex = 10
Me.Button1.Text = "确定"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(336, 310)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.CheckBox3)
Me.Controls.Add(Me.CheckBox2)
Me.Controls.Add(Me.CheckBox1)
Me.Controls.Add(Me.GroupBox2)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.TextBox1)
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Form1"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox2.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Me.RadioButton1.Checked = True Then Me.TextBox1.ForeColor = System.Drawing.Color.Red
If Me.RadioButton2.Checked = True Then Me.TextBox1.ForeColor = System.Drawing.Color.Blue
If Me.RadioButton3.Checked = True Then Me.TextBox1.Font = New Font("宋体", 30)
If Me.RadioButton4.Checked = True Then Me.TextBox1.Font = New Font("宋体", 40)
Dim style As FontStyle = FontStyle.Regular
If Me.CheckBox1.Checked = True Then style = style Or FontStyle.Bold
If Me.CheckBox2.Checked = True Then style = style Or FontStyle.Italic
' If Me.CheckBox1.Checked = True And Me.CheckBox2.Checked = True Then TextBox1.Font = New Font(TextBox1.Font, FontStyle.Bold Or FontStyle.Italic)
If Me.CheckBox3.Checked = True Then style = style Or FontStyle.Underline
Me.TextBox1.Font = New Font(TextBox1.Font, style)
End Sub
End Class
如何设置VB.NET中代码的字体大小,和是否换行 , 这些选项在哪里?没有自动换行,因为VB语句不能随便换行,字体可以设置,点菜单-》工具-》选项-》字体和颜色
vb.net 关于配置文件和修改richtextbox字体跟配置文件没有关系 。
只是要求把你更改后的字体大小保存到一个文件内(文本或APP.CONFIG)
然后读取出来
如果是配置文件的话
参考
System.Configuration.ConfigurationManager
关于vbnet怎么设置字体和vb设置字体为宋体的代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读