首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

vb2010设立label字体大小的代码

2012-12-14 
vb2010设置label字体大小的代码你好,我使用的是vs2010中的Visual Basic,(项目:windows窗体应用程序)我想通

vb2010设置label字体大小的代码
你好,我使用的是vs2010中的Visual Basic,(项目:windows窗体应用程序)我想通过代码,改变label1字体的大小
该如何写呢?
[最优解释]

引用:
可以的。不过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

[其他解释]
看看属性列表中吧,label控件有个Font属性,你在IDE中展开他就能看到那些属性了,个人建议一般情况下设置Pixel型尺寸
[其他解释]
可以的。不过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


[其他解释]
同意楼上,我初接触.net时,最感到意外的是,经常把以前要用一两句话能做到改成要用一堆东西实现的,从这个角度看对其普及不表乐观
[其他解释]
谢谢,问题解决了

热点排行