扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:阿虎 来源:天极开发 2007年11月9日
关键字:
Private Sub MenuItem2_DrawItem ( ByVal sender As Object , ByVal e As System.Windows.Forms.DrawItemEventArgs ) Handles MenuItem2.DrawItem Dim rfBound As RectangleF = New RectangleF ( e.Bounds.X , e.Bounds.Y , e.Bounds.Width - 1 , e.Bounds.Height ) '根据DrawItemEventArgs参数获得菜单项矩形区域并存储到RectangleF类型实例中 Dim rfBound1 As Rectangle = New Rectangle ( e.Bounds.X , e.Bounds.Y , e.Bounds.Width - 1 , e.Bounds.Height ) '根据DrawItemEventArgs参数获得菜单项矩形区域并存储到Rectangle类型实例中 'Rectangle类型实例和RectangleF类型实例差不多,但在后面代码中绘制菜单的函数是有区别的 e.Graphics.FillRectangle ( New SolidBrush ( Color.LightGray ) , rfBound ) Dim s As MenuItem = CType ( sender , MenuItem ) Dim s1 As String = s.Text '获得菜单项对应的文本名称 Dim sfTemp As StringFormat = New StringFormat ( ) sfTemp.Alignment = StringAlignment.Center '设定文本在矩形区域的对齐方式 sfTemp.LineAlignment = StringAlignment.Center Dim rcText As RectangleF = rfBound rcText.Width -= 5 e.Graphics.DrawString ( s1 , New Font ( "宋体" , 10 ) , New SolidBrush ( Color.Blue ) , rcText , sfTemp ) e.Graphics.DrawRectangle ( New Pen ( New SolidBrush ( Color.LightGray ) ) , rfBound1 ) If e.State = ( DrawItemState.NoAccelerator Or DrawItemState.Selected ) Then e.Graphics.FillRectangle ( New SolidBrush ( Color.LightYellow ) , rfBound ) e.Graphics.DrawString ( s1 , New Font ( "宋体" , 10 , FontStyle.Bold Or FontStyle.Underline ) , New SolidBrush ( Color.Red ) , rcText , sfTemp ) e.Graphics.DrawRectangle ( New Pen ( New SolidBrush ( Color.Black ) ) , rfBound1 ) e.DrawFocusRectangle ( ) End If End Sub |
Private Sub MenuItem2_MeasureItem ( ByVal sender As Object , ByVal e As System.Windows.Forms.MeasureItemEventArgs ) Handles MenuItem2.MeasureItem e.ItemWidth = 60 '设定菜单项的宽度 e.ItemHeight = 30 '设定菜单项的高度 End Sub |
Private Sub MenuItem3_DrawItem ( ByVal sender As Object , ByVal e As System.Windows.Forms.DrawItemEventArgs ) Handles MenuItem3.DrawItem Dim rfBound As RectangleF = New RectangleF ( e.Bounds.X , e.Bounds.Y , e.Bounds.Width - 1 , e.Bounds.Height ) '根据DrawItemEventArgs参数获得菜单项矩形区域并存储到RectangleF类型实例中 Dim rfBound1 As Rectangle = New Rectangle ( e.Bounds.X , e.Bounds.Y , e.Bounds.Width - 1 , e.Bounds.Height ) '根据DrawItemEventArgs参数获得菜单项矩形区域并存储到Rectangle类型实例中 'Rectangle类型实例和RectangleF类型实例差不多,但在后面代码中绘制菜单的函数是有区别的 Dim s As MenuItem = CType ( sender , MenuItem ) Dim s1 As String = s.Text Dim sfTemp As StringFormat = New StringFormat ( ) sfTemp.Alignment = StringAlignment.Center sfTemp.LineAlignment = StringAlignment.Center Dim rcText As RectangleF = rfBound rcText.Width -= 5 e.Graphics.DrawString ( s1 , New Font ( "Veranda" , 10 ) , New SolidBrush ( Color.Blue ) , rcText , sfTemp ) e.Graphics.DrawRectangle ( New Pen ( New SolidBrush ( Color.LightGray ) ) , rfBound1 ) If e.State = ( DrawItemState.NoAccelerator Or DrawItemState.Selected ) Then e.Graphics.FillRectangle ( New SolidBrush ( Color.LightYellow ) , rfBound ) e.Graphics.DrawString ( s1 , New Font ( "Veranda" , 10 , FontStyle.Bold Or FontStyle.Underline ) , New SolidBrush ( Color.Red ) , rcText , sfTemp ) e.Graphics.DrawRectangle ( New Pen ( New SolidBrush ( Color.Black ) ) , rfBound1 ) e.DrawFocusRectangle ( ) End If End Sub |
Private Sub MenuItem3_MeasureItem ( ByVal sender As Object , ByVal e As System.Windows.Forms.MeasureItemEventArgs ) Handles MenuItem3.MeasureItem e.ItemWidth = 60 '设定菜单项的宽度 e.ItemHeight = 30 '设定菜单项的高度 End Sub |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者