Visual Basic Development Bookmark and Share   
 Home > Visual Basic Interop and Upgrade > toolstripbutton in interop usercontrol not releasing focus when vb6 shows modal dialog in response to click
 

toolstripbutton in interop usercontrol not releasing focus when vb6 shows modal dialog in response to click

Hi, I have been able to create an interop UserControl in VS08 with the toolkit, and everything seems to work perfectly except this one minor issue:

my usercontrol has a ToolStripButton. on the click event of the ToolStripButton, i raise a custom event, ToolClicked. I handle this is VB6 code, and show a second form modally. When this second form appears, the first click anywhere on this form is ignored. I noticed that the ToolStripButton's border stays "hovered" or "focused" until after the first click on my modal form. One other thing that I noticed is that if I show a .Net form from VB6 code in response to the same ToolClicked event, it works fine.

repro steps:
1. in VS08, create new VB6 Interop UserControl project.
2. add a ToolStrip to the user control
3. add a ToolStripButton to the ToolStrip
4. in code for the UserControl, declare an event; Public Event ToolClick()
5. in the click event of the ToolStripButton, raiseevent the event; RaiseEvent ToolClicked()
6. build the project

7. in VB6, create a new Standand EXE project
8. in the Components dialog check the interop usercontrol
9. add a Form, Form1, and draw the control on the form
10. add another form, Form2, and add a button.
11. in the button's click event call Me.Hide
12. back on Form1, in code, select the ToolClicked event of the usercontrol
13. add the following code to show Form2 modally:
Dim frm As New Form2
frm.Show vbModal, Me
14. run the project, and click the button on the ToolBar.
15. notice that the first click on the button in Form2 is ignored, and after the first click the appearance of the ToolStripButton returns to "unfocused"


burton  Wednesday, January 21, 2009 11:05 PM
ok, this is a hack but it works: in my interopUserControl, i added a timer, set it's interval to 10, in my tool button click event recorded the data i needed to pass in my event, then in the timer tick, stopped the timer, and raised the ToolClicked event.

fortunately i only have to do this for one event, cuz it could get nasty if i had many.


Public Event ToolClicked(ByVal data As String)

Dim data As String = Nothing
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
data = "some button"
Timer1.Start()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Stop()
RaiseEvent ToolClicked(data)
data = Nothing
End Sub

  • Marked As Answer byburton Thursday, January 22, 2009 10:15 PM
  •  
burton  Thursday, January 22, 2009 10:13 PM
ok, this is a hack but it works: in my interopUserControl, i added a timer, set it's interval to 10, in my tool button click event recorded the data i needed to pass in my event, then in the timer tick, stopped the timer, and raised the ToolClicked event.

fortunately i only have to do this for one event, cuz it could get nasty if i had many.


Public Event ToolClicked(ByVal data As String)

Dim data As String = Nothing
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
data = "some button"
Timer1.Start()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Stop()
RaiseEvent ToolClicked(data)
data = Nothing
End Sub

  • Marked As Answer byburton Thursday, January 22, 2009 10:15 PM
  •  
burton  Thursday, January 22, 2009 10:13 PM
I have encounteredthe same problem, and i tried ThreadPool, it works for me, maybe it's useful to you,here is my code:

private void tsbFontColor_Click(object sender, EventArgs e)
{
System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(showColorPicker));
}
private void showColorPicker(Object o)
{
if (this.InvokeRequired)
{
this.Invoke(new SingleParameterDelegate<object>(this.showColorPicker), new object[] { o });
}
else
{
//show form etc.
}
}




//delegate
public delegate void SingleParameterDelegate<T>(T value);
zyccld-Lyndon  Monday, November 09, 2009 9:29 AM

You can use google to search for other answers

Custom Search

More Threads

• VB6 Interop and missing methods
• Repeat calling VB6 components from VB.NET with problems
• Office Interops
• Interop Usercontrol and VB6 Control Array
• Procedure name format when calling VBA macro from .NET code
• dll was loaded but dll register server entry point cannot be found. The file cannot be registered.
• Error: The program 'TEST.vshost.exe: Managed' has exited with code 0
• CCW Attributes Question
• Error On Vista
• Using typelib idl in .NET