vb.net安装字体 vb中字体

VB.NET,Richtextbox的bold设置

斜粗体是用 Or 合并;

合水网站制作公司哪家好,找成都创新互联!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设等网站项目制作,到程序开发,运营维护。成都创新互联于2013年成立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联

Ft = New Font("宋体", 9.0!, CType((FontStyle.Bold Or FontStyle.Italic), FontStyle))

也可以在设定粗体前先保存原有字体,可以方便还原;

Private OldFont As Font '旧的字体

OldFont = RichTextBox1.SelectionFont '保存当前字体 

RichTextBox1.SelectionFont = New Font("宋体", 9.0!, FontStyle.Bold) '9号加粗宋体

换回原来的字体;

RichTextBox1.SelectionFont = OldFont '设定回原来的字体

vb.net GDI ,不是系统的字体,是工程目录下的字体文件

GDI绘图用字体必须安装才能使用

在客户机部署应用程序时,安装该字体就行

VB.net使能不能内嵌字体?

我们写exe程序时,默认字体是宋体,比较难看,指定了其他字体,但是其他用户上没有你指定的这个字体的话,也会变成默认的宋体。解决的办法有这么几个:

1,叫用户安装相应字体,这个基本不可能实现,因为没有几个人会进行这样的操作;

2,给用户安装相应字体,这个办法可行,在制作安装包时将字体打包进去,然后用户安装程序的时候连字体也一并安装上去,一劳永逸;

3,把字体导入到程序资源中,让程序直接调用字体资源,缺点是导致程序体积巨大;

4,将字体文件放到程序目录里,在程序里单独调用。

个人觉得第4种办法比较方便,所以决定采用这种方法,把代码写出来给需要的同学。

引用:

Imports System.Drawing.Text

public sub Setfont()

dim AppPath as string = Application.StartupPath

try

dim font1 as PrivateFontCollection = new PrivateFontCollection()

font1.AddFontFile(AppPath + "\font\msyh.ttf") '字体的路径及名字

dim myFont as Font = new Font(font.Families[0].Name, 9,FontStyle.Regular,GraphicsUnit.Point, 134)

'设置窗体控件字体,哪些控件要更改都写到下面

label1.Font = myFont

label2.Font = myFont

label3.Font = myFont

button1.Font = myFont

button2.Font = myFont

button3.Font = myFont

button4.Font = myFont

button5.Font = myFont

catch e as exception

MessageBox.Show("字体不存在或加载失败\n程序将以默认字体显示", "警告",

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

end try

然后在public sub Form1()

InitializeComponent()

Setfont() '启动字体设置函数

end sub

VB.NET 数值怎么转换为字体

可以使用GetItemText

方法:返回指定项的文本表示形式。使用形式如下:

GetItemText(item)

vb.net如何检查系统版本和系统里是否装有微软雅黑字体??

Private Sub Form_Load()

r=Dir(C:\WINDOWS\Fonts\微软雅黑.ttf) ‘在C盘WINDOWS文件夹fonts中查找微软雅黑

If r""then

...(...填入)确认文件存在

Else

...(...填入)确认文件不存在

End if

End Sub

(*高分寻求*)有关vb.net的字体设置的小小问题。多多指教!先谢谢啦!!

'新建一个VB.NET 项目,把原来所有代码删了,把下面的代码复制贴上去解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)

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 = "话说天下大势,分久必合,合久必分。"

'

'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中字体
当前链接:http://azwzsj.com/article/doccoii.html