473,848 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unhandled exception : The object is currently in use elsewhere while resizing control

I have a ListView control, for which I have overwritten the WndProc
method to gain access to the WM_PAINT message and generate my own
OnPaint and OnPaintBackgrou nd messages, in order to colour the columns
of the listview to my liking. When a row of the listview is selected,
some controls are displayed on that row of the listview (so sort of
like a property list thingy). In order to get the controls
(specifically buttons) to display how I wanted them, I have created a
button subclass that also overrides its OnPaint method.

If I resize the listview (by resizing the form it is on), while these
child controls are displayed, I get the following unex error:
An unhandled exception of type 'System.Invalid OperationExcept ion'
occurred in system.drawing. dll

Additional information: The object is currently in use elsewhere.
The call stack is:

system.drawing. dll!System.Draw ing.Graphics.Ch eckErrorStatus( int
status = 4) + 0x41 bytes
system.drawing. dll!System.Draw ing.Graphics.Fi llRectangle(Sys tem.Drawing.Bru sh
brush = {Color={RGB=0x0 }}, int x = 0, int y = 0, int width = 74, int
height = 159) + 0xc2 bytes
system.drawing. dll!System.Draw ing.Graphics.Fi llRectangle(Sys tem.Drawing.Bru sh
brush = {Color={RGB=0x0 }}, System.Drawing. Rectangle rect = {X=0 Y=0
Width=74 Height=159}) + 0x60 bytes
worldeditpanes. dll!WorldEditPa nes.AtasPropert yList.OnPaintBa ckground(System .Windows.Forms. PaintEventArgs

e = 0x0012ba00) Line 353
worldeditpanes. dll!WorldEditPa nes.AtasPropert yList.WndProc(S ystem.Windows.F orms.Message
message = 0x0012bb18) Line 554
system.windows. forms.dll!Contr olNativeWindow. OnMessage(Syste m.Windows.Forms .Message
m = {System.Windows .Forms.Message} ) + 0x13 bytes
system.windows. forms.dll!Contr olNativeWindow. WndProc(System. Windows.Forms.M essage
m = {System.Windows .Forms.Message} ) + 0xda bytes
system.windows. forms.dll!Syste m.Windows.Forms .NativeWindow.D ebuggableCallba ck(int
hWnd = 133842, int msg = 15, int wparam = 0, int lparam = 0) + 0x3d
bytes

blah, blah, blah...
The relevant code snippets follow. First of all, here is part of my
WndProc method...
//Set up
HWND hwnd = (HWND)message->HWnd.ToInt32() ;
RECT *updateRect = new RECT();
if(GetUpdateRec t(hwnd, updateRect, false) == 0)
break;
System::Drawing ::Rectangle managedRect =
Rectangle::From LTRB(updateRect->left, updateRect->top,
updateRect->right, updateRect->bottom);

PAINTSTRUCT *paintStruct = new PAINTSTRUCT();
IntPtr screenHdc = BeginPaint(hwnd , paintStruct);
Graphics *screenGraphics = Graphics::FromH dc(screenHdc);

//Add the missing OnPaintBackgrou nd() call
OnPaintBackgrou nd(new PaintEventArgs( mInternalGraphi cs, managedRect));

//Draw Internal Graphics
IntPtr hdc = mInternalGraphi cs->GetHdc();
Message printClientMess age = Message::Create (Handle, WM_PRINTCLIENT,
hdc, IntPtr::Zero);
DefWndProc(&pri ntClientMessage );
mInternalGraphi cs->ReleaseHdc( hdc );

//Add the missing OnPaint() call
OnPaint(new PaintEventArgs( mInternalGraphi cs, managedRect));

//Draw Screen Graphics
screenGraphics->DrawImage(mInt ernalBitmap, 0, 0);
screenGraphics->Dispose();

//Tear down
EndPaint(hwnd, paintStruct);
return;
I got that off the web somewhere, and until I added the whole child
control thing it has worked fine.

OnPaintBackgrou nd (where the crash happens) looks like:

void AtasPropertyLis t::OnPaintBackg round(PaintEven tArgs* e)
{
int width = Columns->Item[0]->Width + Columns->Item[1]->Width;
System::Drawing ::Rectangle rcl = System::Drawing ::Rectangle(0, 0,
width, Height);
if(!rcl.IsEmpty )
{
SolidBrush *brush = new SolidBrush(Colo r::LightGray);
e->Graphics->FillRectangle( brush, rcl);
brush->Dispose();
}
rcl = System::Drawing ::Rectangle(wid th, 0, Width - width, Height);
if(!rcl.IsEmpty )
{
SolidBrush *brush = new SolidBrush(Colo r::White);
e->Graphics->FillRectangle( brush, rcl);
brush->Dispose();
}
}

The idea being that the first two columns are grey and the rest are
white.
Finally, the ownerdrawn button OnPaint code (which I suspect is
contributing to the problem:

void PropertyListBut ton::OnPaint(Pa intEventArgs *e)
{
if (mPushed)
{
if (FlatStyle == System::Windows ::Forms::FlatSt yle::Flat)
{
e->Graphics->FillRectangle( new SolidBrush(Back Color), 0, 0,
ClientSize.Widt h, ClientSize.Heig ht);
DrawItem(e->Graphics, 0, 0);
}
else
{
ControlPaint::D rawButton(e->Graphics, 0, 0, Width, Height,
ButtonState::Pu shed);
DrawItem(e->Graphics, 1, 1);
}
}
else
{
if (FlatStyle == System::Windows ::Forms::FlatSt yle::Flat)
{
e->Graphics->FillRectangle( new SolidBrush(Back Color), 0, 0,
ClientSize.Widt h, ClientSize.Heig ht);
DrawItem(e->Graphics, 0, 0);
}
else
{
ControlPaint::D rawButton(e->Graphics, 0, 0, Width, Height,
ButtonState::No rmal);
DrawItem(e->Graphics, 0, 0);
}
}
}
void PropertyListBut ton::DrawItem(G raphics *g, int xOffset, int
yOffset)
{
if (Image == NULL)
{
StringFormat *strf = new StringFormat();
strf->Alignment = StringAlignment ::Center;
strf->LineAlignmen t = StringAlignment ::Center;

SizeF szf = g->MeasureString( Text, Font);

int xPos = (ClientSize.Wid th - (int)Math::Ceil ing(szf.Width)) / 2;
int yPos = (ClientSize.Hei ght - (int)Math::Ceil ing(szf.Height) ) /
2;

RectangleF rf((float)(xPos + xOffset), (float)(yPos + yOffset),
szf.Width, szf.Height);
g->DrawString(Tex t, Font, new SolidBrush(Fore Color), rf, strf);
}
else
{
int xPos = (ClientSize.Wid th - Image->Width) / 2;
int yPos = (ClientSize.Hei ght - Image->Height) / 2;

g->DrawImage(Imag e, xPos + xOffset, yPos + yOffset, Image->Width,
Image->Height);
}
}
I am not running multiple threads (most of the info about this error
seemed to be about multi-threading)

Any ideas?
Nov 17 '05 #1
0 2185

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
536
by: Rafael | last post by:
Hi, I hope I can find some help for this problem IDE: Visual Studio.NET 2003 Developer Editio Language: C# Problem: "An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll. Additional information: Object reference not set to an instance of an object. Visual Studio's IDE is not allowing me to develop projects in C#... I've trying to create a simple Windows Forms project using Visual Studio.NET...
0
1549
by: Oliver | last post by:
Hello, I may have posted in the wrong place, if so, feel free to move my post (just notify me where you put it via email or something) I’m having a problem with my program that I cant readily explain. The program connects to, then reads and creates a new flat old Dbase files (.DBF) stored on a network drive. The program itself is run from the very same network drive/folder.
3
2961
by: Professor Frink | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms application that is going to be used to extract data from a legacy system (VSAM based mainframe file structure), and output data in pipe-delimited record layouts, multiple record types per file, one file per chosen client. I have been working on...
2
2095
by: Maqsood Ahmed | last post by:
Hello! We have experienced following exception in our application that runs over .net v1.0, I had gone through the internet to find an answer about it but failed to do so. I had found a comment about this exception by Mr. Bob Powell (MVP). Now I want to know that if this problem presists in .net framework v1.1?? --------------- System.InvalidOperationException: The object is currently in use
4
2257
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms application that is going to be used to extract data from a legacy system (VSAM based mainframe file structure), and output data in pipe-delimited record layouts, multiple record types per file, one file per chosen client. I have been working on...
7
2720
by: Chuck Hartman | last post by:
I have a Windows service that requests web pages from a site using an HttpWebRequest object. When I try to request a page from an ASP.NET 2 site, I get a WebException with message "The remote server returned an error: (500) Internal Server Error." I found a post that suggested to catch the WebException to retrieve the actual HttpWebResponse object for more information. The response returned is shown below. At first I thought this was a...
1
2111
by: mike | last post by:
My program is crashing, but it doesn't crash on a single line of code. Below is what the output tab displays. I have no idea where to start inorder to debug this problem. Is there any suggesstions on how to start debuging the problem 'DefaultDomain': Loaded 'c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll', No symbols loaded 'StoredProcedure': Loaded 'N:\Dev\Programs\MNTEST3.net\Template.NET\bin\StoredProcedure.exe', No symbols...
5
3317
by: Samuel R. Neff | last post by:
When you have an unhandled exception in vb.net how do you view the exception information in the debugger? In C# the debugger creates a local variable that points to the exception and you can view it in one of the windows (autos or locals, don't remember which). That doesn't appear to be the case with vb.net. I also tried using the command window to inspect "Err" but that gave nothing useful (always empty).
0
1761
by: statlerw | last post by:
I have successfully implemented drag and drop in my application to allow the reordering of columns by dragging and dropping them in the same datagridvire (Net 2.0). If i take it relatively slowly this works perfectly. However, if I perform consecutive drag and drops quickly, the code seems to trip over itself and throws the exception or other similar ones as per below. The main problem is that no matter where I try to catch this...
0
9893
marktang
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...
0
9738
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,...
0
10664
jinu1996
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...
1
10722
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,...
0
10348
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7069
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();...
0
5919
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4137
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3175
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.