Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb_dotnet thread: 'System.OutOfMemoryException' occurred in system.drawing.dll


Message #1 by steve.percival@c... on Fri, 1 Mar 2002 16:07:10
No I wrote this with the release version. It works for a bit and then 
throws the exception.

> hI THERE
> 
> I don't know whether you tried it first in beta2
> version.
> 
> In beta2 version it used to work but in the release
> version it fails.
> 
> I think that (I might be wrong) that with the release
> version Microsoft changed this drawing namespace.
> 
> I WOULD BE VERY INTERESTED TO KNOW WHY?
> I have the same problems
> 
> Gabriel
>  
> 
> --- steve.percival@c... wrote: > Sorry
> about this but this is going to be a long
> > post.
> > 
> > I am trying to create a menuitem class that displays
> > icons. I have found 
> > several sources on the internet and have cobbled
> > together the following 
> > class. The problem I have is that when I use it on a
> > form it works for a 
> > while but then starts giving the following
> > exception:
> > 
> > An unhandled exception of type
> > 'System.OutOfMemoryException' occurred in 
> > system.drawing.dll
> > 
> > Additional information: Out of memory.
> > 
> > this means I have to reboot to cure the problem. Can
> > anyone see a problem 
> > with the class. or the way I am calling it 
> > 
> > 
> > MENU ITEM CLASS
> > 
> > Imports System.Drawing.Text
> > Imports System.ComponentModel
> > 
> > Namespace NSIconMenuItem
> > 
> >     Public Class IconMenuItem
> >         Inherits System.Windows.Forms.MenuItem
> > 
> > #Region " Windows Form Designer generated code "
> > 
> >         Private _DisplayIcon As Icon
> > #Region " Constructors "
> >         Public Sub New()
> >             MyBase.New()
> > 
> >             'This call is required by the Windows
> > Form Designer.
> >             InitializeComponent()
> > 
> >             'Add any initialization after the
> > InitializeComponent() call
> >             Me.OwnerDraw = True
> >         End Sub
> >         Public Sub New(ByVal text As String)
> >             MyBase.New(text)
> > 
> >             'This call is required by the Windows
> > Form Designer.
> >             InitializeComponent()
> > 
> >             'Add any initialization after the
> > InitializeComponent() call
> >             Me.OwnerDraw = True
> >         End Sub
> >         Public Sub New(ByVal text As String, ByVal
> > OnClick As EventHandler)
> >             MyBase.New(text, OnClick)
> > 
> >             'This call is required by the Windows
> > Form Designer.
> >             InitializeComponent()
> > 
> >             'Add any initialization after the
> > InitializeComponent() call
> >             Me.OwnerDraw = True
> >         End Sub
> > 
> >         Public Sub New(ByVal text As String, ByVal
> > Items() As MenuItem)
> >             MyBase.New(text, Items)
> > 
> >             'This call is required by the Windows
> > Form Designer.
> >             InitializeComponent()
> > 
> >             'Add any initialization after the
> > InitializeComponent() call
> >             Me.OwnerDraw = True
> >         End Sub
> > 
> >         Public Sub New(ByVal text As String, ByVal
> > OnClick As 
> > EventHandler, ByVal Shortcut As Shortcut)
> >             MyBase.New(text, OnClick, Shortcut)
> > 
> >             'This call is required by the Windows
> > Form Designer.
> >             InitializeComponent()
> > 
> >             'Add any initialization after the
> > InitializeComponent() call
> >             Me.OwnerDraw = True
> >         End Sub
> > 
> >         Public Sub New(ByVal MergeType As MenuMerge,
> > ByVal MergeOrder As 
> > Integer, ByVal Shortcut As Shortcut, _
> >             ByVal text As String, ByVal OnClick As
> > EventHandler, ByVal 
> > OnPopup As EventHandler, _
> >             ByVal OnSelect As EventHandler, ByVal
> > Items() As MenuItem)
> > 
> >             MyBase.New(MergeType, MergeOrder,
> > Shortcut, text, OnClick, 
> > OnPopup, OnSelect, Items)
> > 
> >             'This call is required by the Windows
> > Form Designer.
> >             InitializeComponent()
> > 
> >             'Add any initialization after the
> > InitializeComponent() call
> >             Me.OwnerDraw = True
> >         End Sub
> > #End Region
> >         Protected Overloads Overrides Sub
> > Dispose(ByVal disposing As 
> > Boolean)
> >             If disposing Then
> >                 If Not (components Is Nothing) Then
> >                     components.Dispose()
> >                 End If
> >             End If
> >             _DisplayIcon.Dispose()
> >             _DisplayIcon = Nothing
> >             MyBase.Dispose(disposing)
> >         End Sub
> > 
> >         'Required by the Windows Form Designer
> >         Private components As
> > System.ComponentModel.IContainer
> > 
> >         'NOTE: The following procedure is required
> > by the Windows Form 
> > Designer
> >         'It can be modified using the Windows Form
> > Designer.  
> >         'Do not modify it using the code editor.
> >         <System.Diagnostics.DebuggerStepThrough()>
> > Private Sub 
> > InitializeComponent()
> >             '
> >             '
> >             '
> >             components = New
> > System.ComponentModel.Container()
> > 
> >         End Sub
> > 
> > #End Region
> >         Public Property DisplayIcon() As Icon
> >             Get
> >                 DisplayIcon = _DisplayIcon
> >             End Get
> >             Set(ByVal Value As Icon)
> >                 _DisplayIcon = Value
> >             End Set
> >         End Property
> > 
> > 
> >         Protected Overrides Sub OnMeasureItem(ByVal
> > e As 
> > System.Windows.Forms.MeasureItemEventArgs)
> >             MyBase.OnMeasureItem(e)
> >             Dim sf As StringFormat = New
> > StringFormat()
> > 
> >             Dim fnt As Font 
> > SystemInformation.MenuFont
> > 
> >             sf.HotkeyPrefix = HotkeyPrefix.Show
> >             sf.SetTabStops(50, New Single() {0})
> > 
> >             If Me.DisplayIcon.Height > fnt.Height
> > Then
> >                 e.ItemHeight = Me.DisplayIcon.Height
> > + 6
> >             Else
> >                 e.ItemHeight = fnt.Height + 6
> >             End If
> >             e.ItemWidth 
> > CInt(e.Graphics.MeasureString(AppendShortcut(), _
> >                    fnt, 1000, sf).Width) +
> > Me.DisplayIcon.Width + 5
> > 
> >             sf.Dispose()
> > 
> >             sf = Nothing
> >         End Sub
> > 
> > 
> > 
> >         Protected Overrides Sub OnDrawItem(ByVal e
> > As 
> > System.Windows.Forms.DrawItemEventArgs)
> > 
> === message truncated === 
> 
> __________________________________________________
> Do You Yahoo!?
> Everything you'll ever need on one web page
> from News and Sport to Email and Music Charts
> http://uk.my.yahoo.com

  Return to Index