Author Topic: Getting focus back from status bar button  (Read 3240 times)

0 Members and 1 Guest are viewing this topic.

Peter Laker

  • Guest
Getting focus back from status bar button
« on: August 27, 2008, 06:09:12 AM »
I have been playing around with some status bar buttons & have found that when you print a message to the text screen from a button press you loose focus on the command line. See Pic

Does anyone know how you can get the focus back on the command line.

A sample of the code is below.




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


namespace buttons
{
    public class PaneButtons
    {
        //test to see if button is loaded
        static bool buttonLoaded = false;

        [CommandMethod("BTEST")]
        public static void PaneButton()
        {
            Pane appPaneButton = new Pane();
            //Set the buttons properties
            appPaneButton.Enabled = true;
            appPaneButton.Visible = true;
            appPaneButton.Style = PaneStyles.Normal;
            appPaneButton.Text = "B-Test";
            appPaneButton.ToolTipText = "This is a command prompt test.";

            if(buttonLoaded == false)
            {
                //Hook into the MouseDown event to run code when the button is pressed.
                appPaneButton.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(appPaneButton);
                buttonLoaded = true;
            }
        }


        private static void OnAppMouseDown(object sender, StatusBarMouseDownEventArgs e)
        {
            //open editor
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            Pane paneButton = (Pane)sender;

            if(paneButton.Style == PaneStyles.PopOut)
            {
                paneButton.Style = PaneStyles.Normal;
                ed.WriteMessage("\n<activated>\n");
            }
            else
            {
                paneButton.Style = PaneStyles.PopOut;
                ed.WriteMessage("\n<de-activated>\n");
            }
            acadApp.StatusBar.Update();
           
        }
    }
}

Glenn R

  • Guest
Re: Getting focus back from status bar button
« Reply #1 on: August 27, 2008, 06:12:21 AM »
AutoCAD version?
.Net Framework version?
Visual Studio version (if used)?

Glenn R

  • Guest
Re: Getting focus back from status bar button
« Reply #2 on: August 27, 2008, 07:11:53 AM »
used autoCAD 2006 and Visual Studio Express 2008 C#:

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


namespace buttons
{
public class PaneButtons
{
//test to see if button is loaded
static bool buttonLoaded = false;

[CommandMethod("BTEST")]
public static void PaneButton()
{
Pane appPaneButton = new Pane();
//Set the buttons properties
appPaneButton.Enabled = true;
appPaneButton.Visible = true;
appPaneButton.Style = PaneStyles.Normal;
appPaneButton.Text = "B-Test";
appPaneButton.ToolTipText = "This is a command prompt test.";

if (buttonLoaded == false)
{
//Hook into the MouseDown event to run code when the button is pressed.
appPaneButton.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(appPaneButton);
acadApp.StatusBar.Update();
buttonLoaded = true;
}
}


private static void OnAppMouseDown(object sender, StatusBarMouseDownEventArgs e)
{
//open editor
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

Pane paneButton = (Pane)sender;

if (paneButton.Style == PaneStyles.PopOut)
{
paneButton.Style = PaneStyles.Normal;
ed.WriteMessage("{0}<activated>", Environment.NewLine);
Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt();
}
else
{
paneButton.Style = PaneStyles.PopOut;
ed.WriteMessage("{0}<de-activated>", Environment.NewLine);
Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt();
}
acadApp.StatusBar.Update();
}
}
}

Updated your code and added a reference to 'acmgdinternal.dll'

Cheers,
Glenn.

Peter Laker

  • Guest
Re: Getting focus back from status bar button
« Reply #3 on: August 27, 2008, 07:20:21 AM »
Thanks Glenn much appreciated.

Been using this with Autocad 2008 & VS 2008 pro.