Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Tab key not working


Recommended Posts

I've created a window with a nethook by using the Form1.show method and everything is working the way I want it except for the tab key isn't tabbing through the controls the way I would normally expect. Anyone seen this before or know why? I tried using the keydown event to catch the Tab key and change the focus to the next control and that works but it makes a warning sound on text boxes which I haven't figured out yet. Buttons don't make the sound.

 

It seems wierd that Tab doesn't work in this case. headscratch.gif

Link to comment
Share on other sites

You should not need to anything "special" for Tabbing between controls on a .NET WinForm

 

I would suggest checking the Properties of the controls on your Form.

Is the TabStop property set to True ?

Other than that setting, all you need to do is check the TabIndex values for each control to make sure that a "proper" order is being specified.

Link to comment
Share on other sites

Tabstop is true and TabIndex values are all correct. 0 for the first 1 for the second and so on. If I run the form as a stand alone application it works fine. It's just when it running inside a nethook with mastercam that the tab key won't work. All it does when I press the tab key is make a warning noise and focus stays on the same control.

Link to comment
Share on other sites

With this code my Tab key works "as expected" ->

 

code:

    //----------------------------------

#region NETHOOK class

//---------------------------------

 

public class NETHOOK : Mastercam.App.NetHook2App

{

// Entry Point

public override Mastercam.App.Types.MCamReturn Run(int param)

{

if (!FindRequiredInteropSupportFiles(false))

{

return Mastercam.App.Types.MCamReturn.ErrorOccurred;

}

 

try

{

frmPolarPointData2Geometry form = new frmPolarPointData2Geometry();

form.ShowDialog(); // * Show the Form *

}

catch (Exception ex)

{

MessageBox.Show(ex.Message, "UnHandled Exception: " + ex.Source,

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

return Mastercam.App.Types.MCamReturn.ErrorOccurred;

}

return Mastercam.App.Types.MCamReturn.NoErrors;

}

 

} // class NETHOOK

 

#endregion class NETHOOK

Link to comment
Share on other sites

In the past I've used Form1.ShowDialog() as well and had very good results. The problem I believe is that with ShowDialog() Form1 holds focus and the user can't manipulate the Mastercam graphics window.

 

Do you know if it's possible to use Form1.Show() as oposed to ShowDialog() but somehow stay within the NetHook Run() method? I'm hoping this would give me the desired results. Currently I think the problem is that Form1 opens as an instance but then the NetHook actually continues through the rest of the code and ends up running the Close() method. This leaves Form1 still open and operating but also allows the user to set focus back to Mastercam which is my tentative goal. smile.gif

Link to comment
Share on other sites

Matt,

 

I investigated "Modeless Dialog with a NETHook".

And the answer was I got was ->

quote:

You could display a modeless dialog, but there’s no get_event()-type support in the NetHook API. It just wasn’t designed for that.

There is some event-driven abilities, but it’s not that extensive and ff you’re doing serious event tracking for mouse movements and the like, odds are good that your app is extensive enough that you should probably be looking at a CHook anyway.

I've done a couple CHooks that use modeless dialogs,

but never needed to with a NETHook.

 

On the subject of Tab Stops...

 

Of course this is all moot in regard to the primary subject at hand...

Some Googling turned up this ->

 

Microsoft Support: Modeless Dialog Box in a DLL Does Not Process TAB Key

*This behavior is by design.*

 

Windows Hooks in the .NET Framework

and

How to set a Windows hook in Visual C# .NET

and

SEE Ying-Shen Yu's answer to Ken Beccard's question

 

Implementing a Hook, I was able to "capture" the messages coming to my DLL.

 

The TAB Key did move the cursor between the controls, but not by the defined Tab Order!?!

It wasn't random, it was almost in reverse, but it was certainly not in the order defined by the TabIndex property set on each control.

With the Hook in place and the form now "seeing" the Tab Key I'm fairly sure that the tab order issue could be worked out, even if you had to "manually" move the focus from control->control.

 

Note: Using the code from the MSDN Magazine Cutting Edge article, the hook is "set" using this code ->

code:

public void Install()

{

m_hhook = SetWindowsHookEx(

m_hookType, m_filterFunc,

IntPtr.Zero,

(int)AppDomain.GetCurrentThreadId());

}

But...

AppDomain.GetCurrentThreadId() is a depreciated item.

When you build the Project you get this Warning->

-----------------------------------------

System.AppDomain.GetCurrentThreadId()' is obsolete: 'AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread.

-----------------------------------------

 

I did not find a around this (and didn't try too hard!) as the resulting DLL will run, but you always have to be very leery of using "depreciated" items!!!

Link to comment
Share on other sites

Wow, thanks a lot Roger. That's all great info. I think the first part pretty much sums it up. "It just wasn't designed for that." I'm going to try a few things with what I've learned here and see how I make out. If I can't get anywhere with it fairly easily I have found a reasonable work around that I will use instead. I'll simply set up a button that takes the focus back to the Mastercam window like the "Hide Dialog" button in the FBM window. That should be easy enough to figure out.

 

Looks like it might be time to take the plunge into Chooks.

 

Thanks for all the help Roger.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...