Results 1 to 3 of 3

Thread: Guru Help Needed!! [ Topic Closed No Guru's here! ]

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    Guru Help Needed!! [ Topic Closed No Guru's here! ]

    I have found the following link to add icons to my menu:

    http://www.fawcette.com/vsm/2003_01/...tips/barfield/

    If someone as time please read it and tell me why I am getting the following error when I have followed the instructions step by step.

    Error: Name 'sfMenuItem' is not declared.

    I am still new so I will explain what I did..

    First I created a menu

    My Menu
    -------
    &File - mnuFile
    &New - mnuFileNew
    &Open - mnuFileOpen

    Then placed the following:

    Private Sub mnuFileNew_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles mnuFileNew.MeasureItem, mnuFileOpen.MeasureItem
    Dim ThisMenuItem As MenuItem = sender
    Dim ThisMenuItem_Strings As String() = _
    ThisMenuItem.Text.Split(",")

    Dim TextSize As SizeF = _
    e.Graphics.MeasureString(ThisMenuItem_Strings(0).Replace("&", ""), SystemInformation.MenuFont)

    e.ItemWidth = TextSize.Width + 30

    If ThisMenuItem.Text = "-" Then
    e.ItemHeight = 3
    Else
    e.ItemHeight = 22
    End If

    End Sub

    Added the following:

    Private Sub mnuFileNew_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles mnuFileNew.DrawItem, mnuFileOpen.DrawItem
    On Error Resume Next

    Dim ThisMenuItem As MenuItem = sender
    Dim ThisMenuItem_Brush As Brush
    Dim ThisMenuItem_Strings As String() = _
    ThisMenuItem.Text.Split(",")
    Dim ThisMenuItem_Icon As Icon = _
    CType(res.GetObject( _
    ThisMenuItem_Strings(1)), System.Drawing.Icon)
    Dim ThisMenuItem_Rect As RectangleF = New _
    RectangleF(30, e.Bounds.Top, _
    e.Bounds.Width - 30, e.Bounds.Height)

    If ((e.State And DrawItemState.Selected) = _
    DrawItemState.Selected) And ((e.State And _
    DrawItemState.Disabled) <> _
    DrawItemState.Disabled) Then
    ' DRAW THE "SELECTED ITEM" BOX
    ThisMenuItem_Brush = New _
    SolidBrush( _
    SystemColors.InactiveCaptionText)
    e.Graphics.FillRectangle(ThisMenuItem_Brush, _
    e.Bounds)
    ThisMenuItem_Brush.Dispose()
    e.Graphics.DrawRectangle( _
    SystemPens.Highlight, e.Bounds.X, _
    e.Bounds.Y, e.Bounds.Width - 1, _
    e.Bounds.Height - 1)
    ' DRAW THE ICON WITH DROPSHADOW
    Dim img As Image = _
    ThisMenuItem_Icon.ToBitmap()
    ControlPaint.DrawImageDisabled( _
    e.Graphics, img, e.Bounds.Left + 4, _
    e.Bounds.Top + 4, _
    SystemColors.InactiveCaptionText)
    e.Graphics.DrawIcon(ThisMenuItem_Icon, _
    e.Bounds.Left + 2, e.Bounds.Top + 2)
    Else
    ' DRAW THE BACKGROUND
    e.Graphics.FillRectangle( _
    SystemBrushes.Control, e.Bounds.Left, _
    e.Bounds.Top, 22, e.Bounds.Height)
    e.Graphics.FillRectangle(SystemBrushes.Menu, _
    e.Bounds.Left + 22, e.Bounds.Top, _
    e.Bounds.Width, e.Bounds.Height)

    ' IF THIS IS A SEPARATOR, DRAW IT AND BAIL OUT
    If ThisMenuItem.Text = "-" Then
    e.Graphics.DrawLine( _
    SystemPens.ControlDark, 30, _
    e.Bounds.Top + 1, e.Bounds.Right, _
    e.Bounds.Top + 1)
    Exit Sub
    End If

    ' DRAW THE ICON
    If ((e.State And DrawItemState.Disabled) <> _
    DrawItemState.Disabled) Then
    e.Graphics.DrawIcon(ThisMenuItem_Icon, _
    e.Bounds.Left + 3, e.Bounds.Top + 3)
    Else
    Dim img As Image = _
    ThisMenuItem_Icon.ToBitmap()
    ControlPaint.DrawImageDisabled( _
    e.Graphics, img, e.Bounds.Left + 3, _
    e.Bounds.Top + 3, _
    SystemColors.InactiveCaptionText)
    End If
    End If

    ' DRAW THE TEXT
    If (e.State And DrawItemState.Disabled) = _
    DrawItemState.Disabled Then
    ThisMenuItem_Brush = New _
    SolidBrush(SystemColors.GrayText)
    e.Graphics.DrawString( _
    ThisMenuItem_Strings(0), _
    SystemInformation.MenuFont, _
    ThisMenuItem_Brush, ThisMenuItem_Rect, _
    sfMenuItem)
    ThisMenuItem_Brush.Dispose()
    Else
    e.Graphics.DrawString( _
    ThisMenuItem_Strings(0), _
    SystemInformation.MenuFont, _
    SystemBrushes.ControlText, _
    ThisMenuItem_Rect, sfMenuItem)
    End If
    End Sub

    The last block of code I am getting the "Error"...

    Also:

    Where is this pulling the icon from? Is this why I am getting an error? I have not added any icons to the program... also the following:

    "The text before the comma will be drawn as the menu text, and the text after the comma is the item's icon name in your resource file."

    How do I add a "Resource File" to my application?
    Like I said I am new so please help me... Detailed explanation of this process would be a +++ !

    Thanks in advance..

    Anjari
    Last edited by Anjari; Jan 15th, 2003 at 12:24 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width