.NET

Reply
Valued Contributor
tanerpro
Posts: 83
Registered: ‎10-07-2005
Message 1 of 7 (568 Views)

Activating drawing screen after clicking button on a toolstrip on a toolpalette

568 Views, 6 Replies
10-28-2012 04:55 AM

Hello,

I  am developing a custom toolpalette, with a toolstrip and buttons on it. The botton asks user to select a point on the screen. But when the button is pressed it gets focus and tu user has to first click on the screen first to activate it and another click to select the point. This is annoying. I tried all of below but can not figure it out. How can i do it?

 

regards,

 

            BringWindowToTop(Acad.HWND32)
            BringWindowToTop(Doc.HWND32)
            BringWindowToTop(Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.Handle.ToInt32)
            AppActivate(Acad.HWND32)
            AppActivate(Doc.HWND32)
            AppActivate(Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.Handle.ToInt32)
           Setfocus.....

 

Windows 7 (x64)
AutoCAD 2012 (x64)
Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 2 of 7 (559 Views)

Re: Activating drawing screen after clicking button on a toolstrip on a toolpale

10-28-2012 07:15 AM in reply to: tanerpro

Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView()

Valued Contributor
tanerpro
Posts: 83
Registered: ‎10-07-2005
Message 3 of 7 (535 Views)

Re: Activating drawing screen after clicking button on a toolstrip on a toolpale

10-29-2012 03:49 AM in reply to: DiningPhilosopher

Thanks but didn't work, as seen in the attachments, the marked button always stays pressed, unless i click anywhere on autocad caption, menus, screen, the button remains focused, maybe we have to make it lost focus.

 

 

Windows 7 (x64)
AutoCAD 2012 (x64)
*Expert Elite*
Alfred.NESWADBA
Posts: 8,867
Registered: ‎06-29-2007
Message 4 of 7 (529 Views)

Re: Activating drawing screen after clicking button on a toolstrip on a toolpale

10-29-2012 03:58 AM in reply to: tanerpro

Hi,

 

does that help:

      <DllImport("user32.dll")> _
      Private Shared Function SetFocus(ByVal hwnd As System.IntPtr) As System.IntPtr
      End Function

And to call it:

      Call SetFocus(ApplicationServices.Application.DocumentManager.MdiActiveDocument.Window.Handle)

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 5 of 7 (505 Views)

Re: Activating drawing screen after clicking button on a toolstrip on a toolpale

10-29-2012 12:15 PM in reply to: tanerpro

That suggestion works with a regular Button, but I didn't notice that you were using a ToolStripButton, which requires special measures.

Here's a solution I've used for that. You can call the AsyncSetFocusToDwgView() just before you call GetPoint(), and see if that works.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Internal;

namespace AcApHelpers
{
   public static class AcApUtils
   {
      public static void AsyncSetFocusToDwgView()
      {
         AsyncHelper.BeginInvoke( () => 
            Utils.SetFocusToDwgView()
         );
      }
   }

   public static class AsyncHelper
   {
      public static void BeginInvoke( Action action )
      {
         if( action == null )
            throw new ArgumentNullException( "action" );
         new IdleInvoke( action );
      }

      class IdleInvoke 
      {
         Action action;
         public IdleInvoke( Action action )
         {
            this.action = action;
            Application.Idle += onIdle; 
         }

         void onIdle( object sender, EventArgs e )
         {
            Application.Idle -= onIdle;
            action();
         }
      }
   }

}

 

Valued Contributor
tanerpro
Posts: 83
Registered: ‎10-07-2005
Message 6 of 7 (450 Views)

Re: Activating drawing screen after clicking button on a toolstrip on a toolpale

11-04-2012 01:16 PM in reply to: Alfred.NESWADBA

Alfred, it didn't work. Whatever I do the toolstripbutton stays pressed, if i click anywhere else, even the palette itself or autocad menus, screen,... , it loses focus but i can't figure it out. I tried to set focus on another object on the palette after the button click event but didn't work. What am i doing wrong? Nobody using toolpalette or toolstripbuttons?

 

DiningPhilosopher sorry but I am using vb.net and at the very beginnig, I can't try it. But thanks.

 

Regards,

Windows 7 (x64)
AutoCAD 2012 (x64)
Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 7 of 7 (446 Views)

Re: Activating drawing screen after clicking button on a toolstrip on a toolpale

11-04-2012 05:46 PM in reply to: tanerpro

You can convert the code to VB.NET using an online converter or a Visual Studio Extension

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community