.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

6 REPLIES 6
Reply
Message 1 of 7
tanerpro
1533 Views, 6 Replies

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

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.....

 

6 REPLIES 6
Message 2 of 7

Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView()

Message 3 of 7

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.

 

 

Message 4 of 7
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 5 of 7

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();
         }
      }
   }

}

 

Message 6 of 7
tanerpro
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,

Message 7 of 7

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost