VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > vb >
  • vb.net 教程 3-7 窗体编程 菜单和工具栏 3 StatusStrip 2

版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
 
通过上一节的学习,大家对StatusStrip控件有了初步了解,
 
本节主要讲解如何通过代码操作StatusStrip,在上一节窗体基础上增加两个按钮:
 
 
 
按下“修改状态栏标签”按钮
 
    '修改状态栏标签
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ToolStripStatusLabel1.Text = "这是状态栏"
        ToolStripStatusLabel1.Image = Nothing
    End Sub
按下后:
 
 
 
按下“启动进度条”按钮:
 
 
 
    '启动进度条
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        For i As Integer = 0 To 100
            ToolStripProgressBar1.Value = i
            Threading.Thread.Sleep(100)
        Next
    End Sub
按下后:
 
 
 
 
 
 
 
 
 
在窗体编辑器上双击粗体、斜体或者下划线按钮添加Click事件,
 
使标签上的图片变化,同时使ToolStripDropDownButton1上的图片也跟着变化:
 
    '粗体
    Private Sub 粗体ToolStripMenuItem3_Click(sender As Object, e As EventArgs) Handles 粗体ToolStripMenuItem3.Click
        ToolStripStatusLabel1.Image = 粗体ToolStripMenuItem3.Image
        ToolStripStatusLabel1.Text = ""
        ToolStripDropDownButton1.Image = 粗体ToolStripMenuItem3.Image
    End Sub
    '斜体
    Private Sub 斜体ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 斜体ToolStripMenuItem.Click
        ToolStripStatusLabel1.Image = 斜体ToolStripMenuItem.Image
        ToolStripStatusLabel1.Text = ""
        ToolStripDropDownButton1.Image = 斜体ToolStripMenuItem.Image
    End Sub
    '下划线
    Private Sub 下划线ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 下划线ToolStripMenuItem.Click
        ToolStripStatusLabel1.Image = 下划线ToolStripMenuItem.Image
        ToolStripStatusLabel1.Text = ""
        ToolStripDropDownButton1.Image = 下划线ToolStripMenuItem.Image
    End Sub
运行时如图:
 
 
 
在窗体编辑器上双击左对齐、右对齐或者ToolStripSplitButton1添加Click事件:
 
    '左对齐
    Private Sub 左对齐ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 左对齐ToolStripMenuItem.Click
        ToolStripStatusLabel1.Image = Nothing
        ToolStripStatusLabel1.Text = "这是状态栏说明"
        ToolStripStatusLabel1.TextAlign = ContentAlignment.MiddleLeft
    End Sub
    '右对齐
    Private Sub 右对齐ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 右对齐ToolStripMenuItem.Click
        ToolStripStatusLabel1.Image = Nothing
        ToolStripStatusLabel1.Text = "这是状态栏说明"
        ToolStripStatusLabel1.TextAlign = ContentAlignment.MiddleRight
    End Sub
    '直接按下ToolStripSplitButton1
    Private Sub ToolStripSplitButton1_ButtonClick(sender As Object, e As EventArgs) Handles ToolStripSplitButton1.ButtonClick
        ToolStripStatusLabel1.Image = Nothing
        ToolStripStatusLabel1.Text = "这是状态栏说明"
        ToolStripStatusLabel1.TextAlign = ContentAlignment.MiddleCenter
    End Sub
运行时如图:
 
 
 
 
需要注意的是,虽然按下左对齐、右对齐后改变了文字对齐方式,但是由于ToolStripStatusLabel1的ImageAlign属性设置为了MiddleCenter
 
所以按下ToolStripDropDownButton上的粗体、斜体、下划线按钮后,显示的图片的对齐方式不受文字对齐方式的影响。
 
 
 
学习更多vb.net知识,请参看 vb.net 教程 目录
————————————————
版权声明:本文为CSDN博主「VB.Net」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/uruseibest/article/details/72972679

相关教程