.NET

Reply
Active Contributor
tangferry
Posts: 43
Registered: ‎04-21-2005
Message 1 of 4 (270 Views)

What's wrong with the TrayItem's event?

270 Views, 3 Replies
07-06-2005 05:55 PM
There happens nothing when I click on the trayitem.
[CommandMethod("Test")]
static public void test()
{
TrayItem item=acadApp.StatusBar.TrayItems[0];
item.MouseDown+=new StatusBarMouseDownEventHandler(item_MouseDown);
}
private static void item_MouseDown(object sender, StatusBarMouseDownEventArgs e)
{
System.Windows.Forms.MessageBox.Show("Tray Item Clicked");
}
*Albert Szilvasy
Message 2 of 4 (270 Views)

Re: What's wrong with the TrayItem's event?

07-07-2005 10:16 AM in reply to: tangferry
You can only sink the events for the tray items that you created:

public class TestStatusBarPane
{
///
[CommandMethod("PANETEST")]
public void DoIt()
{

Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Application
Statusbar \n");
StatusBar sb = Application.StatusBar;

// add a new pane
Pane newPane = new Pane();
newPane.Text = "Hello";
newPane.ToolTipText = "Hello Tip";
newPane.Visible = true;
newPane.MinimumWidth = 40;
newPane.Style = PaneStyles.Normal;

newPane.MouseDown += new
StatusBarMouseDownEventHandler(paneMouseDown);

sb.Panes.Add(newPane);

PaneCollection panes = sb.Panes;
foreach (Pane p in panes)
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Pane
-- {0}\n", p.Text);
}

Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Document
Statusbar \n");
sb = Application.DocumentManager.MdiActiveDocument.StatusBar;
panes = sb.Panes;
foreach (Pane p in panes)
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Pane
-- {0}\n", p.Text);

}

}
static void paneMouseDown(Object o, StatusBarMouseDownEventArgs e)
{
Pane p = (Pane) o;
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Pane
on Click-- {0} {1}\n", p.Text, e.Button);
}

static void trayMouseDown(Object o, StatusBarMouseDownEventArgs e)
{
TrayItem ti = (TrayItem) o;
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Tray
on Click-- {0} {1}\n", ti.ToolTipText, e.Button);
ti.CloseBubbleWindows();
}

static void bubbleClosed(Object o,
TrayItemBubbleWindowClosedEventArgs e)
{
TrayItemBubbleWindow bubble = (TrayItemBubbleWindow) o;
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Bubble
'{0}' closed on Click -- {1}\n", bubble.Title, e.CloseReason);

}


public class TestStatusBarTray
{
static TrayItem oneNewTi = null;
///
[CommandMethod("TRAYTEST")]
public void DoIt()
{

Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Status
Bar Tray Item test \n");
StatusBar sb = Application.StatusBar;

TrayItemCollection tis = sb.TrayItems;
TrayItem oneTi = null;
foreach (TrayItem ti in tis)
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Tray
-- {0}\n", ti.ToolTipText);
oneTi = ti;
}

if (oneTi != null && oneNewTi == null)
{
oneNewTi = new TrayItem();
oneNewTi.Visible = true;
oneNewTi.Icon = oneTi.Icon;
oneNewTi.ToolTipText = "copy of " + oneTi.ToolTipText;
tis.Add(oneNewTi);

oneNewTi.MouseDown += new
StatusBarMouseDownEventHandler(trayMouseDown);
}

TrayItemBubbleWindow bubble = new TrayItemBubbleWindow();
bubble.Text = "Bubble Text";
bubble.Title = "Bubble Title";
bubble.HyperLink = "http://google.com";
bubble.HyperText = "Cool site";
oneNewTi.ShowBubbleWindow(bubble);
bubble.Closed += new
TrayItemBubbleWindowClosedEventHandler(bubbleClosed);

}
}
}

wrote in message news:4894583@discussion.autodesk.com...
There happens nothing when I click on the trayitem.
[CommandMethod("Test")]
static public void test()
{
TrayItem item=acadApp.StatusBar.TrayItems[0];
item.MouseDown+=new StatusBarMouseDownEventHandler(item_MouseDown);
}
private static void item_MouseDown(object sender,
StatusBarMouseDownEventArgs e)
{
System.Windows.Forms.MessageBox.Show("Tray Item Clicked");
}
*Danny P.
Message 3 of 4 (270 Views)

Re: What's wrong with the TrayItem's event?

07-07-2005 07:55 PM in reply to: tangferry
Albert,

Excellent example, thanks. Having played with this for a few minutes,
I'm really intrigued by the Popup pane style. It looks as though it's
meant to attach a menu item to. Any chance you could make a simple
example showing a menu popup and a click handler on a menu item? (or
would the menu events handle the click?)

Something like a menu with "Say Hello" and an event handler of MsgBox
("Hello world")? I can run with it from there.

Thanks in advance for your help, and thanks for everything you do here
for us,
-Danny Polkinhorn
WATG
Honolulu

PS: Here's the VB port (as well as I can do it, watch for wrapping)...


Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Windows

Public Class TestStatusBarPane

_
Public Sub DoIt()


Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Application
Statusbar " + ControlChars.Lf)
Dim sb As StatusBar =
Autodesk.AutoCAD.ApplicationServices.Application.StatusBar

' add a new pane
Dim newPane As New Pane
newPane.Text = "Scale: 1/8'' = 1'-0''"
newPane.ToolTipText = "Default Scale"
newPane.Visible = True
newPane.MinimumWidth = 40
newPane.Style = PaneStyles.PopUp

AddHandler newPane.MouseDown, AddressOf paneMouseDown

sb.Panes.Add(newPane)

Dim panes As PaneCollection = sb.Panes
Dim p As Pane
For Each p In panes

Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Pane
-- {0}" + ControlChars.Lf, p.Text)
Next p

Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Document
Statusbar " + ControlChars.Lf)
sb = Application.DocumentManager.MdiActiveDocument.StatusBar
panes = sb.Panes
For Each p In panes

Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Pane
-- {0}" + ControlChars.Lf, p.Text)
Next p
End Sub 'DoIt

Shared Sub paneMouseDown(ByVal o As Object, ByVal e As
StatusBarMouseDownEventArgs)
Dim p As Pane = CType(o, Pane)

Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Pane
-- {0} {1}, Style: " + ControlChars.Lf, p.Text, e.Button, p.Style.ToString)
End Sub 'paneMouseDown

Shared Sub trayMouseDown(ByVal o As Object, ByVal e As
StatusBarMouseDownEventArgs)
Dim ti As TrayItem = CType(o, TrayItem)

Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Tray
on Click {0} {1}" + ControlChars.Lf, ti.ToolTipText, e.Button)
ti.CloseBubbleWindows()
End Sub 'trayMouseDown


Shared Sub bubbleClosed(ByVal o As Object, ByVal e As
TrayItemBubbleWindowClosedEventArgs)
Dim bubble As TrayItemBubbleWindow = CType(o, TrayItemBubbleWindow)

Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Bubble
'{0}' closed on Click -- {1}" + ControlChars.Lf, bubble.Title,
e.CloseReason)
End Sub 'bubbleClosed

Public Class TestStatusBarTray

Private Shared oneNewTi As TrayItem = Nothing

_
Public Sub DoIt()


Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Status
Bar Tray Item test " + ControlChars.Lf)
Dim sb As StatusBar = Application.StatusBar

Dim tis As TrayItemCollection = sb.TrayItems
Dim oneTi As TrayItem = Nothing
Dim ti As TrayItem
For Each ti In tis

Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Tray
-- {0}" + ControlChars.Lf, ti.ToolTipText)
oneTi = ti
Next ti

If Not (oneTi Is Nothing) And oneNewTi Is Nothing Then
oneNewTi = New TrayItem
oneNewTi.Visible = True
oneNewTi.Icon = oneTi.Icon
oneNewTi.ToolTipText = "copy of " + oneTi.ToolTipText
tis.Add(oneNewTi)

AddHandler oneNewTi.MouseDown, AddressOf trayMouseDown
End If

Dim bubble As New TrayItemBubbleWindow
bubble.Text = "Bubble Text"
bubble.Title = "Bubble Title"
bubble.HyperLink = "http://google.com"
bubble.HyperText = "Cool site"
oneNewTi.ShowBubbleWindow(bubble)
AddHandler bubble.Closed, AddressOf bubbleClosed
End Sub 'DoIt
End Class 'TestStatusBarTray
End Class 'TestStatusBarPane
Valued Contributor
tim-bot
Posts: 84
Registered: ‎02-28-2005
Message 4 of 4 (270 Views)

Re: What's wrong with the TrayItem's event?

02-29-2008 09:53 AM in reply to: tangferry
hmm... i'm frustrated, i'm using this code and there's no bubble coming up... does anyone know why?
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.