Click here to Skip to main content
15,920,217 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: How to disable Ctrl+Alt+Del in window XP with VB Pin
Dave Kreskowiak5-Jan-04 3:41
mveDave Kreskowiak5-Jan-04 3:41 
GeneralExamining bytes returned from an ATL component Pin
Aby Philip4-Jan-04 3:23
Aby Philip4-Jan-04 3:23 
GeneralRe: Examining bytes returned from an ATL component Pin
Vi25-Jan-04 0:25
Vi25-Jan-04 0:25 
QuestionShadow Effects? Pin
Bus Clocking4-Jan-04 1:21
Bus Clocking4-Jan-04 1:21 
QuestionPackage and Deployment ? Pin
Member 7660843-Jan-04 21:51
Member 7660843-Jan-04 21:51 
AnswerRe: Package and Deployment ? Pin
elRaptor8-Jan-04 7:15
elRaptor8-Jan-04 7:15 
QuestionMenu -Help ? Pin
Member 7660843-Jan-04 21:49
Member 7660843-Jan-04 21:49 
AnswerRe: Menu -Help ? Pin
elRaptor8-Jan-04 7:38
elRaptor8-Jan-04 7:38 
Hello again:
I have use a component class that inherits from the MenuItem class: this is the class:

Imports System.ComponentModel
<description("owner draw="" menuitem="" class="" with="" new="" properties="" such="" as="" image="" and="" font.")=""> _
Public Class MiMenuItem
Inherits MenuItem
Private mFont As Font = SystemInformation.MenuFont
Private mImage As System.Drawing.Image = Nothing
Private nStartTextPosition As Integer = 0
Public Sub New()
MyBase.New()
End Sub
<description("position of="" the="" left="" corner="" menuitem="" control="" where="" text="" is="" drawing"),="" defaultvalue(0)=""> _
Property StartTextPosition() As Integer
Get
StartTextPosition = nStartTextPosition
End Get
Set(ByVal Value As Integer)
nStartTextPosition = Value
End Set
End Property
<description("the font="" used="" to="" draw="" the="" text")=""> Property Font() As System.Drawing.Font
Get
Font = mFont
End Get
Set(ByVal Value As Font)
mFont = Value
End Set
End Property
<description("this image="" will="" be="" used="" on="" the="" left="" side="" menuitem.note:="" this="" is="" visible="" only="" at="" run-time="" !")=""> Property Image() As Image
Get
Image = mImage
End Get
Set(ByVal Value As Image)
mImage = Value
End Set
End Property
Protected Overrides Sub OnMeasureItem(ByVal e As System.Windows.Forms.MeasureItemEventArgs)
Dim itemSize As SizeF
itemSize = e.Graphics.MeasureString(Me.Text, mFont)
Dim nIconW As Integer = 0
Dim nIconH As Integer = 0
If Not (mImage Is Nothing) Then
nIconW = mImage.Width
If mImage.Height > itemSize.Height Then nIconH = mImage.Height - itemSize.Height
End If
e.ItemWidth = itemSize.Width + nIconW + nStartTextPosition
e.ItemHeight = itemSize.Height + nIconH
End Sub

Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)

Dim selected As Boolean
Dim textcolor As Color = SystemColors.MenuText
Dim textformat As New StringFormat()
textformat.HotkeyPrefix = Drawing.Text.HotkeyPrefix.Show

Dim nIconW As Integer = 0
If Not (mImage Is Nothing) Then
nIconW = mImage.Width
End If
Dim R As New RectangleF(e.Bounds.Left + nIconW, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height)

selected = (e.State And DrawItemState.Selected)

e.Graphics.FillRectangle(SystemBrushes.Menu, e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height)
If selected Then
e.DrawBackground()
textcolor = SystemColors.HighlightText
Else
e.Graphics.FillRectangle(SystemBrushes.Menu, R)
End If
If Not (mImage Is Nothing) Then
e.Graphics.DrawImageUnscaled(mImage, e.Bounds.Left, e.Bounds.Top)
End If
R.X += nStartTextPosition
e.Graphics.DrawString(Me.Text, mFont, New SolidBrush(textcolor), R, textformat)
End Sub
End Class

>>>>>>>>>>>>>>>>>
Now you need to change the line where you define the menu Item and the line where you define the instance of that MenuItem of your menu:
Friend WithEvents MenuExit As System.Windows.Forms.MenuItem
Me.MenuExit = New System.Windows.Forms.MenuItem
for your new component
Friend WithEvents MenuExit As miMenuItem
Me.MenuExit = New MiProyect.MiMenuItem


Finally, define the type of Font and Image you want, you can use the properties browser to change this fields.
Me.MenuExit.Font = New System.Drawing.Font("Tahoma", 11.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World, CType(0, Byte))
Me.MenuExit.Image = CType(resources.GetObject("MenuExit.Image"), System.Drawing.Image)

Hope this Helps!
JA
GeneralHelp - Disable Ctrl - Esc Pin
Anonymous3-Jan-04 18:41
Anonymous3-Jan-04 18:41 
GeneralRe: Help - Disable Ctrl - Esc Pin
Dave Kreskowiak4-Jan-04 8:14
mveDave Kreskowiak4-Jan-04 8:14 
GeneralSending to a Web Form Pin
ProjectInsanity3-Jan-04 17:19
ProjectInsanity3-Jan-04 17:19 
GeneralBasic VB Excel Chart data selection Pin
mitreviper3-Jan-04 16:13
mitreviper3-Jan-04 16:13 
GeneralDatagrid &quot;Edit Only&quot; Pin
pchak3-Jan-04 8:12
pchak3-Jan-04 8:12 
GeneralRe: Datagrid &quot;Edit Only&quot; Pin
Guillermo Rivero3-Jan-04 17:24
Guillermo Rivero3-Jan-04 17:24 
GeneralHelp required Pin
emmshazi3-Jan-04 4:27
emmshazi3-Jan-04 4:27 
GeneralRe: Help required Pin
Guillermo Rivero3-Jan-04 17:31
Guillermo Rivero3-Jan-04 17:31 
GeneralRe: Help required Pin
Member 7660843-Jan-04 17:51
Member 7660843-Jan-04 17:51 
Generaltask scheduler Pin
Vipul Bhatt2-Jan-04 18:52
Vipul Bhatt2-Jan-04 18:52 
GeneralClickity Pin
Colin Angus Mackay3-Jan-04 2:46
Colin Angus Mackay3-Jan-04 2:46 
GeneralRe: task scheduler Pin
Colin Angus Mackay3-Jan-04 2:56
Colin Angus Mackay3-Jan-04 2:56 
GeneralParameter passing and reading [task scheduler] Pin
Vipul Bhatt2-Jan-04 18:48
Vipul Bhatt2-Jan-04 18:48 
GeneralClickity Pin
Colin Angus Mackay3-Jan-04 2:46
Colin Angus Mackay3-Jan-04 2:46 
GeneralRe: Parameter passing and reading [task scheduler] Pin
Colin Angus Mackay3-Jan-04 3:01
Colin Angus Mackay3-Jan-04 3:01 
GeneralRecursive File Copy/Delete Pin
crouchie042-Jan-04 13:23
crouchie042-Jan-04 13:23 
GeneralRe: Recursive File Copy/Delete Pin
BenBadger4-Jan-04 7:15
sussBenBadger4-Jan-04 7:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.