|
-
Aug 6th, 2009, 09:35 AM
#1
[RESOLVED] Subclass BindingNavigator - Strange behavior
Hello all,
One of the VBF member was asking how to add a close button on the BindingNavigator control once and reuse it on all other forms, so I try to create a custom bindingnavigator class that inherits the BindingNavigator class.
Below is the inherited class:
vb.net Code:
Public Class BindingNavigatorEx
Inherits System.Windows.Forms.BindingNavigator
Public Sub New()
MyBase.New()
'Add the closeform button
Dim closeButton As New ToolStripButton("Close", Nothing, New EventHandler(AddressOf CloseForm_OnClick))
Me.Items.Add(closeButton)
'Add a separator
Dim separator As New ToolStripSeparator()
separator.Size = New System.Drawing.Size(6, 25)
Me.Items.Add(separator)
End Sub
Private Sub CloseForm_OnClick(ByVal sender As Object, ByVal e As System.EventArgs)
'Find the outer most parent container control and trycast it to a form
'and call the close method on that form
Dim parent As Form = Nothing
Dim child As Control = Me
Dim ctrl As Control = Me.Parent
Do Until ctrl Is Nothing
child = ctrl
ctrl = ctrl.Parent
Loop
parent = TryCast(child, Form)
If parent IsNot Nothing Then
parent.Close()
End If
End Sub
End Class
The thing that I can't figure out is that it looks OK in design mode, but at run time, the custom binding navigator shows 2 "Close" buttons. Only one of them will close the form when clicked, the other one doesn't function. See the attached image.
Any ideas?
Last edited by stanav; Sep 11th, 2009 at 08:19 AM.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|