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

Getting focus to switch to editor from palette

5 REPLIES 5
Reply
Message 1 of 6
Anonymous
951 Views, 5 Replies

Getting focus to switch to editor from palette

I have created a custom user control that i use in a palette. The control has a button on it that when clicked asks the user to select an insertion point for a new block. The code works and inserts the block. The problem is when i go to select the insertion point I have to click once on the drawing area so it gets focus, then i can click again to pick my insertion point. Is there anyway in code to set focus from the palette to the drawing editor?

Thanks in advance for your help
Mark
5 REPLIES 5
Message 2 of 6
chiefbraincloud
in reply to: Anonymous

Many people (including myself) have had similar problems with both palettes and modeless dialogs.

I think most who have solved their problem would indicate that your getpoint should not run inside the event handler of the palette, but rather be in a sub that is called from the event handler. My problem was a little different, and after attempting a lot of different approaches, a solution that ended up working was proposed to me by Kean Walmsley. That solution is to PInvoke a SetFocus method like this:
{code}
[System.Runtime.InteropServices.DllImport("user32.dll")] _
Public Function SetFocus(ByVal hwnd As IntPtr) As IntPtr
End Function
{code}
(NOTE: either with or without the [code] tags, this editor was removing the DllImport statement because of the 'greater than/less than' symbols. The top line should have the brackets [ ] replaced with 'less than, greater than')

Then call it right before the select point like this:
{code}
SetFocus(Document.UnmanagedObject)
{code}
where Document is obviously a reference to whatever document you are trying to activate.

This worked for my particular problem with a modeless dialog keeping the focus when it shouldn't have.
Dave O.                                                                  Sig-Logos32.png
Message 3 of 6
Anonymous
in reply to: Anonymous

If you're targeting AutoCAD 2009 at minimum, you can use
this, just before you call any GetXxxxx() method of the Editor:

Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();

On AutoCAD 2009 this requires a reference to AcMgdInternal.dll,
but not on 2010.

If you're using a ToolStrip on your palette, this may not work.

In that case, download this for some additional help:

http://www.caddzone.com/PaletteUtils.cs

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6266108@discussion.autodesk.com...
I have created a custom user control that i use in a palette. The control
has a button on it that when clicked asks the user to select an insertion
point for a new block. The code works and inserts the block. The problem is
when i go to select the insertion point I have to click once on the drawing
area so it gets focus, then i can click again to pick my insertion point.
Is there anyway in code to set focus from the palette to the drawing editor?

Thanks in advance for your help
Mark
Message 4 of 6
Anonymous
in reply to: Anonymous

Works Great! Thanks guys, you are the best
Message 5 of 6
PeterKompier
in reply to: Anonymous

2017.. 

 

Using the mouse enter and leave events works for me in 2017. MouseEnter to set the focus on the toolstrips of a palette (fixed two clicks on the first button click) and the MouseLeave to set focus the normal way, without the button pulling the focus back..

 

Snippet

   Private Sub ToolStrip1_MouseEnter(sender As Object, e As EventArgs) Handles ToolStrip1.MouseEnter         
ToolStrip1.Focus()     
End Sub

Private
 Clamps_Clicked As Boolean = False
   Private Sub Clamps_Click(sender As Object, e As EventArgs) Handles Clamps.Click        Clamps_Clicked = True    End Sub
   Private Sub Clamps_MouseEnter(sender As Object, e As EventArgs) Handles Clamps.MouseEnter        Clamps_Clicked = False    End Sub
   Private Sub Clamps_MouseLeave(sender As Object, e As EventArgs) Handles Clamps.MouseLeave        If Clamps_Clicked Then            'PaletteFocus.ActivateEditor() 'txt Tony            Active.Document.Window.Focus()            myApp.Commands.SelectStuff()        End If    End Sub

 

Message 6 of 6
PeterKompier
in reply to: PeterKompier

Use SendStringToExecute to start the command. Helps against the bounce of the toolstrip button and the user can repeat the command after enter of space..

Active.Document.Window.Focus()
Active.Document.SendStringToExecute("MyCommand ", True, False, False)

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