Control with image loaded from file, cant view in designer

This is a discussion on Control with image loaded from file, cant view in designer within the C# Programming forums, part of the General Programming Boards category; I have a control that loads an image in the OnLoad and displays this image in OnPaint. However, when I ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    54

    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]

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    54
    Thank you. this is perfect for solving the issue.

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    54
    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");
    }

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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.

  6. #6
    Registered User
    Join Date
    Dec 2005
    Posts
    54
    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.

  7. #7
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM

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