My name is Akmal. And I try to use C# for my job. I need to draw some images on PictureBox control. This is code:
C# |
Try to run this code and you will see the erorr. But i don't uderstand where the problem in my code?
Please help me.
C# |
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Prasant JinagaRank #2,383 · 594 reputationPosted Feb 14, 2011, 1:55 AM EST
Put the image in solution explorer and try..Hope it will work.
Thanks,
Prasant
Suthish NairRank #92 · 22.8K reputationPosted Feb 14, 2011, 5:10 AM EST
Sam HobbsRank #107 · 20.5K reputationPosted Feb 14, 2011, 1:14 PM EST
Akmal Ali16 reputationPosted Feb 14, 2011, 6:57 PM EST
Below I will show the error message and a screen shot.
/*
System.ArgumentException ?? ??????????
Message="???????????? ????????."
Source="System.Drawing"
StackTrace:
? System.Drawing.Image.get_Width()
? System.Drawing.Image.get_Size()
? System.Windows.Forms.PictureBox.ImageRectangleFromSizeMode(PictureBoxSizeMode mode)
? System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
? System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
? System.Windows.Forms.Control.WmPaint(Message& m)
? System.Windows.Forms.Control.WndProc(Message& m)
? System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
? System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
? System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
? System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
? System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
? System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
? System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
? System.Windows.Forms.Application.Run(Form mainForm)
? test_Move_Image.Program.Main() ? C:\Documents and Settings\?????????????\??? ?????????\Visual Studio 2008\Projects\test_Move_Image\test_Move_Image\Program.cs:?????? 18
? System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
? System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
? Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
? System.Threading.ThreadHelper.ThreadStart_Context(Object state)
? System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
? System.Threading.ThreadHelper.ThreadStart()
InnerException:
*/
Sam HobbsRank #107 · 20.5K reputationPosted Feb 14, 2011, 7:36 PM EST
When I remove (comment out) the lines that call tgr.Dispose() and tbmp.Dispose() then the error is gone. I am not experienced with graphics in .Net but I really doubt that you need to call Dispose for those two objects; it is probably just a problem to call Dispose for them.
Akmal Ali16 reputationPosted Feb 14, 2011, 7:47 PM EST
Sam HobbsRank #107 · 20.5K reputationPosted Feb 14, 2011, 8:14 PM EST
You did not say if you understand about Paint. I think the answer to the question of why you are getting the error is that Windows needs the object to do the Paint. If you don't understand about painting in Windows then you need to learn about that.
Here is a simple rule. Don't call Dispose unless you know you need it.
FroglegRank #1,020 · 1.9K reputationPosted Feb 14, 2011, 8:25 PM EST
map = tbmp;
use
Rectangle rct = new Rectangle(0,0,tbmp.Width,tbmp.Height);
map = tbmp.Clone(rct, tbmp.PixelFormat);
if map is equal to tbmp and tbmp is disposed - map = null
Sam HobbsRank #107 · 20.5K reputationPosted Feb 14, 2011, 8:33 PM EST
Akmal Ali16 reputationPosted Feb 14, 2011, 8:48 PM EST
Thank's to all for your assistance and for your attention.
Suthish NairRank #92 · 22.8K reputationPosted Feb 15, 2011, 9:48 PM EST