473,387 Members | 3,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 OnPaintBackground 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.InvalidOperationException'
occurred in system.drawing.dll

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

system.drawing.dll!System.Drawing.Graphics.CheckEr rorStatus(int
status = 4) + 0x41 bytes
system.drawing.dll!System.Drawing.Graphics.FillRec tangle(System.Drawing.Brush
brush = {Color={RGB=0x0}}, int x = 0, int y = 0, int width = 74, int
height = 159) + 0xc2 bytes
system.drawing.dll!System.Drawing.Graphics.FillRec tangle(System.Drawing.Brush
brush = {Color={RGB=0x0}}, System.Drawing.Rectangle rect = {X=0 Y=0
Width=74 Height=159}) + 0x60 bytes
worldeditpanes.dll!WorldEditPanes.AtasPropertyList .OnPaintBackground(System.Windows.Forms.PaintEvent Args

e = 0x0012ba00) Line 353
worldeditpanes.dll!WorldEditPanes.AtasPropertyList .WndProc(System.Windows.Forms.Message
message = 0x0012bb18) Line 554
system.windows.forms.dll!ControlNativeWindow.OnMes sage(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x13 bytes
system.windows.forms.dll!ControlNativeWindow.WndPr oc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0xda bytes
system.windows.forms.dll!System.Windows.Forms.Nati veWindow.DebuggableCallback(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(GetUpdateRect(hwnd, updateRect, false) == 0)
break;
System::Drawing::Rectangle managedRect =
Rectangle::FromLTRB(updateRect->left, updateRect->top,
updateRect->right, updateRect->bottom);

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

//Add the missing OnPaintBackground() call
OnPaintBackground(new PaintEventArgs(mInternalGraphics, managedRect));

//Draw Internal Graphics
IntPtr hdc = mInternalGraphics->GetHdc();
Message printClientMessage = Message::Create(Handle, WM_PRINTCLIENT,
hdc, IntPtr::Zero);
DefWndProc(&printClientMessage);
mInternalGraphics->ReleaseHdc( hdc );

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

//Draw Screen Graphics
screenGraphics->DrawImage(mInternalBitmap, 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.

OnPaintBackground (where the crash happens) looks like:

void AtasPropertyList::OnPaintBackground(PaintEventArgs * 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(Color::LightGray);
e->Graphics->FillRectangle(brush, rcl);
brush->Dispose();
}
rcl = System::Drawing::Rectangle(width, 0, Width - width, Height);
if(!rcl.IsEmpty)
{
SolidBrush *brush = new SolidBrush(Color::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 PropertyListButton::OnPaint(PaintEventArgs *e)
{
if (mPushed)
{
if (FlatStyle == System::Windows::Forms::FlatStyle::Flat)
{
e->Graphics->FillRectangle(new SolidBrush(BackColor), 0, 0,
ClientSize.Width, ClientSize.Height);
DrawItem(e->Graphics, 0, 0);
}
else
{
ControlPaint::DrawButton(e->Graphics, 0, 0, Width, Height,
ButtonState::Pushed);
DrawItem(e->Graphics, 1, 1);
}
}
else
{
if (FlatStyle == System::Windows::Forms::FlatStyle::Flat)
{
e->Graphics->FillRectangle(new SolidBrush(BackColor), 0, 0,
ClientSize.Width, ClientSize.Height);
DrawItem(e->Graphics, 0, 0);
}
else
{
ControlPaint::DrawButton(e->Graphics, 0, 0, Width, Height,
ButtonState::Normal);
DrawItem(e->Graphics, 0, 0);
}
}
}
void PropertyListButton::DrawItem(Graphics *g, int xOffset, int
yOffset)
{
if (Image == NULL)
{
StringFormat *strf = new StringFormat();
strf->Alignment = StringAlignment::Center;
strf->LineAlignment = StringAlignment::Center;

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

int xPos = (ClientSize.Width - (int)Math::Ceiling(szf.Width)) / 2;
int yPos = (ClientSize.Height - (int)Math::Ceiling(szf.Height)) /
2;

RectangleF rf((float)(xPos + xOffset), (float)(yPos + yOffset),
szf.Width, szf.Height);
g->DrawString(Text, Font, new SolidBrush(ForeColor), rf, strf);
}
else
{
int xPos = (ClientSize.Width - Image->Width) / 2;
int yPos = (ClientSize.Height - Image->Height) / 2;

g->DrawImage(Image, 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 2151

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

Similar topics

1
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...
0
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...
3
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...
2
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...
4
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...
7
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...
1
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...
5
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.