Author Topic: AU 2005 code - Part 2 "Adding buttons to the application and document panes"  (Read 3952 times)

0 Members and 2 Guests are viewing this topic.

Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
Code: [Select]
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.Windows;

namespace AU2005.AcadApi
{
//Pages 7 & 8
public class PaneButtonsExample
{
#region Application Pane

[CommandMethod("CreateAppPane")]
public static void AddApplicationPane()
{
Pane au2005AppPaneButton = new Pane();

//Set the buttons properties
au2005AppPaneButton.Enabled = true;
au2005AppPaneButton.Visible = true;
au2005AppPaneButton.Style = PaneStyles.Normal;
au2005AppPaneButton.Text = "AU2005 App. Pane";
au2005AppPaneButton.ToolTipText = "Welcome to Autodesk University 2005!";

//Hook into the MouseDown event to run code when the button is pressed.
au2005AppPaneButton.MouseDown += new StatusBarMouseDownEventHandler(OnAppMouseDown);

//Add the button to the applications status bar
//Items can also be added to the tray area
acadApp.StatusBar.Panes.Add(au2005AppPaneButton);
}


private static void OnAppMouseDown(object sender, StatusBarMouseDownEventArgs e)
{
Pane paneButton = (Pane) sender;
string alertMessage;

if (paneButton.Style == PaneStyles.PopOut)
{
paneButton.Style = PaneStyles.Normal;
alertMessage = "The application button is activated.";
}
else
{
paneButton.Style = PaneStyles.PopOut;
alertMessage = "The application button is de-activated.";
}

acadApp.StatusBar.Update();

acadApp.ShowAlertDialog(alertMessage);
}

#endregion


//Document pane code not shown in the handout
#region Document Pane

[CommandMethod("CreateDocPane")]
public static void AddDocumentPane()
{
Pane au2005DocPaneButton = new Pane();

//Set the buttons properties
au2005DocPaneButton.Enabled = true;
au2005DocPaneButton.Visible = true;
au2005DocPaneButton.Style = PaneStyles.Normal;
au2005DocPaneButton.Text = "AU2005 Doc. Pane";
au2005DocPaneButton.ToolTipText = "Welcome to Autodesk University 2005!";

//Hook into the MouseDown event to run code when the button is pressed.
au2005DocPaneButton.MouseDown += new StatusBarMouseDownEventHandler(OnDocMouseDown);

//Add the button to the documents status bar
acadApp.DocumentManager.MdiActiveDocument.StatusBar.Panes.Add(au2005DocPaneButton);
}


private static void OnDocMouseDown(object sender, StatusBarMouseDownEventArgs e)
{
Pane paneButton = (Pane) sender;
string alertMessage;

if (paneButton.Style == PaneStyles.PopOut)
{
paneButton.Style = PaneStyles.Normal;
alertMessage = "The document button is activated.";
}
else
{
paneButton.Style = PaneStyles.PopOut;
alertMessage = "The document button is de-activated.";
}

acadApp.DocumentManager.MdiActiveDocument.StatusBar.Update();

acadApp.ShowAlertDialog(alertMessage);
}

#endregion
}
}
« Last Edit: December 28, 2005, 02:32:03 PM by Bobby C. Jones »
Bobby C. Jones

itcad

  • Guest
Code: [Select]
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.Windows;

namespace AU2005.AcadApi
{
//Pages 7 & 8
public class PaneButtonsExample
{
#region Application Pane

[CommandMethod("CreateAppPane")]
public static void AddApplicationPane()
{
Pane au2005AppPaneButton = new Pane();

//Set the buttons properties
au2005AppPaneButton.Enabled = true;
au2005AppPaneButton.Visible = true;
au2005AppPaneButton.Style = PaneStyles.Normal;
au2005AppPaneButton.Text = "AU2005 App. Pane";
au2005AppPaneButton.ToolTipText = "Welcome to Autodesk University 2005!";

//Hook into the MouseDown event to run code when the button is pressed.
au2005AppPaneButton.MouseDown += new StatusBarMouseDownEventHandler(OnAppMouseDown);

//Add the button to the applications status bar
//Items can also be added to the tray area
acadApp.StatusBar.Panes.Add(au2005AppPaneButton);
}


private static void OnAppMouseDown(object sender, StatusBarMouseDownEventArgs e)
{
Pane paneButton = (Pane) sender;
string alertMessage;

if (paneButton.Style == PaneStyles.PopOut)
{
paneButton.Style = PaneStyles.Normal;
alertMessage = "The application button is activated.";
}
else
{
paneButton.Style = PaneStyles.PopOut;
alertMessage = "The application button is de-activated.";
}

acadApp.StatusBar.Update();

acadApp.ShowAlertDialog(alertMessage);
}

#endregion


//Document pane code not shown in the handout
#region Document Pane

[CommandMethod("CreateDocPane")]
public static void AddDocumentPane()
{
Pane au2005DocPaneButton = new Pane();

//Set the buttons properties
au2005DocPaneButton.Enabled = true;
au2005DocPaneButton.Visible = true;
au2005DocPaneButton.Style = PaneStyles.Normal;
au2005DocPaneButton.Text = "AU2005 Doc. Pane";
au2005DocPaneButton.ToolTipText = "Welcome to Autodesk University 2005!";

//Hook into the MouseDown event to run code when the button is pressed.
au2005DocPaneButton.MouseDown += new StatusBarMouseDownEventHandler(OnDocMouseDown);

//Add the button to the documents status bar
acadApp.DocumentManager.MdiActiveDocument.StatusBar.Panes.Add(au2005DocPaneButton);
}


private static void OnDocMouseDown(object sender, StatusBarMouseDownEventArgs e)
{
Pane paneButton = (Pane) sender;
string alertMessage;

if (paneButton.Style == PaneStyles.PopOut)
{
paneButton.Style = PaneStyles.Normal;
alertMessage = "The document button is activated.";
}
else
{
paneButton.Style = PaneStyles.PopOut;
alertMessage = "The document button is de-activated.";
}

acadApp.DocumentManager.MdiActiveDocument.StatusBar.Update();

acadApp.ShowAlertDialog(alertMessage);
}

#endregion
}
}

Why I could'nt see the au2005DocPaneButton in autocad2006 or autocad2007?
« Last Edit: May 22, 2008, 06:35:03 AM by itcad »