vb.net 更改字体名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18269918/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 14:42:08  来源:igfitidea点击:

Changing font name

vb.netfonts

提问by user2169140

in vb.net ,I have a rich text box for write text and a combo box for font names. i added fonts to combo box with this code:

在 vb.net 中,我有一个用于写入文本的富文本框和一个用于字体名称的组合框。我使用以下代码将字体添加到组合框中:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim ff As FontFamily
    For Each ff In System.Drawing.FontFamily.Families
        FontName.Items.Add(ff.Name)
    Next
End Sub

But i don't know, how to change the font name of the rich text box.

但我不知道,如何更改富文本框的字体名称。

回答by varocarbas

You have to use the code below:

您必须使用以下代码:

RichTextBox1.Font = New Font("Font Name", size)

Adapt it to your specific conditions: replace RichTextBox1with your RichTextBox, "Font Name" with the given item of your ComboBox FontName, sizewith the size you want (it might be the current one, that is, RichTextBox1.Font.Size).

使其适应您的特定条件:将RichTextBox1您的 RichTextBox、“字体名称”替换为 ComboBox 的给定项目FontNamesize以及您想要的大小(它可能是当前的大小,即RichTextBox1.Font.Size)。

回答by Jonathon Cowley-Thom

Font.Name is read only, but Font is not. So I'd do this:

Font.Name 是只读的,但 Font 不是。所以我会这样做:

TextBox1.Font = New Font(FontName.Text, 26.0, FontStyle.Regular)

TextBox1.Font = New Font(FontName.Text, 26.0, FontStyle.Regular)

Size and style could be hard-coded, or could be filled from their own combo boxes. Put that code in whatever event-driven sub you're using for the user having selected from the combo box (e.g SelectedValue changed)

大小和样式可以是硬编码的,也可以从它们自己的组合框中填充。将该代码放在您为从组合框中选择的用户使用的任何事件驱动子中(例如 SelectedValue 已更改)

回答by VB.NET LEARNER

RichTextBox.Font = New Font(FontName.Text, 10, FontStyle.Regular)

回答by Mohamed ELgendy

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim ff As FontFamily
    For Each ff In System.Drawing.FontFamily.Families
        FontName.Items.Add(ff.Name)
    Next

End Sub