Can someone reproduce the following error?
I'm using the module at the bottom of my post to owner draw a menu
items, I call the module from a form like this:
Private Sub mnuOpen_DrawItem(ByVal sender As Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles mnuOpen.DrawItem
Dim Ic As New Icon(Application.StartupPath & "\101_72.ico")
DrawItems(e, mnuOpen, Ic)
End Sub
Private Sub mnuOpen_MeasureItem(ByVal sender As Object, ByVal e As
System.Windows.Forms.MeasureItemEventArgs) Handles mnuOpen.MeasureItem
MeasureItems(e, mnuOpen)
End Sub
It al works just fine but if I try to debug and step through it, or if
I type something wrong so that I get an error message at runtime. The
next time I try to run it I keep getting this error message:
An unhandled exception of type 'System.OutOfMemoryException' occurred
in system.drawing.dll
Additional information: Out of memory.
and then right clicking (even on the desktop) doesn't work like it
should and I have to reboot my pc for everything to return to normal.
Is there something wrong in the module. Or isn't it my fault?
thanks a lot
'Module om icoontjes aan een menu toe te voegen
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Windows.Forms
Module IconsMenuMain
Dim m_Font As New Font("Arial", 8)
Sub MeasureItems(ByVal EvMeasureItem As
System.Windows.Forms.MeasureItemEventArgs, ByVal Mi As MenuItem)
Dim sf As StringFormat = New StringFormat()
sf.HotkeyPrefix = HotkeyPrefix.Show
sf.SetTabStops(60, New Single() {0})
EvMeasureItem.ItemHeight = 22
EvMeasureItem.ItemWidth =
CInt(EvMeasureItem.Graphics.MeasureString(GetRealT ext(Mi), _
m_Font,
10000, sf).Width) + 30
sf.Dispose()
sf = Nothing
End Sub
Sub DrawItems(ByVal EvDrawItems As
System.Windows.Forms.DrawItemEventArgs, ByVal Mi As MenuItem, ByVal
m_Icon As Icon)
Dim br As Brush
Dim br2 As Brush
Dim fDisposeBrush As Boolean
Dim rand As Pen
Dim rcBk As Rectangle = EvDrawItems.Bounds
rcBk.Height -= 1
rcBk.Width -= 1
If CBool(EvDrawItems.State And DrawItemState.Selected) Then
br = New LinearGradientBrush(rcBk, Color.MediumPurple,
Color.YellowGreen, 0)
fDisposeBrush = True
rand = New Pen(Color.DarkBlue, 1)
EvDrawItems.Graphics.FillRectangle(br, rcBk)
EvDrawItems.Graphics.DrawRectangle(rand, rcBk)
Else
br = SystemBrushes.Control
br2 = New SolidBrush(Color.WhiteSmoke)
rand = System.Drawing.SystemPens.Control
EvDrawItems.Graphics.DrawRectangle(rand, rcBk)
rcBk.X += 24
rcBk.Width -= 23
rcBk.Y -= 1
rcBk.Height += 2
EvDrawItems.Graphics.FillRectangle(br2, rcBk)
rcBk.X = 0
rcBk.Width = 24
EvDrawItems.Graphics.FillRectangle(br, rcBk)
br2.Dispose()
End If
'Dim rcIcon As New Rectangle(EvDrawItems.Bounds.Left + 2,
EvDrawItems.Bounds.Top + 2, m_Icon.Width, m_Icon.Height)
'EvDrawItems.Graphics.ExcludeClip(rcIcon)
If fDisposeBrush Then br.Dispose()
br = Nothing
Dim sf As StringFormat = New StringFormat()
sf.HotkeyPrefix = HotkeyPrefix.Show
sf.SetTabStops(60, New Single() {0})
If Mi.Enabled Then
br = New SolidBrush(EvDrawItems.ForeColor)
Else
br = New SolidBrush(Color.Gray)
End If
EvDrawItems.Graphics.DrawString(GetRealText(Mi), m_Font, br, _
EvDrawItems.Bounds.Left + 25,
_
EvDrawItems.Bounds.Top + 2,
sf)
br.Dispose()
br = Nothing
sf.Dispose()
sf = Nothing
If Not m_Icon Is Nothing Then
If Not Mi.Checked Then
EvDrawItems.Graphics.DrawIcon(m_Icon,
EvDrawItems.Bounds.Left + 2, _
EvDrawItems.Bounds.Top +
2)
Else
EvDrawItems.Graphics.DrawIcon(m_Icon,
EvDrawItems.Bounds.Left + 2, _
EvDrawItems.Bounds.Top +
2)
End If
End If
End Sub
Function GetRealText(ByVal Mi As MenuItem) As String
Dim s As String = Mi.Text
If Mi.ShowShortcut And Mi.Shortcut <> Shortcut.None Then
Dim k As Keys = CType(Mi.Shortcut, Keys)
s = s & Convert.ToChar(9) & _
TypeDescriptor.GetConverter(GetType(Keys)).Convert ToString(k)
End If
Return s
End Function
End Module 2 2621
Good Evening Piedro,
Your problem is common to programmers. It is known as memory leak. You are
not handling your errors with try catch statements and when that happens your
computer still thinks it is running that program and will not release the
memory unless you reboot.
My suggestion is to put a try catch such as the one below this way when a
runtime error occurs it will release memory and you can at least debug
without running out of memory.
Try
'potential code that is having errors
Catch ex As Exception
MsgBox(ex.Message)
End
End Try
Rachel
"Piedro" wrote: Can someone reproduce the following error?
I'm using the module at the bottom of my post to owner draw a menu items, I call the module from a form like this:
Private Sub mnuOpen_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles mnuOpen.DrawItem Dim Ic As New Icon(Application.StartupPath & "\101_72.ico") DrawItems(e, mnuOpen, Ic) End Sub
Private Sub mnuOpen_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles mnuOpen.MeasureItem MeasureItems(e, mnuOpen) End Sub
It al works just fine but if I try to debug and step through it, or if I type something wrong so that I get an error message at runtime. The next time I try to run it I keep getting this error message: An unhandled exception of type 'System.OutOfMemoryException' occurred in system.drawing.dll Additional information: Out of memory.
and then right clicking (even on the desktop) doesn't work like it should and I have to reboot my pc for everything to return to normal. Is there something wrong in the module. Or isn't it my fault?
thanks a lot 'Module om icoontjes aan een menu toe te voegen
Imports System Imports System.ComponentModel Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Drawing.Text Imports System.Windows.Forms
Module IconsMenuMain
Dim m_Font As New Font("Arial", 8)
Sub MeasureItems(ByVal EvMeasureItem As System.Windows.Forms.MeasureItemEventArgs, ByVal Mi As MenuItem) Dim sf As StringFormat = New StringFormat() sf.HotkeyPrefix = HotkeyPrefix.Show sf.SetTabStops(60, New Single() {0}) EvMeasureItem.ItemHeight = 22 EvMeasureItem.ItemWidth = CInt(EvMeasureItem.Graphics.MeasureString(GetRealT ext(Mi), _ m_Font, 10000, sf).Width) + 30 sf.Dispose() sf = Nothing End Sub
Sub DrawItems(ByVal EvDrawItems As System.Windows.Forms.DrawItemEventArgs, ByVal Mi As MenuItem, ByVal m_Icon As Icon) Dim br As Brush Dim br2 As Brush Dim fDisposeBrush As Boolean Dim rand As Pen
Dim rcBk As Rectangle = EvDrawItems.Bounds rcBk.Height -= 1 rcBk.Width -= 1 If CBool(EvDrawItems.State And DrawItemState.Selected) Then br = New LinearGradientBrush(rcBk, Color.MediumPurple, Color.YellowGreen, 0) fDisposeBrush = True rand = New Pen(Color.DarkBlue, 1) EvDrawItems.Graphics.FillRectangle(br, rcBk) EvDrawItems.Graphics.DrawRectangle(rand, rcBk)
Else br = SystemBrushes.Control br2 = New SolidBrush(Color.WhiteSmoke) rand = System.Drawing.SystemPens.Control EvDrawItems.Graphics.DrawRectangle(rand, rcBk) rcBk.X += 24 rcBk.Width -= 23 rcBk.Y -= 1 rcBk.Height += 2 EvDrawItems.Graphics.FillRectangle(br2, rcBk) rcBk.X = 0 rcBk.Width = 24 EvDrawItems.Graphics.FillRectangle(br, rcBk) br2.Dispose()
End If
'Dim rcIcon As New Rectangle(EvDrawItems.Bounds.Left + 2, EvDrawItems.Bounds.Top + 2, m_Icon.Width, m_Icon.Height) 'EvDrawItems.Graphics.ExcludeClip(rcIcon)
If fDisposeBrush Then br.Dispose() br = Nothing
Dim sf As StringFormat = New StringFormat() sf.HotkeyPrefix = HotkeyPrefix.Show sf.SetTabStops(60, New Single() {0}) If Mi.Enabled Then br = New SolidBrush(EvDrawItems.ForeColor) Else br = New SolidBrush(Color.Gray) End If
EvDrawItems.Graphics.DrawString(GetRealText(Mi), m_Font, br, _ EvDrawItems.Bounds.Left + 25, _ EvDrawItems.Bounds.Top + 2, sf)
br.Dispose() br = Nothing sf.Dispose() sf = Nothing If Not m_Icon Is Nothing Then If Not Mi.Checked Then EvDrawItems.Graphics.DrawIcon(m_Icon, EvDrawItems.Bounds.Left + 2, _ EvDrawItems.Bounds.Top + 2) Else EvDrawItems.Graphics.DrawIcon(m_Icon, EvDrawItems.Bounds.Left + 2, _ EvDrawItems.Bounds.Top + 2)
End If
End If End Sub
Function GetRealText(ByVal Mi As MenuItem) As String Dim s As String = Mi.Text If Mi.ShowShortcut And Mi.Shortcut <> Shortcut.None Then Dim k As Keys = CType(Mi.Shortcut, Keys) s = s & Convert.ToChar(9) & _ TypeDescriptor.GetConverter(GetType(Keys)).Convert ToString(k) End If Return s End Function
End Module
Hi Rachel,
thnx for your reply, I know about memory leaks but the problem even
kicks in when there isn't an error in the prog, but when I just step
through it by placing a break in the code and then step through it,
that's why I think it's a strange error.
Grtz Peter
Rachel <Ra****@discussions.microsoft.com> wrote in message news:<BD**********************************@microso ft.com>... Good Evening Piedro,
Your problem is common to programmers. It is known as memory leak. You are not handling your errors with try catch statements and when that happens your computer still thinks it is running that program and will not release the memory unless you reboot.
My suggestion is to put a try catch such as the one below this way when a runtime error occurs it will release memory and you can at least debug without running out of memory. Try 'potential code that is having errors Catch ex As Exception MsgBox(ex.Message) End End Try
Rachel
"Piedro" wrote:
Can someone reproduce the following error?
I'm using the module at the bottom of my post to owner draw a menu items, I call the module from a form like this:
Private Sub mnuOpen_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles mnuOpen.DrawItem Dim Ic As New Icon(Application.StartupPath & "\101_72.ico") DrawItems(e, mnuOpen, Ic) End Sub
Private Sub mnuOpen_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles mnuOpen.MeasureItem MeasureItems(e, mnuOpen) End Sub
It al works just fine but if I try to debug and step through it, or if I type something wrong so that I get an error message at runtime. The next time I try to run it I keep getting this error message: An unhandled exception of type 'System.OutOfMemoryException' occurred in system.drawing.dll Additional information: Out of memory.
and then right clicking (even on the desktop) doesn't work like it should and I have to reboot my pc for everything to return to normal. Is there something wrong in the module. Or isn't it my fault?
thanks a lot 'Module om icoontjes aan een menu toe te voegen
Imports System Imports System.ComponentModel Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Drawing.Text Imports System.Windows.Forms
Module IconsMenuMain
Dim m_Font As New Font("Arial", 8)
Sub MeasureItems(ByVal EvMeasureItem As System.Windows.Forms.MeasureItemEventArgs, ByVal Mi As MenuItem) Dim sf As StringFormat = New StringFormat() sf.HotkeyPrefix = HotkeyPrefix.Show sf.SetTabStops(60, New Single() {0}) EvMeasureItem.ItemHeight = 22 EvMeasureItem.ItemWidth = CInt(EvMeasureItem.Graphics.MeasureString(GetRealT ext(Mi), _ m_Font, 10000, sf).Width) + 30 sf.Dispose() sf = Nothing End Sub
Sub DrawItems(ByVal EvDrawItems As System.Windows.Forms.DrawItemEventArgs, ByVal Mi As MenuItem, ByVal m_Icon As Icon) Dim br As Brush Dim br2 As Brush Dim fDisposeBrush As Boolean Dim rand As Pen
Dim rcBk As Rectangle = EvDrawItems.Bounds rcBk.Height -= 1 rcBk.Width -= 1 If CBool(EvDrawItems.State And DrawItemState.Selected) Then br = New LinearGradientBrush(rcBk, Color.MediumPurple, Color.YellowGreen, 0) fDisposeBrush = True rand = New Pen(Color.DarkBlue, 1) EvDrawItems.Graphics.FillRectangle(br, rcBk) EvDrawItems.Graphics.DrawRectangle(rand, rcBk)
Else br = SystemBrushes.Control br2 = New SolidBrush(Color.WhiteSmoke) rand = System.Drawing.SystemPens.Control EvDrawItems.Graphics.DrawRectangle(rand, rcBk) rcBk.X += 24 rcBk.Width -= 23 rcBk.Y -= 1 rcBk.Height += 2 EvDrawItems.Graphics.FillRectangle(br2, rcBk) rcBk.X = 0 rcBk.Width = 24 EvDrawItems.Graphics.FillRectangle(br, rcBk) br2.Dispose()
End If
'Dim rcIcon As New Rectangle(EvDrawItems.Bounds.Left + 2, EvDrawItems.Bounds.Top + 2, m_Icon.Width, m_Icon.Height) 'EvDrawItems.Graphics.ExcludeClip(rcIcon)
If fDisposeBrush Then br.Dispose() br = Nothing
Dim sf As StringFormat = New StringFormat() sf.HotkeyPrefix = HotkeyPrefix.Show sf.SetTabStops(60, New Single() {0}) If Mi.Enabled Then br = New SolidBrush(EvDrawItems.ForeColor) Else br = New SolidBrush(Color.Gray) End If
EvDrawItems.Graphics.DrawString(GetRealText(Mi), m_Font, br, _ EvDrawItems.Bounds.Left + 25, _ EvDrawItems.Bounds.Top + 2, sf)
br.Dispose() br = Nothing sf.Dispose() sf = Nothing If Not m_Icon Is Nothing Then If Not Mi.Checked Then EvDrawItems.Graphics.DrawIcon(m_Icon, EvDrawItems.Bounds.Left + 2, _ EvDrawItems.Bounds.Top + 2) Else EvDrawItems.Graphics.DrawIcon(m_Icon, EvDrawItems.Bounds.Left + 2, _ EvDrawItems.Bounds.Top + 2)
End If
End If End Sub
Function GetRealText(ByVal Mi As MenuItem) As String Dim s As String = Mi.Text If Mi.ShowShortcut And Mi.Shortcut <> Shortcut.None Then Dim k As Keys = CType(Mi.Shortcut, Keys) s = s & Convert.ToChar(9) & _ TypeDescriptor.GetConverter(GetType(Keys)).Convert ToString(k) End If Return s End Function
End Module This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Eric Boutin |
last post by:
Hi ! I have a strange problem with a std::ostringstream..
code :
#include <sstream>
/*...*/
std::ostringstream ss();
ss << "\"\"" << libpath << "\"\" \"\"" << argfilename << "\"\"...
|
by: brckcc |
last post by:
I'm attempting to use XmlTextReader. When I call the Read() method I get the following error
"The data at the root level is invalid. Line 1, position 1.
The xml is formatted fine. The first...
|
by: Neil Ginsberg |
last post by:
I have a strange situation with my Access 2000 database. I have code in the
database which has worked fine for years, and now all of a sudden doesn't
work fine on one or two of my client's...
|
by: Kris Vanherck |
last post by:
yesterday i started getting this strange error when i try to run my asp.net
project:
Compiler Error Message: CS0006: Metadata file
'c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net...
|
by: Nathan Sokalski |
last post by:
When I view my index.aspx page any time after the first time, I recieve the
following error:
System.Web.TraceContext.AddNewControl(String id, String parentId, String
type, Int32 viewStateSize)...
|
by: ivb |
last post by:
Hi all,
I am using DB2 8.1.11.1 on NT with ASP.NET 1.1
When application make connection to database (via ADO.NET), it set
"Connection timeout" parameter to 30 seconds.
After, when my webpage...
|
by: Martin Joergensen |
last post by:
Hi,
I've encountered a really, *really*, REALLY strange error :-)
I have a for-loop and after 8 runs I get strange results...... I
mean: A really strange result....
I'm calculating...
|
by: Mike C# |
last post by:
Hi all,
I keep getting a strange error and can't pin it down. The message is:
This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's...
|
by: Shelly |
last post by:
I am encountering two strange problems.
First one:
I get a "server misconfiguration error", but only sometimes. It occurs on
the first screen that accesses the database on a submit. This error...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |