扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
控件类型 | 属性 | 设置值 |
Panel | Name | Panel1 |
Dock | Bottom | |
StatusBar | Name | StatusBar1 |
Dock | Fill | |
Panels | 1、加入一个Name为stabutton的面板将其Style设为OwnerDraw。 2、加入一个Name为staStatus的面板,将其Style设为Text,AutoSize设为Spring,Text设为“状态栏上放置控件”。 | |
Button | Name | Button1 |
Private Sub StatusBar1_DrawItem _ (ByVal sender As Object, ByVal sbdevent As System.Windows.Forms.StatusBarDrawItemEventArgs) _ Handles StatusBar1.DrawItem If sbdevent.Panel Is stabutton Then ‘此处是关键,一定要根据Statusbar控件中相应面板的调整大小时, ‘将放置在该面板上用户放置的控件(此处是Button1)调整为面板的尺寸。 ‘,在sbdevent.Bounds提供的面板大小中使用的坐标系统原点是在StatusBar1的左上角, ‘而因为Button1.Bounds使用的坐标系统的原点都是在Panel1的左上角,而StatusBar1和Button1的父对象 ‘同为Panel1,所以只需将sbdevent.Bounds的X及Y坐标加上StatusBar1.Location的X和Y做一个平移 ‘就可以得到Button1所应处的正确位置。 Button1.Bounds = New Rectangle(sbdevent.Bounds.X + StatusBar1.Location.X, _ sbdevent.Bounds.Y + StatusBar1.Location.Y, _ sbdevent.Bounds.Width, _ sbdevent.Bounds.Height) End If End Sub Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click StatusBar1.Panels(1).Text = "你点击了按钮,鼠标位置为" & Cursor.Position.ToString End Sub |
濡傛灉鎮ㄩ潪甯歌揩鍒囩殑鎯充簡瑙T棰嗗煙鏈€鏂颁骇鍝佷笌鎶€鏈俊鎭紝閭d箞璁㈤槄鑷抽《缃戞妧鏈偖浠跺皢鏄偍鐨勬渶浣抽€斿緞涔嬩竴銆�