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_DrawIte m(ByVal sender As Object, ByVal e As
System.Windows. Forms.DrawItemE ventArgs) Handles mnuOpen.DrawIte m
Dim Ic As New Icon(Applicatio n.StartupPath & "\101_72.ic o")
DrawItems(e, mnuOpen, Ic)
End Sub
Private Sub mnuOpen_Measure Item(ByVal sender As Object, ByVal e As
System.Windows. Forms.MeasureIt emEventArgs) Handles mnuOpen.Measure Item
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.OutOfMe moryException' 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.Componen tModel
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(By Val EvMeasureItem As
System.Windows. Forms.MeasureIt emEventArgs, ByVal Mi As MenuItem)
Dim sf As StringFormat = New StringFormat()
sf.HotkeyPrefix = HotkeyPrefix.Sh ow
sf.SetTabStops( 60, New Single() {0})
EvMeasureItem.I temHeight = 22
EvMeasureItem.I temWidth =
CInt(EvMeasureI tem.Graphics.Me asureString(Get RealText(Mi), _
m_Font,
10000, sf).Width) + 30
sf.Dispose()
sf = Nothing
End Sub
Sub DrawItems(ByVal EvDrawItems As
System.Windows. Forms.DrawItemE ventArgs, 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.Bou nds
rcBk.Height -= 1
rcBk.Width -= 1
If CBool(EvDrawIte ms.State And DrawItemState.S elected) Then
br = New LinearGradientB rush(rcBk, Color.MediumPur ple,
Color.YellowGre en, 0)
fDisposeBrush = True
rand = New Pen(Color.DarkB lue, 1)
EvDrawItems.Gra phics.FillRecta ngle(br, rcBk)
EvDrawItems.Gra phics.DrawRecta ngle(rand, rcBk)
Else
br = SystemBrushes.C ontrol
br2 = New SolidBrush(Colo r.WhiteSmoke)
rand = System.Drawing. SystemPens.Cont rol
EvDrawItems.Gra phics.DrawRecta ngle(rand, rcBk)
rcBk.X += 24
rcBk.Width -= 23
rcBk.Y -= 1
rcBk.Height += 2
EvDrawItems.Gra phics.FillRecta ngle(br2, rcBk)
rcBk.X = 0
rcBk.Width = 24
EvDrawItems.Gra phics.FillRecta ngle(br, rcBk)
br2.Dispose()
End If
'Dim rcIcon As New Rectangle(EvDra wItems.Bounds.L eft + 2,
EvDrawItems.Bou nds.Top + 2, m_Icon.Width, m_Icon.Height)
'EvDrawItems.Gr aphics.ExcludeC lip(rcIcon)
If fDisposeBrush Then br.Dispose()
br = Nothing
Dim sf As StringFormat = New StringFormat()
sf.HotkeyPrefix = HotkeyPrefix.Sh ow
sf.SetTabStops( 60, New Single() {0})
If Mi.Enabled Then
br = New SolidBrush(EvDr awItems.ForeCol or)
Else
br = New SolidBrush(Colo r.Gray)
End If
EvDrawItems.Gra phics.DrawStrin g(GetRealText(M i), m_Font, br, _
EvDrawItems.Bou nds.Left + 25,
_
EvDrawItems.Bou nds.Top + 2,
sf)
br.Dispose()
br = Nothing
sf.Dispose()
sf = Nothing
If Not m_Icon Is Nothing Then
If Not Mi.Checked Then
EvDrawItems.Gra phics.DrawIcon( m_Icon,
EvDrawItems.Bou nds.Left + 2, _
EvDrawItems.Bou nds.Top +
2)
Else
EvDrawItems.Gra phics.DrawIcon( m_Icon,
EvDrawItems.Bou nds.Left + 2, _
EvDrawItems.Bou nds.Top +
2)
End If
End If
End Sub
Function GetRealText(ByV al 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.Shortc ut, Keys)
s = s & Convert.ToChar( 9) & _
TypeDescriptor. GetConverter(Ge tType(Keys)).Co nvertToString(k )
End If
Return s
End Function
End Module 2 2640
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.Messa ge)
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_DrawIte m(ByVal sender As Object, ByVal e As System.Windows. Forms.DrawItemE ventArgs) Handles mnuOpen.DrawIte m Dim Ic As New Icon(Applicatio n.StartupPath & "\101_72.ic o") DrawItems(e, mnuOpen, Ic) End Sub
Private Sub mnuOpen_Measure Item(ByVal sender As Object, ByVal e As System.Windows. Forms.MeasureIt emEventArgs) Handles mnuOpen.Measure Item 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.OutOfMe moryException' 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.Componen tModel 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(By Val EvMeasureItem As System.Windows. Forms.MeasureIt emEventArgs, ByVal Mi As MenuItem) Dim sf As StringFormat = New StringFormat() sf.HotkeyPrefix = HotkeyPrefix.Sh ow sf.SetTabStops( 60, New Single() {0}) EvMeasureItem.I temHeight = 22 EvMeasureItem.I temWidth = CInt(EvMeasureI tem.Graphics.Me asureString(Get RealText(Mi), _ m_Font, 10000, sf).Width) + 30 sf.Dispose() sf = Nothing End Sub
Sub DrawItems(ByVal EvDrawItems As System.Windows. Forms.DrawItemE ventArgs, 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.Bou nds rcBk.Height -= 1 rcBk.Width -= 1 If CBool(EvDrawIte ms.State And DrawItemState.S elected) Then br = New LinearGradientB rush(rcBk, Color.MediumPur ple, Color.YellowGre en, 0) fDisposeBrush = True rand = New Pen(Color.DarkB lue, 1) EvDrawItems.Gra phics.FillRecta ngle(br, rcBk) EvDrawItems.Gra phics.DrawRecta ngle(rand, rcBk)
Else br = SystemBrushes.C ontrol br2 = New SolidBrush(Colo r.WhiteSmoke) rand = System.Drawing. SystemPens.Cont rol EvDrawItems.Gra phics.DrawRecta ngle(rand, rcBk) rcBk.X += 24 rcBk.Width -= 23 rcBk.Y -= 1 rcBk.Height += 2 EvDrawItems.Gra phics.FillRecta ngle(br2, rcBk) rcBk.X = 0 rcBk.Width = 24 EvDrawItems.Gra phics.FillRecta ngle(br, rcBk) br2.Dispose()
End If
'Dim rcIcon As New Rectangle(EvDra wItems.Bounds.L eft + 2, EvDrawItems.Bou nds.Top + 2, m_Icon.Width, m_Icon.Height) 'EvDrawItems.Gr aphics.ExcludeC lip(rcIcon)
If fDisposeBrush Then br.Dispose() br = Nothing
Dim sf As StringFormat = New StringFormat() sf.HotkeyPrefix = HotkeyPrefix.Sh ow sf.SetTabStops( 60, New Single() {0}) If Mi.Enabled Then br = New SolidBrush(EvDr awItems.ForeCol or) Else br = New SolidBrush(Colo r.Gray) End If
EvDrawItems.Gra phics.DrawStrin g(GetRealText(M i), m_Font, br, _ EvDrawItems.Bou nds.Left + 25, _ EvDrawItems.Bou nds.Top + 2, sf)
br.Dispose() br = Nothing sf.Dispose() sf = Nothing If Not m_Icon Is Nothing Then If Not Mi.Checked Then EvDrawItems.Gra phics.DrawIcon( m_Icon, EvDrawItems.Bou nds.Left + 2, _ EvDrawItems.Bou nds.Top + 2) Else EvDrawItems.Gra phics.DrawIcon( m_Icon, EvDrawItems.Bou nds.Left + 2, _ EvDrawItems.Bou nds.Top + 2)
End If
End If End Sub
Function GetRealText(ByV al 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.Shortc ut, Keys) s = s & Convert.ToChar( 9) & _ TypeDescriptor. GetConverter(Ge tType(Keys)).Co nvertToString(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****@discuss ions.microsoft. com> wrote in message news:<BD******* *************** ************@mi crosoft.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.Messa ge) 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_DrawIte m(ByVal sender As Object, ByVal e As System.Windows. Forms.DrawItemE ventArgs) Handles mnuOpen.DrawIte m Dim Ic As New Icon(Applicatio n.StartupPath & "\101_72.ic o") DrawItems(e, mnuOpen, Ic) End Sub
Private Sub mnuOpen_Measure Item(ByVal sender As Object, ByVal e As System.Windows. Forms.MeasureIt emEventArgs) Handles mnuOpen.Measure Item 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.OutOfMe moryException' 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.Componen tModel 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(By Val EvMeasureItem As System.Windows. Forms.MeasureIt emEventArgs, ByVal Mi As MenuItem) Dim sf As StringFormat = New StringFormat() sf.HotkeyPrefix = HotkeyPrefix.Sh ow sf.SetTabStops( 60, New Single() {0}) EvMeasureItem.I temHeight = 22 EvMeasureItem.I temWidth = CInt(EvMeasureI tem.Graphics.Me asureString(Get RealText(Mi), _ m_Font, 10000, sf).Width) + 30 sf.Dispose() sf = Nothing End Sub
Sub DrawItems(ByVal EvDrawItems As System.Windows. Forms.DrawItemE ventArgs, 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.Bou nds rcBk.Height -= 1 rcBk.Width -= 1 If CBool(EvDrawIte ms.State And DrawItemState.S elected) Then br = New LinearGradientB rush(rcBk, Color.MediumPur ple, Color.YellowGre en, 0) fDisposeBrush = True rand = New Pen(Color.DarkB lue, 1) EvDrawItems.Gra phics.FillRecta ngle(br, rcBk) EvDrawItems.Gra phics.DrawRecta ngle(rand, rcBk)
Else br = SystemBrushes.C ontrol br2 = New SolidBrush(Colo r.WhiteSmoke) rand = System.Drawing. SystemPens.Cont rol EvDrawItems.Gra phics.DrawRecta ngle(rand, rcBk) rcBk.X += 24 rcBk.Width -= 23 rcBk.Y -= 1 rcBk.Height += 2 EvDrawItems.Gra phics.FillRecta ngle(br2, rcBk) rcBk.X = 0 rcBk.Width = 24 EvDrawItems.Gra phics.FillRecta ngle(br, rcBk) br2.Dispose()
End If
'Dim rcIcon As New Rectangle(EvDra wItems.Bounds.L eft + 2, EvDrawItems.Bou nds.Top + 2, m_Icon.Width, m_Icon.Height) 'EvDrawItems.Gr aphics.ExcludeC lip(rcIcon)
If fDisposeBrush Then br.Dispose() br = Nothing
Dim sf As StringFormat = New StringFormat() sf.HotkeyPrefix = HotkeyPrefix.Sh ow sf.SetTabStops( 60, New Single() {0}) If Mi.Enabled Then br = New SolidBrush(EvDr awItems.ForeCol or) Else br = New SolidBrush(Colo r.Gray) End If
EvDrawItems.Gra phics.DrawStrin g(GetRealText(M i), m_Font, br, _ EvDrawItems.Bou nds.Left + 25, _ EvDrawItems.Bou nds.Top + 2, sf)
br.Dispose() br = Nothing sf.Dispose() sf = Nothing If Not m_Icon Is Nothing Then If Not Mi.Checked Then EvDrawItems.Gra phics.DrawIcon( m_Icon, EvDrawItems.Bou nds.Left + 2, _ EvDrawItems.Bou nds.Top + 2) Else EvDrawItems.Gra phics.DrawIcon( m_Icon, EvDrawItems.Bou nds.Left + 2, _ EvDrawItems.Bou nds.Top + 2)
End If
End If End Sub
Function GetRealText(ByV al 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.Shortc ut, Keys) s = s & Convert.ToChar( 9) & _ TypeDescriptor. GetConverter(Ge tType(Keys)).Co nvertToString(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 << "\"\" \"\""
<< outfilename << "\"\""; //line 75
|
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 entry in the xml file is a valid tag
What does this error trying to tell me. I can read the file using a TextReader class just fine
|
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 machines. The code opens MS Word
through Automation and then opens a particular Word doc. It's still working
fine on most machines; but on one or two of them, the user is getting an
Automation Error. The code used is as follows:
Dim objWord As...
|
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
files\spsweb\0e3514bf\cb1844e7\assembly\dl2\3b163f
16\00452d31_84e5c301\infragistics.webui.ultrawebgrid.v3.dll' could not be
found
|
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) +313
System.Web.UI.Control.BuildProfileTree(String parentId, Boolean
calcViewState) +201
System.Web.UI.Control.BuildProfileTree(String parentId, Boolean
calcViewState) +263
| |
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 requests database, and query execution time
exceeds 30 seconds, the following error reported:
===
|
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 temperatures. T = 20 degrees at all
times.... The 2D T-array looks like this:
|
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 support team for more information.
However I'm not purposely requesting that the Runtime terminate in an
"unusual way." The line that is causing me headaches is:
|
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 is
intermittent -- sometimes it happens and sometimes not from the same screen
with the same data.
Here is the error:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |