Hi
I have an application that uses .NET, but allows it to pass in a window handle, a window title, else it uses the active window as the parent window. The code works, apart from the fact that using the TAB key tabs through the controls in reverse, and, if I then use Shift+TAB, they go in the opposite order (so they're swapped!
I have the tab order set correctly, and swapping the tab order around makes no difference it seems
I'd like the dialog window to act as any other window, and be able to react to TAB. Also, the Default button does not work at all. Pressing ENTER does nothing although the accept button for the dialog form is set
Any ideas would be highly appreciated, and code to go with it would be appreciated even more
Here is the code to show the window
public void DoModalWindow(IntPtr hParent, Form formToShow
IntPtr hWnd = formToShow.Handle
bool isClosing = false
IntPtr parenthandle = IntPtr.Zero
formToShow.Show()
// Set parent of window..
if (hParent != IntPtr.Zero
parenthandle = SetWindowLong(hWnd, GWW_HWNDPARENT, hParent)
EnableWindow(hParent, false)
MSG msg = new MSG(IntPtr.Zero, 0, 0, 0, 0, new POINT(0,0))
// These are more in the way of a test, I thought maybe adding accelerator keys might make
// SHIFT, TAB, ENTER work, but it didn't seem to help. Having said that, I might be calling i
// all incorrectly
ACCEL[] accel = new ACCEL[2]
accel[0] = new ACCEL(0,(char)0,(char)0)
accel[1] = new ACCEL(VF_SHIFT, (char)16, (char)0)
while (formToShow != null
if (PeekMessage(ref msg,IntPtr.Zero,0,0,PM_REMOVE)
if (TranslateAccelerator(formToShow.Handle, ref accel, ref msg) != 0
continue
else if (IsDialogMessage(formToShow.Handle, ref msg)
continue
els
TranslateMessage(ref msg)
DispatchMessage(ref msg)
if ((formToShow != null) && (formToShow.DialogResult != DialogResult.None) && (!isClosing)
{
// Get whether we authenticated of not, then kill off the window..
this.authenticated = (formToShow.DialogResult == DialogResult.OK);
formToShow.Close()
formToShow = null
GC.Collect()
isClosing = true
if (hParent != IntPtr.Zero
EnableWindow(hParent, true)
// Set parent of window back to original value..
SetWindowLong(parenthandle, GWW_HWNDPARENT, hParent)
ShowWindow(hParent, SW_SHOW)
Thanks for your help in advance
Martin Platt
DotNetJunkies User - 20 Sep 2004 18:02 GMT
Hello Martin,
we have a similar problem. Did you find a solution for the problem?
Thanks in advance
Thomas
---
DotNetJunkies User - 20 Sep 2004 18:04 GMT
Hello Martin,
we have a similar problem. Did you find a solution for the problem?
Thanks in advance
Thomas
---
DotNetJunkies User - 20 Sep 2004 18:07 GMT
Hello Martin,
we have a similar problem. Did you find a solution for the problem?
Thanks in advance
Thomas
---
pjhauser - 22 Aug 2008 16:15 GMT
I did not see a resolution to this thread, so I thought I would add some
things that I've found. I've got an application that is VB.Net 2005 and it
is ultimately called from an Activex component, which gives symptoms similar
to what you've described. (see also KB article 233263 & 187988). At first I
was not getting the tab key to work at all until I found a workaround that
involves adding a keyboard hook and calling the IsDialogMessage API from VB.
This fixed the problem but the tab order did not match what was specified on
the form.
It appears that because this is a .Net form, the IsDialogMessage doesn't use
the TabIndex that has been set, but instead uses the z order for the control.
The workaround was to rearrange the z order to match what I wanted for the
tab order. I'm in VB.Net so I started with the first control and did a "Send
to Back" and then repeated that through all the controls in the tab order I
wanted. You could also start with the last control and do a "Bring to Front"
and work backwards.
After doing this, that tab key worked correctly and so did the delete and
accelerator keys. The only thing still not working was the Enter key. It
appears that the IsDialogMessage API does not properly handle a .Net form
that has an "AcceptButton" set to something. I suspect it is still trying to
find the button that has the "Default" property set to True as it was done in
VB6. To work around this, I added some more code to the my keyboard hook
handler routine to intercept the Enter key and do my own processing instead
of calling IsDialogMessage.
I know this is an old thread but it is still popping up in Google so I
thought I'd add my two cents worth in case it is of any use to anyone.
>Hello Martin,
>
[quoted text clipped - 5 lines]
>
>---