VB 窗口中label text等控件的字体改变大小
2013-07-14
展开全部
使用for each 遍历窗体所有控件,如果是label 或 text 控件则改变其字体,或颜色。以下代码vs2008下通过测试。e.g.'---------------------------------------------------'窗体:Form1'2个label : label1,label2'2个Textbox: textbox1,textbox2'1个button : button1'-----------------------------------------------------------Public Class Form1'按钮单击时间 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ob As Control
Dim obtype As String
For Each ob In Me.Controls
obtype = ob.GetType().ToString()
If obtype = "System.Windows.Forms.TextBox" Or obtype = "System.Windows.Forms.Label" Then
ob.ForeColor = Color.Blue ‘字体颜色
ob.Font = New System.Drawing.Font("宋体", 20.5F, FontStyle.Underline) ’字体
End If
Next
End Sub
End Class
Dim ob As Control
Dim obtype As String
For Each ob In Me.Controls
obtype = ob.GetType().ToString()
If obtype = "System.Windows.Forms.TextBox" Or obtype = "System.Windows.Forms.Label" Then
ob.ForeColor = Color.Blue ‘字体颜色
ob.Font = New System.Drawing.Font("宋体", 20.5F, FontStyle.Underline) ’字体
End If
Next
End Sub
End Class
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询