vb.net安裝字體 vb設(shè)置字體代碼

(*高分尋求*)有關(guān)vb.net的字體設(shè)置的小小問題。多多指教!先謝謝啦!!

'新建一個(gè)VB.NET 項(xiàng)目,把原來所有代碼刪了,把下面的代碼復(fù)制貼上去解OK了

創(chuàng)新互聯(lián)公司專注于企業(yè)營銷型網(wǎng)站建設(shè)、網(wǎng)站重做改版、臨江網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5建站、商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為臨江等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

Public Class Form1

Inherits System.Windows.Forms.Form

#Region " Windows 窗體設(shè)計(jì)器生成的代碼 "

Public Sub New()

MyBase.New()

'該調(diào)用是 Windows 窗體設(shè)計(jì)器所必需的。

InitializeComponent()

'在 InitializeComponent() 調(diào)用之后添加任何初始化

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 窗體設(shè)計(jì)器所必需的

Private components As System.ComponentModel.IContainer

'注意: 以下過程是 Windows 窗體設(shè)計(jì)器所必需的

'可以使用 Windows 窗體設(shè)計(jì)器修改此過程。

'不要使用代碼編輯器修改它。

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 = "藍(lán)色"

'

'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 = "字號(hào)"

'

'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號(hào)"

'

'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號(hào)"

'

'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使能不能內(nèi)嵌字體?

我們寫exe程序時(shí),默認(rèn)字體是宋體,比較難看,指定了其他字體,但是其他用戶上沒有你指定的這個(gè)字體的話,也會(huì)變成默認(rèn)的宋體。解決的辦法有這么幾個(gè):

1,叫用戶安裝相應(yīng)字體,這個(gè)基本不可能實(shí)現(xiàn),因?yàn)闆]有幾個(gè)人會(huì)進(jìn)行這樣的操作;

2,給用戶安裝相應(yīng)字體,這個(gè)辦法可行,在制作安裝包時(shí)將字體打包進(jìn)去,然后用戶安裝程序的時(shí)候連字體也一并安裝上去,一勞永逸;

3,把字體導(dǎo)入到程序資源中,讓程序直接調(diào)用字體資源,缺點(diǎn)是導(dǎo)致程序體積巨大;

4,將字體文件放到程序目錄里,在程序里單獨(dú)調(diào)用。

個(gè)人覺得第4種辦法比較方便,所以決定采用這種方法,把代碼寫出來給需要的同學(xué)。

引用:

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)

'設(shè)置窗體控件字體,哪些控件要更改都寫到下面

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程序?qū)⒁阅J(rèn)字體顯示", "警告",

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

end try

然后在public sub Form1()

InitializeComponent()

Setfont() '啟動(dòng)字體設(shè)置函數(shù)

end sub

vb.net注冊(cè)字體問題

在給所有頂層窗口發(fā)送消息之前需要在注冊(cè)表中記錄字體:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts

否則是無法顯示在系統(tǒng)的字體列表中的。

vb.net GDI ,不是系統(tǒng)的字體,是工程目錄下的字體文件

GDI繪圖用字體必須安裝才能使用

在客戶機(jī)部署應(yīng)用程序時(shí),安裝該字體就行

網(wǎng)頁標(biāo)題:vb.net安裝字體 vb設(shè)置字體代碼
當(dāng)前URL:http://muchs.cn/article24/doeecce.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動(dòng)態(tài)網(wǎng)站、ChatGPT、虛擬主機(jī)關(guān)鍵詞優(yōu)化、靜態(tài)網(wǎng)站Google

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站