SetMenuItemBitmaps и VB.NET

Язык Visual Basic на платформе .NET.

Модераторы: Ramzes, Sebas

Serega435
Начинающий
Начинающий
 
Сообщения: 2
Зарегистрирован: 23.04.2003 (Ср) 10:38

SetMenuItemBitmaps и VB.NET

Сообщение Serega435 » 23.04.2003 (Ср) 10:42

Каким образом организуется вызов SetMenuItemBitmaps d VB.NEt? В 6-м вроде все работает, а в Net не могу организовать вызов... :?:

CREATOR
Новичок
Новичок
 
Сообщения: 29
Зарегистрирован: 26.03.2003 (Ср) 12:32

Сообщение CREATOR » 26.04.2003 (Сб) 8:48

Попробуй компонент, примитив но в некотором смысле решает :idea:
Решений на данную тему великое множество, что конкретно нужно :?:
Мыль постараюсь помоч ......

[Imports System
Imports System.ComponentModel
'Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
'Imports System.Reflection
'Imports System.Resources
'Imports System.Windows.Forms

Namespace System.Windows.Forms
Public Class DMenuItem : Inherits MenuItem

Private _Icon As Icon = Nothing
Private _IconSize As New Size(16, 16)
Private _Font As Font = New Font("Microsoft Sans Serif", 8)
Private _Gradient_Color_First As Color = SystemColors.Highlight
Private _Gradient_Color_Last As Color = SystemColors.Menu

#Region " СВОЙСТВА "
Public Property Icon() As Icon
Get
Return _Icon
End Get
Set(ByVal Value As Icon)
_Icon = Value 'New Icon(Value, _IconSize)
_IconSize = Value.Size
End Set
End Property
Public ReadOnly Property IconSize() As Size
Get
Return _IconSize
End Get
End Property
Public Property Font() As Font
Get
Return _Font
End Get
Set(ByVal Value As Font)
_Font = Value
End Set
End Property
Public Property GradientColorFirst() As Color
Get
Return _Gradient_Color_First
End Get
Set(ByVal Value As Color)
_Gradient_Color_First = Value
End Set
End Property
Public Property GradientColorLast() As Color
Get
Return _Gradient_Color_Last
End Get
Set(ByVal Value As Color)
_Gradient_Color_Last = Value
End Set
End Property
#End Region

#Region " МЕТОДЫ "
Public Sub New()
MyBase.New()
Me.OwnerDraw = True
End Sub
Public Sub New(ByVal icon As Icon)
MyBase.New()
Me.OwnerDraw = True
_Icon = icon
End Sub
Public Sub New(ByVal icon As Icon, _
ByVal text As String)
MyBase.New(text)
Me.OwnerDraw = True
_Icon = icon
End Sub
Public Sub New(ByVal icon As Icon, _
ByVal text As String, _
ByVal colorFirst As Color, _
ByVal colorLast As Color)
MyBase.New(text)
Me.OwnerDraw = True
_Icon = icon
_Gradient_Color_First = colorFirst
_Gradient_Color_Last = colorLast
End Sub
Public Sub New(ByVal icon As Icon, _
ByVal text As String, _
ByVal onClick As EventHandler)
MyBase.New(text, onClick)
Me.OwnerDraw = True
_Icon = icon
End Sub
Public Sub New(ByVal icon As Icon, _
ByVal text As String, _
ByVal onClick As EventHandler, _
ByVal shortcut As Shortcut)
MyBase.New(text, onClick, shortcut)
Me.OwnerDraw = True
_Icon = icon
End Sub
Public Sub New(ByVal icon As Icon, _
ByVal text As String, _
ByVal colorFirst As Color, _
ByVal colorLast As Color, _
ByVal onClick As EventHandler, _
ByVal shortcut As Shortcut)
MyBase.New(text, onClick, shortcut)
Me.OwnerDraw = True
_Icon = icon
_Gradient_Color_First = colorFirst
_Gradient_Color_Last = colorLast
End Sub
#End Region

#Region " Overrides МЕТОДЫ "
Protected Overrides Sub OnDrawItem(ByVal e As DrawItemEventArgs)
MyBase.OnDrawItem(e)
Dim br As Brush
If Not _Icon Is Nothing Then
e.Graphics.DrawIcon(_Icon, e.Bounds.Left + 2, e.Bounds.Top + 2)
End If
Dim rcBk As Rectangle = e.Bounds
rcBk.X += Me.IconSize.Height + 4
If CBool(e.State And DrawItemState.Selected) Then
br = New LinearGradientBrush(rcBk, _Gradient_Color_First, _Gradient_Color_Last, 0)
Else
br = SystemBrushes.Menu
End If
e.Graphics.FillRectangle(br, rcBk)
Dim sf As StringFormat = New StringFormat()
sf.HotkeyPrefix = HotkeyPrefix.Show
br = New SolidBrush(e.ForeColor)
e.Graphics.DrawString(GetText(), _Font, br, e.Bounds.Left + Me.IconSize.Height + 5, e.Bounds.Top + 2, sf)
br.Dispose()
br = Nothing
sf.Dispose()
sf = Nothing
End Sub
Protected Overrides Sub OnMeasureItem(ByVal e As MeasureItemEventArgs)
Dim sf As New StringFormat()
sf.HotkeyPrefix = HotkeyPrefix.Show
MyBase.OnMeasureItem(e)
e.ItemHeight = Me.IconSize.Height + 4
e.ItemWidth = CInt(e.Graphics.MeasureString(GetText(), _Font, 10000, sf).Width) + 10
sf.Dispose()
sf = Nothing
End Sub
#End Region

#Region " Локальные методы "
Private Function GetText() As String
Dim s As String = Me.Text
If Me.ShowShortcut And Me.Shortcut <> Shortcut.None Then
s = s & Convert.ToChar(9) & TypeDescriptor.GetConverter(GetType(Keys)).ConvertToString(CType(Shortcut, Keys))
End If
Return s
End Function
#End Region

End Class
End Namespace
]
[/code]


Вернуться в Visual Basic .NET

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 72

    TopList