Click here to Skip to main content
15,891,694 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this problem for many years but I never address it.
I have this custom control:
C#
using System.IO;
...............
    public partial class VIRxC : UserControl
    {
        public VIRxC()
        {
            InitializeComponent();
            image01 = Bitmap.FromFile(root + "Ohms Law Pie Chart.gif");
        }

        Image image01;
        string root = @"D:\Programe\Info\Visual Studio 2010\Projects\Electronics\ElectronicTool\ElectronicTool v4\ElectronicTool\bin\Debug\";
        //string root = Application.StartupPath;


What I have tried:

If I want to use
string root = Application.StartupPath;
, it is throwing me one or more errors in Form1 design window, see the picture here:
https://i.imgur.com/DRIZ5Qp.jpg[^]

To correct it, I write the DIRECT image ROOT, and everything goes back to normal. All the errors disappear and the designer is rendering the Form and its controls.
Can you help me understand and repair this issue?
Thank you very much !
Posted
Updated 18-Jul-21 10:02am
v2

You cannot use Application.Startup at design-time. It doesn't exist until run-time.

Though, you can move the image to Resources and load it from there at design-time.
 
Share this answer
 
Comments
_Q12_ 18-Jul-21 12:29pm    
Thank you very much!
Now I understand it.
The answer here will shed some light on this problem: vb.net - Defining path to executable for a custom control - Stack Overflow[^]
Although this is about VB.NET, it is the same for C#.
 
Share this answer
 
Hello,

Application.path is a ENV constant.

reWriting this constant in .Net is useless.

It's ENV about your application,
and except for reallocation ( when you use "string root =.. " ),
or renaming the same path;

Application.path is located in the folder the .exe exists.

( with the App not loaded , the Application.path is "NULL/UNDEFINED". )
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900