Announcements

Announcement: We’re aware of an issue affecting starting a new topic from category pages and creating new blog posts. New topics can still be started directly from the relevant board. Learn more here.

TrayItem Icon disappears

TrayItem Icon disappears

Anonymous
Not applicable
1,559 Views
6 Replies
Message 1 of 7

TrayItem Icon disappears

Anonymous
Not applicable
Hi all

Can someone help me with custom trayitem/pane icon. I have the following code which is supposed to load a custom icon. The problem i am having is that the icon seems to disappear in Autocad.

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
Public Class Class1
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
Overridable Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize
AddTrayItems()
End Sub

Function GetEmbeddedIcon(ByVal strName As String) As Drawing.Icon
Return New Drawing.Icon(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(strName))
End Function

Sub AddTrayItems()
Try
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ti As New TrayItem()
ti.ToolTipText = "MyCadAddon Info"
ti.Icon = GetEmbeddedIcon("MyCadAddon.blue.ico")
Application.StatusBar.TrayItems.Add(ti)
Dim bw As New TrayItemBubbleWindow()
bw.Title = "MyCadAddon Application:"
'bw.HyperText = ""
' bw.HyperLink = ""
bw.Text = "This application has been loaded sucessfully"
bw.IconType = IconType.Information
ti.ShowBubbleWindow(bw)
Catch

End Try

End Sub


Overridable Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate

End Sub

End Class



see also attached icon
0 Likes
1,560 Views
6 Replies
Replies (6)
Message 2 of 7

Thosti
Explorer
Explorer

Hello,

 

i'm in the same situation. I tried to load a custom icon as TrayItem, however sometimes I can see it but mostly there is only the space without the icon. Icons grabbed from an existing acad trayitem were always shown.

 

Have you found any solution?

 

Thanks Thosti

0 Likes
Message 3 of 7

michael_vanhoose
Advocate
Advocate

Try reloading it on Document events.  It work most of the time for me.  Once and awhile I notice it gone.  But, not as much since I added on the Document Created event and Active Event.

0 Likes
Message 4 of 7

Balaji_Ram
Alumni
Alumni

I could recreate the same problem when an icon created using Visual studio is used.

Try creating an icon which similar to acad.ico (256 x 256, 32 bit).



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 7

Thosti
Explorer
Explorer

Thanks for reply,

 

I tried both suggestions (acad.ico with 256x256, which is included as embedded resource in the project and adding events to the doument) but with no success. So I simplyfied my code to generate this TrayItem by executing a command.

Here is the codesnipe

 

static Autodesk.AutoCAD.Windows.TrayItem oneNewTi = null;

//Funktion um befehle zu testen[CommandMethod("test")] public static void test() { try { if (oneNewTi == null) { System.Drawing.Icon ic; //Laden des Icons aus der Resourcendatei System.Reflection.Assembly thisExe = System.Reflection.Assembly.GetExecutingAssembly(); System.IO.Stream file = thisExe.GetManifestResourceStream("CAD.Bilder.acadmap.ico");
//ic = new System.Drawing.Icon(file, 256, 256); ic = new System.Drawing.Icon(file); oneNewTi = new Autodesk.AutoCAD.Windows.TrayItem(); oneNewTi.Visible = true; oneNewTi.Icon = ic; oneNewTi.ToolTipText = "Verbindung"; //Hinzufügen zur Statusbar und Anzeige aktualisieren Application.StatusBar.TrayItems.Add(oneNewTi); }

Application.StatusBar.Update(); } catch (System.Exception ex) { Application.ShowAlertDialog("Fehler in Funktion Test.\nMeldung: " + ex.Message); } finally { //MainApp.acadFunctions.UpdateApplication(); } //System.Diagnostics.Process.Start }

It ended with the same behaviour. Executing test-command adds the icon to the statusbar. The icon is visible. When moving mouse-cursor through acadmenu (we do not use multifunction-bar) for example, so that the statusbar is not visible for a short time - icon is gone when statusbar is visible again.

Executing test-command again doesn't make icon visible. There is only the empty space.

 

Could anybody reproduce this behaviour?

 

Regards, thosti

0 Likes
Message 6 of 7

Thosti
Explorer
Explorer

Hello,

 

here is the solution that worked for me.

When the icon is defined as static global variable then the icon does not disappear.

 

I will have a look at my "little icon" in further time.

 

Thanks for all replies

Thosti

0 Likes
Message 7 of 7

tiancao1001
Explorer
Explorer
The same code, why come out two icons?
0 Likes