MS Visual C# und auf kompilierte resource zugreifen
-
Hallo,
ich spiele gerade mit NotifyIcon rum .
Mir ist aufgefallen dass ich im MS Visual C# mehrere Icons einfügen kann.
Dire werden dann auch mit kompiliert.Meine eigentliche Frage ,wie bekomme ich zugriff auf die kompilierten Icons, ich habe es bis jetzt nicht rausgefunden (geht das überhaupt) ?
Also da erste Icon was ich ausgewählt habe wird angezeigt, ich wollte bisschen rumprobieren und das Icon in der Anwendung per Klick ändern.Das funktioniert ja auch aber nur wenn ich die Icons in einem externen Ordner habe, dann habe ich per Pfad zugriff drauf.Wie greife auf die einzelnen Icons zu wenn sie in der Anwendung kompiliert sind (Pfad..??) ?Gruss
-
Servus,
welches Framework benutzt du? .Net 1.x / .Net 2.0 ?
mfg
Hellsgore
-
Hallo,
Net 2.0
Gruss
-
http://msdn2.microsoft.com/de-de/library/7k989cfy(VS.80).aspx
http://support.microsoft.com/kb/319292/de
-
Hallo,
stehe jetzt an einem Punkt wo ich nicht weiterkomme.
Folgendes:wenn meine Anwendung einen Bestimmten "String" erreicht dann möchte ich ein bestimmtes Icon anzeigen.
Der String wechselt oft den Wert und das Icon sollte sich dann auch dann mitändern.Das wechseln funktioniert nur 2-3 mal nach starten der Anwendung, dann bekomme ich eine Fehlermeldung. (Hatte davor die Icons in einem externen Ordner (nicht in der Anwendung kompiliert, da klappte das hin und her wechseln ohne Probleme)
Wollte das ganze jetzt testen , wenn die Icons in der Anwendung kompiliert sind, aber irgendwo habe ich einen Wurm drin...Assembly _assembly; Stream _imageStream1; Stream _imageStream2; Stream _imageStream3; Stream _imageStream4;
String s3 = listView1.Items.Count.ToString();
Ich habe verschiedene Icons in der Anwendung kompiliert auf die ich dann so zugreife:
String s3 = listView1.Items.Count.ToString(); if (s3 == "1") notifyIcon1.Icon = new System.Drawing.Icon(_imageStream1); if (s3 == "2") notifyIcon1.Icon = new System.Drawing.Icon(_imageStream2); if (s3 == "3") notifyIcon1.Icon = new System.Drawing.Icon(_imageStream2); if (s3 == "4") notifyIcon1.Icon = new System.Drawing.Icon(_imageStream4);
_assembly = Assembly.GetExecutingAssembly(); _imageStream1 = _assembly.GetManifestResourceStream("MyNamespace.1.ico"); _imageStream2 = _assembly.GetManifestResourceStream("MyNamespace.2.ico"); _imageStream3 = _assembly.GetManifestResourceStream("MyNamespace.3.ico"); _imageStream4 = _assembly.GetManifestResourceStream("MyNamespace.4.ico");
Hier die Fehlermeldung:
Das Argument picture muss ein Bild sein, das als Icon verwendet werden kann.
Verwende nur Icons , deswegen ?????
System.Reflection.TargetInvocationException was unhandled Message="Ein Aufrufziel hat einen Ausnahmefehler verursacht." Source="mscorlib" StackTrace: bei System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) bei System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) bei System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) bei System.Delegate.DynamicInvokeImpl(Object[] args) bei System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme) bei System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj) bei System.Threading.ExecutionContext.runTryCode(Object userData) bei System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) bei System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme) bei System.Windows.Forms.Control.InvokeMarshaledCallbacks() bei System.Windows.Forms.Control.WndProc(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) bei System.Windows.Forms.Application.Run(Form mainForm) bei Test.Program.Main() in C:\Users\Eigene\Documents\Visual Studio 2005\Projects\WindowsApplication3_\WindowsApplication3\Program.cs:Zeile 22. bei System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() bei System.Threading.ThreadHelper.ThreadStart_Context(Object state) bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) bei System.Threading.ThreadHelper.ThreadStart()
Vielleicht kann mir jemand einen Tip geben ?
Mfg
-
Versuch's mal so:
protected Icon[] aIcon = new Icon[4]; ... // einlesen for (int i = 0; i < 4; i++) { aIcon[i] = new Icon(GetType(), "DerNameDeinerApplication." + i + ".ico"); } ... // ausgeben int n = 2; // eine Ziffer zwischen 0 und 3 System.Drawing.Icon(aIcon[n]);
Die Icon müssen deinem Projekt als Verweise 0.ico bis 3.ico hinzugefügt werden.