I have a windows form with a UltraToolbarsManager containing a ribbon with groups, tools and a textboxtool. I want the textboxtool to get the focus when F12 is pressed but i am getting the exception "Can't activate a tool that is not visible."
I searched the forum and found some old entry but i could not get a solution out of it.
The Code i am running is:
Private Sub frmMain_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
If e.KeyCode = Keys.F12 Then
zeigeofrmBueroKunden()
oUltraToolbarsManagerMain.Ribbon.SelectedTab = oUltraToolbarsManagerMain.Ribbon.Tabs("buero")
Dim oTextBoxTool As TextBoxTool = CType(oUltraToolbarsManagerMain.Ribbon.Tabs("buero").Groups("BueroKunden").Tools("BueroKundenSuchenTextBoxTool"), TextBoxTool) oTextBoxTool.IsActiveTool = True
e.Handled = False End If End Sub
Hi Dawit,
The reason that this doesn't work is because setting a tool that isn't visible to be the active tool is not allowed. In this case, the tool you're setting will be active next time the page draws. The simplest way to address this, then, is to call Me.Update() to force the screen to draw.
An alternate solution is to use Invoke to defer setting the active tool until the next time messages are processed.
Please try this out and let me know which solution works for you.
Hi Mike,
thank you for your hint. The following code ist working now.
Private Sub frmMain_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp If e.KeyCode = Keys.F12 Then zeigeofrmBueroKunden()
Me.Update()
Dim oTextBoxToolBueroKundenSuchen As Infragistics.Win.UltraWinToolbars.TextBoxTool = CType(oUltraToolbarsManagerMain.Ribbon.Tabs("buero").Groups("BueroKunden").Tools("BueroKundenSuchenTextBoxTool"), Infragistics.Win.UltraWinToolbars.TextBoxTool)
oTextBoxToolBueroKundenSuchen.IsInEditMode = True
e.Handled = True End If End Sub
Me.Update() makes the exception disappear. and IsInEditMode sets the focus to TextBoxTool as intended.
Best regards,
Dawit