C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-03-2009, 05:06 PM   #1
Registered User
 
Join Date: Dec 2005
Posts: 51
Control with image loaded from file, cant view in designer

I have a control that loads an image in the OnLoad and displays this image in OnPaint. However, when I try to use the control on a form, I can't view the form because of the following error:

Parameter is not valid.

at System.Drawing.Bitmap..ctor(String filename)
at Card_Creator.Item_Preview.Item_Preview_Load(Object sender, EventArgs e) in C:\Users\Jeremy\Desktop\SVN\Source Code\Card Creator\Card Creator\Item Preview.cs:line 72


I have seen this issue a few times in the office with trying to reference config files that are loaded in. Is there a way to work around this so I can load something in and not have the designer barf on it?


[Edit: Spelling]
JeremyCAFE is offline   Reply With Quote
Old 09-03-2009, 11:57 PM   #2
Confused
 
Magos's Avatar
 
Join Date: Sep 2001
Location: Sweden
Posts: 3,125
Check the (inherited) DesignMode property. If this is True, don't load the image.
This property won't work in the constructor, check it in OnLoad.
__________________
MagosX.com

Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Magos is offline   Reply With Quote
Old 09-04-2009, 06:57 AM   #3
Registered User
 
Join Date: Dec 2005
Posts: 51
Thank you. this is perfect for solving the issue.
JeremyCAFE is offline   Reply With Quote
Old 09-04-2009, 08:50 AM   #4
Registered User
 
Join Date: Dec 2005
Posts: 51
hmm, so the solution is not working if the control with the check is double embedded. (used on a parent control, in which that parent control is used on another control)

Code:
if(!DesignMode)
{
          bmpCardBackground = new Bitmap("tressure_bg.png");
}
JeremyCAFE is offline   Reply With Quote
Old 09-04-2009, 09:45 AM   #5
Confused
 
Magos's Avatar
 
Join Date: Sep 2001
Location: Sweden
Posts: 3,125
Quote:
is not working
Being more specific would be helpful.
__________________
MagosX.com

Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Magos is offline   Reply With Quote
Old 09-04-2009, 11:04 AM   #6
Registered User
 
Join Date: Dec 2005
Posts: 51
Quote:
Originally Posted by Magos View Post
Being more specific would be helpful.

I am getting the same error I was getting before on the top most parent now.


Control 1 (with loaded image) is put onto control 2.

Control 2 is put onto Form. Form cannot load and is giving the error shown in first post. Builds fine, just can't view it in the designer.
JeremyCAFE is offline   Reply With Quote
Old 09-04-2009, 12:56 PM   #7
Confused
 
Magos's Avatar
 
Join Date: Sep 2001
Location: Sweden
Posts: 3,125
Try using a full path (C:\Folder1\Folder2\Image.png) instead of a relative that you use now.
Also you spell "treasure" as "tressure", typo or error?
You could also try another image, like a jpg. Perhaps your png is saved in a weird format that the bitmap class can't handle?
That's all I can think of now.
__________________
MagosX.com

Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Magos is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A development process Noir C Programming 32 12-19-2009 10:15 AM
Memory Address kevinawad C++ Programming 18 10-19-2008 10:27 AM
Need Help Fixing My C Program. Deals with File I/O Matus C Programming 7 04-29-2008 07:51 PM
C++ std routines siavoshkc C++ Programming 33 07-28-2006 12:13 AM
Unknown Memory Leak in Init() Function CodeHacker Windows Programming 3 07-09-2004 09:54 AM


All times are GMT -6. The time now is 04:33 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22