扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
Public Class UserControl1 Inherits System.Windows.Forms.UserControl |
Public Class myMenuItem Inherits System.Windows.Forms.MenuItem Private m_picture As Image #Region … #End Region '下面代码实现Picture属性 Public Property picture() As Image Get picture = m_picture End Get Set(ByVal Value As Image) m_picture = Value End Set End Property '下面代码首先在菜单项上绘制图形,然后绘制菜单内容,图形在左边,然后是菜单内容 Private Sub myMenuItem_DrawItem(ByVal sender As Object, ByVal e As _ System.Windows.Forms.DrawItemEventArgs) Handles MyBase.DrawItem Dim r As New RectangleF(e.Bounds.X + e.Bounds.Height, e.Bounds.Y, e.Bounds.Width, _ e.Bounds.Height) Dim r1 As New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Height, e.Bounds.Height) e.Graphics.DrawImage(m_picture, r1) e.Graphics.DrawString(Me.Text, New Font("Times New Roman", 10, FontStyle.Regular), _ Brushes.Black, r) End Sub '下面代码用来确定菜单的矩形尺寸,注意最后的语句将宽度加宽 Private Sub myMenuItem_MeasureItem(ByVal sender As Object, ByVal e As _ System.Windows.Forms.MeasureItemEventArgs) Handles MyBase.MeasureItem Dim drawSize As SizeF drawSize = e.Graphics.MeasureString(Me.Text, New Font("Times New Roman", 10, _ FontStyle.Regular)) e.ItemHeight = Drawsize.Height e.ItemWidth = Drawsize.Width + Drawsize.Height End Sub End Class |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者