Why isn't my Custom Task Pane receiving focus?

  • Thread starter Edward Smit -Macaw-
  • Start date
E

Edward Smit -Macaw-

I have a form with a Custom Task Pane. When I start the form the CTP is shown
but it doesn't have the focus. I close the CTP. Now when I press F1 the Help
Task Pane is shown and it has the focus, however if I instead use CTRL-F1 to
get the task pane, my CTP comes up but without the focus! Can I do something
about this, and force the focus somehow?
 
S

Scott L. Heim [MSFT]

Hi Edward,

You will need to have code in your custom task pane to explicitly move the
focus to, say, a text box on your task pane.

Here is some sample jscript that you can use behind your task pane - this
could probably be slimmed down some but I needed for another issue and it
works as is! :)

**NOTE: This does assume there is a text box on the task pane with an ID
of: Text1.

<html>
<head>
<body>
<p><b>This demonstrates using a custom task pane to set focus to a field on
the Task Pane when the form opens.</b></p>

<Input id="Text1" type="text" name="Text1" />
</body>

<script language="jscript">

var gIntPollTimer = null;
var i_DELAY_TIME = 100; //Time in milliseconds.

function StartPolling()
{
gobjXDocument = window.external.Window.XDocument;
if( null != gobjXDocument )
{
gIntPollTimer = window.setInterval(fnPollingLoop, i_DELAY_TIME );
}
}

function StopPolling()
{
window.clearInterval(gIntPollTimer);
}

function fnPollingLoop()
{
MoveTheFocus();
StopPolling();
}

function MoveTheFocus()
{
Text1.focus();
}

function window::OnLoad()
{
StartPolling();
}
</script>
</head>
</html>

I hope this helps!

Best Regards,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
E

Edward Smit -Macaw-

Thanks Scott,
although I had tried Text1.focus() at several locations, your post triggered
my memory. I knew that there was a issue in the handling of the focus event
hence your setInterval. Your example didn't work as I wanted, but put me on
the right trail. In my final code I use window.setTimeout to delay-fire the
event.
So my TaskPane.html now contains:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<script language=javascript>
xDocument = window.external.XDocument;

function Init()
{
window.onfocus = SetFocus;
SetFocus();
}

function SetFocus()
{
setTimeout('FirstTextBox.focus()', 50);
}
</script>
</head>
<body onload="Init();">
<input type=text id="FirstTextBox">
</body>
</html>

Thanks again.
 
S

Scott L. Heim [MSFT]

Hi,

Thank you for the update - I am glad to hear you were able to get the
process working!

Best Regards,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top