User Control - Menu with background colors!

xiaoxiao2021-03-06  20

Imports system.componentmodel

Public Class MyMenuItem

Inherits System.Windows.Forms.MenuItem

#Region "Windows Form Designer Generated Code"

Public Sub New ()

Mybase.new ()

'This call is required for the Windows Form Designer.

InitializeComponent ()

'Add any initialization after INITIALIZECOMPONENT ()

End Sub

'UserControl overrides Dispose to clean the component list.

Protected Overloads Overrides Sub Dispose (Byval Disposing as Boolean)

IF Disposing then

IF not (Components Is Nothing) THEN

Components.dispose ()

END IF

END IF

Mybase.dispose (Disposing)

End Sub

'Windows Form Designer

Private Components as System.comPonentModel.icontainer

'Note: The following process is necessary for the Windows Form Designer.

'You can modify this process using the Windows Form Designer.

'Don't modify it using the code editor.

private subinitializecomponent ()

Components = new system.componentmodel.container ()

End Sub

#End region

Private m_backcolor as color = color.blue

_

Public property Bcolor () As Color

Get

Return M_BackColor

END GET

SET (ByVal Value As Color)

m_backcolor = value

End set

End Property

Private sub mymenuitem_drawitem (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.WIDTH, E.BOUNDS.HEIGHT)

'E.Graphics.drawImage (M_Picture, R1)

DIM M As New Solidbrush (M_BackColor)

E.Graphics.FillRectangle (M, R1)

'E.graphics.drawline (Pens.Yellow, E.Bounds.x, E.Bounds.y, E.Bounds.x, E.Bounds.y E.Bounds.Height)

'E.Graphics.drawline (Pens.Yellow, E.Bounds.x, E.Bounds.y, E.Bounds.x E.BOUNDS.WIDTH, E.BOUNDS.Y)

'E.Graphics.drawline (Pens.Yellow, E.Bounds.x, E.Bounds.y, E.Bounds.x E.Bounds.Width, E.BOUNDS.Y E.BOUNDS.HEight)' e. Graphics.drawline (Pens.yellow, E.Bounds.x E.Bounds.width, E.Bounds.y, E.Bounds.x E.Bounds.width, E.Bounds.y E.Bounds.Height)

E.Graphics.drawstring (Me.Text, New Font ("Times New Roman", 10, FontStyle.Regular, Brushes.black, R)

End Sub

Private sub mymenuitem_measureItem (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

转载请注明原文地址:https://www.9cbs.com/read-43127.html

New Post(0)