vb2010设置label字体大小的代码

wuguiwu 2012-12-01 11:56:13
你好,我使用的是vs2010中的Visual Basic,(项目:windows窗体应用程序)我想通过代码,改变label1字体的大小
该如何写呢?
...全文
1191 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuguiwu 2012-12-04
  • 打赏
  • 举报
回复
谢谢,问题解决了
c_cyd2008 2012-12-03
  • 打赏
  • 举报
回复
引用 2 楼 chenjl1031 的回复:
可以的。不过VB.net真麻烦,Label1.Font.Name和Label1.Font.Size只能取得属性值,不能设置,仅读属性,还是VB6好用。 VB.net要通过实例化对象才能实现,真麻烦: Visual Basic code ? 123456789101112131415161718192021222324252627282930313233343536373……
其实没必要每个参数都重新指定,用原来字体的就行了,这里只改变大小Size + 10

        With Label1.Font
            Label1.Font = New System.Drawing.Font(.FontFamily, .Size + 10, .Style, .Unit)
        End With
bcrun 2012-12-03
  • 打赏
  • 举报
回复
同意楼上,我初接触.net时,最感到意外的是,经常把以前要用一两句话能做到改成要用一堆东西实现的,从这个角度看对其普及不表乐观
东方之珠 2012-12-03
  • 打赏
  • 举报
回复
可以的。不过VB.net真麻烦,Label1.Font.Name和Label1.Font.Size只能取得属性值,不能设置,仅读属性,还是VB6好用。 VB.net要通过实例化对象才能实现,真麻烦:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label1.AutoSize = vbTrue
        Dim MyFont As System.Drawing.Font
        Dim MyFontName As String

        MyFontName = "黑体"
        Dim MyFontStyle As FontStyle

        Dim sngSize = 48
        Dim intStyle = True
        Dim bolUnder = True
        Dim bolStrike = True

        Dim intColorR = 20
        Dim intColorG = 20
        Dim intColorB = 20
        If bolUnder Then
            myFontStyle = myFontStyle Or FontStyle.Underline
        End If
        If bolStrike Then
            myFontStyle = myFontStyle Or FontStyle.Strikeout
        End If
        If intStyle Then
            myFontStyle = myFontStyle Or FontStyle.Bold Or FontStyle.Italic
        End If
        Dim myColor As Color
        myColor = Color.FromArgb(RGB(intColorR, intColorG, intColorB))
        'myColor = RGB(intColorR, intColorG, intColorB) 
        Dim myFontFamily As System.Drawing.FontFamily
        myFontFamily = New FontFamily(MyFontName)
        myFont = New System.Drawing.Font(myFontFamily, sngSize, myFontStyle, System.Drawing.GraphicsUnit.Point)
        Label1.Font = myFont
        Label1.ForeColor = myColor

    End Sub
End Class
bcrun 2012-12-02
  • 打赏
  • 举报
回复
看看属性列表中吧,label控件有个Font属性,你在IDE中展开他就能看到那些属性了,个人建议一般情况下设置Pixel型尺寸

1,453

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧