|
If you mean embedded resources in a .NET assembly, then embed resources in the assembly from which images can be selected, then use the Bitmap(Type, String) constructor. The Type parameter should be a type that has the same namespace as the embedded resources (in a mannger of speak), and the String should be the name of the resource that begins with the same namespace. See that constructor documentation for more details.
You can also create an image from a stream, which means you can use Assembly.GetManifestResourceStream to get a Stream for the embedded resource, which you then create an image from, and assign that to PictureBox.Image .
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi Heath,
thanks for your input.
I did not get what you have suggested in 1st para.
What I did is I embedded the resources by changing their build property to embedded resource. And I tried to get the required resource from Assembly Manifest by using statements
System.Reflection.Assembly thisExe = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.Stream file = thisExe.GetManifestResourceStream ("ShapeLibrary.5side_Equipment.gif");
baseShape1.PropDisplayImage = Image.FromStream(file);
While I am trying to compile the project getting this exception message
" An exception occurred while trying to create an instance of ShapeLibrary.BaseShape. The exception was "'null' is not a valid value for 'stream'.".
Whereas "ShapeLibrary" is name of assembly containing Embedded resources. BaseShape is the user control in this Library in which I am putting image from this perticular code above.
For that I have written public property which sets image on the picture box.
Have I missed anything?
Regards
Shailaja
|
|
|
|
|
If you're getting that error while compiling, the code above has nothing to do with it. It's not JIT'ed and executed during compile-time, only at run-time. And the name of the assembly doesn't matter when resolving the embedded resource per se. If you're using VS.NET, the resource will contain the base namespace (configurable in the project properties, which is defaulted to the assembly name) plus dot-separated namespaces for each folder the resource is in (for source files, the namespace uses these as well for default namespaces), plus the resource name. If you're not sure about this, open your compiled assembly in ildasm.exe (the IL Disassembler, part of the .NET Framework SDK) and examine the MANIFEST file. Toward the bottom you'll see .mresource entries. Type the name into GetManifestResourceStream exactly as you see it there.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi
I noticed diffrence in the way these embedded resource files are described in assembly manifest.
Some are without '' and some within ''
Is it affecting the working of my code?
for Eg:
.mresource public ShapeLibrary.Sensor.gif
{
}
.mresource public 'ShapeLibrary.4side_Equipment.gif'
{
}
.mresource public 'ShapeLibrary.5side_Equipment.gif'
{
}
So should I use stringname = "'ShapeLibrary.4side_Equipment.gif'";
where as earlier I was not using ''?
I tried doing this but still the exception persists.
Regards
Shailaja
|
|
|
|
|
Again, are you getting this error when compiling your project, or when executing it?
And as far as the single quotes go, you should use them if they are specified there, but I'm curious how they got there in the first place. Check the resource name in the property grid when you select the file in your project that is the embedded resource and make sure there are no single quotes.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I am getting this error while compiling. I could not reach till execution stage.
Regards
Shailaja
|
|
|
|
|
Then you have a different problem than the name of the resource in your source code - that isn't checked by the compiler, except for syntax and type-safety. Having those single quotes in your resource names (for the project, not the code) could be causing problems for the assembler. Like I said in my previous post, try to figure out why the single quotes are there and get rid of them. You might have to manually edit your .csproj file, but it isn't difficult. Be sure to do a complete rebuild when you're finished to make sure the resources are properly embedded.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi Heath,
I checked csproject file also opening it in notepad.
The resource files having single cots in manifest are shown like pther files not having double cots.
if you don't mind can I zip the solution and send it to you?
Regards
Shailaja
|
|
|
|
|
Just send the csproj file. I shouldn't need the others.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hello,
is there a way to fill a String variable with the content of a stream ?
e.g.
XmlDocument.save() only allows writing to a stream. But I want the XML-Contents in a variable of type String
Thanx
|
|
|
|
|
Try and use:
- XmlDocument.OuterXml -> deliveres string directly
or
- XmlDocument.WriteTo
something like:
StringBuilder b = new StringBuilder();
XmlTextWriter writer = new XmlTextWriter(b);
xmlDoc.WriteTo(writer);
writer.Close();
return b.ToString();
|
|
|
|
|
StreamReader reader = new StreamReader(yourStream);
String s = reader.ReadToEnd();
|
|
|
|
|
Has anyone written code for bluetooth communication ?
I need to transfer data between a laptop and a Pocket PC via bluetooth.
Any help would be appreciated.
Johan Lombaard
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former - Albert Einstein
|
|
|
|
|
hi all,
i ve to create an application in which i can open graphical files(created in c#) into microsoft powerpoint. is there any way by which i can achieve this.
im very new to c#, so any help/ideas/suggestions in this regards will be highly appreciated.
thanks in advance
p123
|
|
|
|
|
If you're new to C#, then first learn that and don't start-off with such a hard problem. Providing an image format handler is an incredibly daunting task that requires many, many COM interfaces (and in .NET, these have to be redefined in managed code) and registry entries. If you merely need to insert a well-known image format (like GIF, JPEG, PNG, BMP, etc.), then add the Microsoft PowerPoint typelib to your project (right-click on your project, select Add Reference, then click the COM tab) which creates an interop assembly. Then you can use the PowerPoint object model to insert an image.
Besides, it might not even be possible since PowerPoint may be configured to only handle image formats that it was written and compiled to understand. In this case, you have to create an image viewer COM component and get into OLE (object-link and embedding) to display it in PowerPoint. Again, this is a very daunting task that is even difficult for those of us that have been using .NET for the last couple years.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I want to write a simple usb driver to read from a usb device, but I really have no idea how to do it. All I know is that it can be done through the Win32 API. Does anyone know how I can do this or knows of a sample I can view? Thanks in advance.
|
|
|
|
|
You won't want to try doing this from C#. Try the C++ forums.
|
|
|
|
|
currently, i would like to enhance the features of my system, which is
previously written system in c# by using several using several native
DLL.
however, the data structure in the DLL is rather complicated. they
have several array of struct re-inside struct, struct re-inside array
of struct, array of struct re-inside array of struct......
i know it is possible to write the wrapper class over struct. but, is
it possible to write wrapper class over the complex structure i
mention above? can anyone point me out more resource where i can get
related information?
someone suggested me to write an unmanaged C++ proxy/facade to interface between C# and the DLL. is it a good solution? can anyone point me out more resource where i can get related information on this?
thank you.
|
|
|
|
|
It is possible, though not always neat and clean. See the System.Runtime.InteropServices for lots of attributes, enumerations, and other classes to help create the structures with the right byte alignment and field marshaling, and to marshal the parameters for function calls. There is a lot of documentation the .NET Framework SDK that deals with these namespace elements.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I have created a Panel onto which I am adding several UserControls. Each UserControl has a button which should delete the UserControl from the Panel. To each UserControl I'm passing a ref to the Panel so when the button receives a click event it can call this.panel.Controls.Remove(this). This however seems to work but when I quit the program it just hangs and I have located the problem to the Remove call. Is it illegal for UserControls to remove themselves from a ControlCollection? If so, how should I structure my code to avoid this situation?
As a related question, when Remove is called the UserControl is not visually removed from the Panel (unless I call Dispose on the UserControl), so what is the proper way of updating the Panel?
|
|
|
|
|
Controls can only be added and removed in the main UI thread. Make sure you're not removing a control in a different thread. It's also possible that something else has a reference to the UserControl (such as event handler). After removing the control have you tried disposing it and see if the problem happens?
To update the Panel , just call Panel.Refresh (inheritted from Control ).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi,
I've running a project with dynamic generation of some kind of source code.
Therefore I'm looking for a .Net Template Engine which can combine Templates and some kind of objects to produce the code. The template engine velocity (which is for Java) would be the rights solution but I want to develop in C#.
I'm thankful for all ideas
Thanks
bernhard
|
|
|
|
|
There is a research version avaliable for the shared source implementation of .NET, I think over at http://research.microsft.com[^]
If you can wait, Generics (not quite templates) will be in the next version of .NET due first half of next year I think.
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
Anyone had a go at this in C#. I've seen some articles where they bind to the external calls, but I was looking more for how to do it with the features of the .NET runtime.
System.Threading.IOCompletionCallback seems to suggest its supported by the documentation is a bit lame.
As well as that the ThreadPool class does not seem to be up to scratch. 25 threads by default per processor seems a bit much.
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
I am working with Tabbed Control, How can i assign a hot Key to Each Tab page. Itried normail way of putting & in heading but this does not work. Is there any way of doing so?
|
|
|
|