473,396 Members | 1,918 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,396 software developers and data experts.

How to use images in C# solutions

Hi,

Newbie here, please bear with me.

I have a C# project which implements a tree view control. I want to add
some images to this tree view control. The tree view control represents
the tree view found in Microsoft SQL Server Enterprise Manager. So we
have Server Groups and Servers, in the tree view.

I want to create my own similar tree view and have an image representing
a Server Group, and another image representing a Server. I have these
images as bitmaps in my file system. What is the best way of "managing"
these files? When I develop on my desktop, I reference them like this:

ImageList imgTreeNodes = new ImageList();
imgTreeNodes.TransparentColor = Color.White;
System.Drawing.Image imgServer = Image.FromFile(@"C:\Local Files\Visual
Studio Projects\SquealFind1.3\SquealFind\Icons\server.bmp ");
System.Drawing.Image imgServerGroup = Image.FromFile(@"C:\Local
Files\Visual Studio
Projects\SquealFind1.3\SquealFind\Icons\servergrou p.bmp");
imgTreeNodes.Images.Add(imgServerGroup);
imgTreeNodes.Images.Add(imgServer);
tvwServers.ImageList = imgTreeNodes;

However, when I copy my solution to the laptop, the directory structure
is different.

What's the best way of including the images in my solution, but
abstracting it from the file system?

--
Mark Allison, SQL Server MVP
http://www.markallison.co.uk

Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602m.html
Nov 16 '05 #1
4 12203
Two comments here. First of all, when you use the Visual Studio .NET visual
editor to assign images to an Image List, the images are serialized with
your project and compiled as embedded resources, so you don't need to reload
them as external icons.

Second, if you need the images to load from the hard disk, make the images
relative to the executable, then extend
System.Windows.Forms.Application.ExecutablePath with the relative path to
the images. For example, if the EXE is in c:\myApp\ and the images are
stored in c:\myApp\images\ then use:

string imageLocation = Application.ExecutablePath + \\images\\myimage.jpg;

HTH,
Jon
"Mark Allison" <ma***@no.tinned.meat.mvps.org> wrote in message
news:eD*************@TK2MSFTNGP10.phx.gbl...
Hi,

Newbie here, please bear with me.

I have a C# project which implements a tree view control. I want to add
some images to this tree view control. The tree view control represents
the tree view found in Microsoft SQL Server Enterprise Manager. So we
have Server Groups and Servers, in the tree view.

I want to create my own similar tree view and have an image representing
a Server Group, and another image representing a Server. I have these
images as bitmaps in my file system. What is the best way of "managing"
these files? When I develop on my desktop, I reference them like this:

ImageList imgTreeNodes = new ImageList();
imgTreeNodes.TransparentColor = Color.White;
System.Drawing.Image imgServer = Image.FromFile(@"C:\Local Files\Visual
Studio Projects\SquealFind1.3\SquealFind\Icons\server.bmp ");
System.Drawing.Image imgServerGroup = Image.FromFile(@"C:\Local
Files\Visual Studio
Projects\SquealFind1.3\SquealFind\Icons\servergrou p.bmp");
imgTreeNodes.Images.Add(imgServerGroup);
imgTreeNodes.Images.Add(imgServer);
tvwServers.ImageList = imgTreeNodes;

However, when I copy my solution to the laptop, the directory structure
is different.

What's the best way of including the images in my solution, but
abstracting it from the file system?

--
Mark Allison, SQL Server MVP
http://www.markallison.co.uk

Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602m.html

Nov 16 '05 #2
> string imageLocation = Application.ExecutablePath + \\images\\myimage.jpg;

FYI Outlook Express took out the "'s. One should prefix the first "\\" and
one should come after "jpg".

Jon

"Jon Davis" <jo*@REMOVE.ME.jondavis.net> wrote in message
news:Ot*************@TK2MSFTNGP11.phx.gbl...
Two comments here. First of all, when you use the Visual Studio .NET visual editor to assign images to an Image List, the images are serialized with
your project and compiled as embedded resources, so you don't need to reload them as external icons.

Second, if you need the images to load from the hard disk, make the images
relative to the executable, then extend
System.Windows.Forms.Application.ExecutablePath with the relative path to
the images. For example, if the EXE is in c:\myApp\ and the images are
stored in c:\myApp\images\ then use:

string imageLocation = Application.ExecutablePath + \\images\\myimage.jpg;

HTH,
Jon
"Mark Allison" <ma***@no.tinned.meat.mvps.org> wrote in message
news:eD*************@TK2MSFTNGP10.phx.gbl...
Hi,

Newbie here, please bear with me.

I have a C# project which implements a tree view control. I want to add
some images to this tree view control. The tree view control represents
the tree view found in Microsoft SQL Server Enterprise Manager. So we
have Server Groups and Servers, in the tree view.

I want to create my own similar tree view and have an image representing
a Server Group, and another image representing a Server. I have these
images as bitmaps in my file system. What is the best way of "managing"
these files? When I develop on my desktop, I reference them like this:

ImageList imgTreeNodes = new ImageList();
imgTreeNodes.TransparentColor = Color.White;
System.Drawing.Image imgServer = Image.FromFile(@"C:\Local Files\Visual
Studio Projects\SquealFind1.3\SquealFind\Icons\server.bmp ");
System.Drawing.Image imgServerGroup = Image.FromFile(@"C:\Local
Files\Visual Studio
Projects\SquealFind1.3\SquealFind\Icons\servergrou p.bmp");
imgTreeNodes.Images.Add(imgServerGroup);
imgTreeNodes.Images.Add(imgServer);
tvwServers.ImageList = imgTreeNodes;

However, when I copy my solution to the laptop, the directory structure
is different.

What's the best way of including the images in my solution, but
abstracting it from the file system?

--
Mark Allison, SQL Server MVP
http://www.markallison.co.uk

Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602m.html




Nov 16 '05 #3
Jon Davis wrote:
string imageLocation = Application.ExecutablePath + \\images\\myimage.jpg;

FYI Outlook Express took out the "'s. One should prefix the first "\\" and
one should come after "jpg".


Use Firefox instead! :) Doesn't take anything off :)

Jon

"Jon Davis" <jo*@REMOVE.ME.jondavis.net> wrote in message
news:Ot*************@TK2MSFTNGP11.phx.gbl...
Two comments here. First of all, when you use the Visual Studio .NET


visual
editor to assign images to an Image List, the images are serialized with
your project and compiled as embedded resources, so you don't need to


reload
them as external icons.

Second, if you need the images to load from the hard disk, make the images
relative to the executable, then extend
System.Windows.Forms.Application.ExecutablePat h with the relative path to
the images. For example, if the EXE is in c:\myApp\ and the images are
stored in c:\myApp\images\ then use:

string imageLocation = Application.ExecutablePath + \\images\\myimage.jpg;

HTH,
Jon
"Mark Allison" <ma***@no.tinned.meat.mvps.org> wrote in message
news:eD*************@TK2MSFTNGP10.phx.gbl...
Hi,

Newbie here, please bear with me.

I have a C# project which implements a tree view control. I want to add
some images to this tree view control. The tree view control represents
the tree view found in Microsoft SQL Server Enterprise Manager. So we
have Server Groups and Servers, in the tree view.

I want to create my own similar tree view and have an image representing
a Server Group, and another image representing a Server. I have these
images as bitmaps in my file system. What is the best way of "managing"
these files? When I develop on my desktop, I reference them like this:

ImageList imgTreeNodes = new ImageList();
imgTreeNodes.TransparentColor = Color.White;
System.Drawing.Image imgServer = Image.FromFile(@"C:\Local Files\Visual
Studio Projects\SquealFind1.3\SquealFind\Icons\server.bmp ");
System.Drawing.Image imgServerGroup = Image.FromFile(@"C:\Local
Files\Visual Studio
Projects\SquealFind1.3\SquealFind\Icons\serverg roup.bmp");
imgTreeNodes.Images.Add(imgServerGroup);
imgTreeNodes.Images.Add(imgServer);
tvwServers.ImageList = imgTreeNodes;

However, when I copy my solution to the laptop, the directory structure
is different.

What's the best way of including the images in my solution, but
abstracting it from the file system?

--
Mark Allison, SQL Server MVP
http://www.markallison.co.uk

Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602m.html



Nov 16 '05 #4
You mean Thunderbird? Firefox doesn't do NNTP posting.

Jon

"Andrey" <le*******@yahoo.com> wrote in message
news:dy46d.35927$He1.16271@attbi_s01...
Jon Davis wrote:
string imageLocation = Application.ExecutablePath + \\images\\myimage.jpg;


FYI Outlook Express took out the "'s. One should prefix the first "\\" and one should come after "jpg".


Use Firefox instead! :) Doesn't take anything off :)

Jon

"Jon Davis" <jo*@REMOVE.ME.jondavis.net> wrote in message
news:Ot*************@TK2MSFTNGP11.phx.gbl...
Two comments here. First of all, when you use the Visual Studio .NET


visual
editor to assign images to an Image List, the images are serialized with
your project and compiled as embedded resources, so you don't need to


reload
them as external icons.

Second, if you need the images to load from the hard disk, make the

imagesrelative to the executable, then extend
System.Windows.Forms.Application.ExecutablePat h with the relative path tothe images. For example, if the EXE is in c:\myApp\ and the images are
stored in c:\myApp\images\ then use:

string imageLocation = Application.ExecutablePath + \\images\\myimage.jpg;
HTH,
Jon
"Mark Allison" <ma***@no.tinned.meat.mvps.org> wrote in message
news:eD*************@TK2MSFTNGP10.phx.gbl...

Hi,

Newbie here, please bear with me.

I have a C# project which implements a tree view control. I want to add
some images to this tree view control. The tree view control represents
the tree view found in Microsoft SQL Server Enterprise Manager. So we
have Server Groups and Servers, in the tree view.

I want to create my own similar tree view and have an image representinga Server Group, and another image representing a Server. I have these
images as bitmaps in my file system. What is the best way of "managing"
these files? When I develop on my desktop, I reference them like this:

ImageList imgTreeNodes = new ImageList();
imgTreeNodes.TransparentColor = Color.White;
System.Drawing.Image imgServer = Image.FromFile(@"C:\Local Files\VisualStudio Projects\SquealFind1.3\SquealFind\Icons\server.bmp ");
System.Drawing.Image imgServerGroup = Image.FromFile(@"C:\Local
Files\Visual Studio
Projects\SquealFind1.3\SquealFind\Icons\serverg roup.bmp");
imgTreeNodes.Images.Add(imgServerGroup);
imgTreeNodes.Images.Add(imgServer);
tvwServers.ImageList = imgTreeNodes;

However, when I copy my solution to the laptop, the directory structure
is different.

What's the best way of including the images in my solution, but
abstracting it from the file system?

--
Mark Allison, SQL Server MVP
http://www.markallison.co.uk

Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602m.html


Nov 16 '05 #5

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

Similar topics

11
by: LarryM | last post by:
Hi, NB, not to stop capturing the single displayed Image, but to stop downloading the entire image directory. (In my Website you will do a search, and get some thumbnails, and these can be...
3
by: MediaDesign | last post by:
so there's the problem: my text links have background images and when I put links around images on my page, they too get the background image treatment which I do not...I have tried several...
4
by: Dom Hicklin | last post by:
I have created a form onto which images can be dropped and thus added to the OLE field of a Table (Access 2000 linked to SQL 2000 server). I use the Stephen Lebans ExportOLE function to do this...
3
by: marwa mohamed | last post by:
salamo alikom hi all when i run report that includes image control linked to a field in the table that contains the image path(on the server)and the record source of the report contains over 30...
16
by: Fred | last post by:
hi, is there some way to prevent(at least for not so advanced users) image saving on local disk; currently i use javascript which handles the right mouse button click, but all it takes is to...
61
by: phil-news-nospam | last post by:
Why does SVG need a different tag than other images? IMHO, SVG should be implemented as an image type just like any other image type, allowing it to work with <img> tags, and ... here is the...
2
by: OBAFGKM_RNS | last post by:
Let's say I have a Javascript function that loops over and over. In that function i have it alternating images on a button this way: if(var==0){ var myHTML = "<input type='button'...
1
by: Maxus | last post by:
Hi Everyone, Just wondering if anyone knew of a way to compare images and getting a nearest matching image out of a collection of images of diffrent sizes, colors, etc. Ideally want to compare...
17
by: liketofindoutwhy | last post by:
to simply add two quote images around some text. seems quite simple at first but turns out all the obvious solutions are not as desirable as a perfect solution: please see...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.