ImageList for Console Application

J

jp2msft

I am experimenting with a concept the engineers want.

I want to create an app that runs in the console. When an event happens, I
want to display an image.

Can I do this without having a form?

Right now, my app compiles, but crashes with an unhandled exception at this
part:
//
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)
resources.GetObject("imageList1.ImageStream")));
//
It is erroring because I do not have anything called "imageList1.ImageStream".

How would I define something like this?

I included a Resources.resx file, and loaded several images into it. I just
don't know how to access them.

Can anyone help?
 
J

Jon Skeet [C# MVP]

jp2msft said:
I am experimenting with a concept the engineers want.

I want to create an app that runs in the console. When an event happens, I
want to display an image.

Where do you want to display the image?
Can I do this without having a form?

Not really.
Right now, my app compiles, but crashes with an unhandled exception at this
part:
//
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)
resources.GetObject("imageList1.ImageStream")));
//
It is erroring because I do not have anything called "imageList1.ImageStream".

How would I define something like this?

To be honest, the *easiest* way would be to create an image list in a
form, even if you then delete the form itself.

An alternative would be to build the images into the assembly as
individual resources, and call Assembly.GetManifestResourceAsStream. I
find that tends to make it easier to update than using a resx - just
drop a new image into the solution, set it to Embedded Resource and
rebuild.
 
M

Miro

You can create a form'd application and set the opacity to 100 % which makes
it invisible.
Set it so it does not appear in the taskbar either.

Miro
 
S

sloan

I guess one off the wall idea is to write out the the TEMP folder. And pop
the default application.

I don't know if this will work with a stream from the resource..but here is
my crappy string/file version.

It should convey the idea.

If you swap out to an image file extension
fileName = fileName.Replace(".tmp", ".jpg");
and work out the details of the stream writing..maybe its a poor man's fix
for showing images with a console application.



public void Test1()

string fileName = WriteToTempFile("Hi There");
System.Diagnostics.Process.Start(fileName);


}





public string WriteToTempFile(string toWrite)
{

System.IO.StreamWriter writer = null;
System.IO.FileStream fs = null;
string fileName = string.Empty;
try
{

// Writes text to a temporary file and returns path
fileName = System.IO.Path.GetTempFileName();
fileName = fileName.Replace(".tmp", ".txt");
fs = new System.IO.FileStream(fileName,
System.IO.FileMode.Append, System.IO.FileAccess.Write);
// Opens stream and begins writing
writer = new System.IO.StreamWriter(fs);
writer.BaseStream.Seek(0, System.IO.SeekOrigin.End);
writer.WriteLine(toWrite);
writer.Flush();



}
finally
{
if (null != writer)
{
writer.Close();
}
if (null != fs)
{
fs.Close();
}
}


return fileName;

}
 
J

jp2msft

They want me to build them a menu that floats at the top of Windows, like the
Start menu floats at the bottom of Windows.

I can create a form, assign it to the top of the screen, and remove the
Windows controls, but that's not what I'm after.

I want a console app that can I can create a panel in, assign that panel to
the Desktop window, then dock it to the top.

The panel will have my images in it, but I can't get past the step of
getting the ImageList to load from the resource file.
 
J

Jon Skeet [C# MVP]

jp2msft said:
They want me to build them a menu that floats at the top of Windows, like the
Start menu floats at the bottom of Windows.

I can create a form, assign it to the top of the screen, and remove the
Windows controls, but that's not what I'm after.

I want a console app that can I can create a panel in, assign that panel to
the Desktop window, then dock it to the top.

Why do you want the console in the first place? What do you mean by
"assign that panel to the Desktop window"?

I think you're trying to do the impossible. You can't just start
injecting your apps into other windows. (At least, there are ways of
doing it but they're distinctly tricky, and I wouldn't like to guess
where or not it would work for the desktop window itself.)
The panel will have my images in it, but I can't get past the step of
getting the ImageList to load from the resource file.

That sounds like the least of your worries. If you can get a panel with
a simple label in to behave as you want it to, the rest is simple - but
there's no point getting images right if the fundamental behaviour of
your app is impossible.
 
J

jp2msft

Ok. Let me rephrase: I need to design a toolbar that docs to the top of the
Desktop for our company's PCs.

Remember Microsoft Office 2000's ShortCut Bar? I want something like that,
only bigger so our half blind people can easily tell what the icons are.
 
J

Jon Skeet [C# MVP]

jp2msft said:
Ok. Let me rephrase: I need to design a toolbar that docs to the top of the
Desktop for our company's PCs.

Remember Microsoft Office 2000's ShortCut Bar? I want something like that,
only bigger so our half blind people can easily tell what the icons are.

What happens when you create a Windows Form which sets its location to
the top of the desktop?
 
J

jp2msft

I guess that's what I'm going to have to do.

I wanted to create a panel, assign its parent to be the the Windows Desktop,
then dock the panel to the top of the parent window (i.e. Desktop).

Oh well.

Happy Easter. Eat lots of Bunny Rabbits. (J/K)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top