|
Hi, I have subclassed the ToolStrip control and ToolStripProfessionalRenderer to create my custom control and I have some events/methods overriden so the ToolStrip works the way I want it.
My custom ToolStrip will have just ToolStripButtons and on the overriden OnItemClicked event, I control the checked button (only one can be checked at a time). So this works somewhat like a toolbar but where you can choose which page you want to see (this is for an options dialog).
Now, my real problem. What's the best way to accomplish the rest? I mean, I was going to add a bunch of panels and then, depending on the checked button, I would make the corresponding panel visible and all the others hidden. But there must be a better way than this... Doing it this way, makes things hard on editing the UI for every page and if I have lots of pages, it will be even harder to maintain all this.
So, how can I have my custom ToolStrip, behave like a TabControl when I click any of the buttons, both at design-time and run-time? Is this even possible?
|
| Nazgulled Thursday, July 12, 2007 11:45 PM |
By far the easiest way is to actually use a TabControl, easy in the designer. Check this thread for a tab control that doesn't show its tabs.
|
| nobugz Friday, July 13, 2007 4:50 PM |
By far the easiest way is to actually use a TabControl, easy in the designer. Check this thread for a tab control that doesn't show its tabs.
|
| nobugz Friday, July 13, 2007 4:50 PM |
I went into this link (http://www.dotnetrix.co.uk/tabcontrols.html) in the thread you gave me and opted for the "Add a HideTabs property to turn on/off the Tabs" solution. It seems better to do this way...
However, is there anyway to change the selectedIndex for the custom TabControl according to the button checked in the custom ToolStrip but coding all this in the sub-classes? So I can make a dll from this and don't need to code by hand the change of the SelectedIndex property for every program I want to use this type of interface.
If possible how can I accomplish that?
|
| Nazgulled Friday, July 13, 2007 5:41 PM |
Not really. You'd need a UserControl to combine the toolstrip and the tab control. But then you wouldn't be able to add buttons and tabs when you put the UC on a form. Unless you make your own designer...
|
| nobugz Friday, July 13, 2007 6:33 PM |
If it takes that much work, I think I'll pass it...
|
| Nazgulled Friday, July 13, 2007 6:42 PM |
if you're using the "Add a HideTabs property..." method, you could just extend it to associate a ToolStrips button index's with the tabpage index's.
[VB code given as no preference mentioned]
Code Snippet
Private WithEvents m_NavBuddy As ToolStrip
Public Property NavBuddy() As ToolStrip Get Return m_NavBuddy End Get Set(ByVal value As ToolStrip) m_NavBuddy = value End Set
End Property
Private Sub m_NavBuddy_ItemClicked(ByVal sender As Object, _ ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) _ Handles m_NavBuddy.ItemClicked
Dim id As Int32 = m_NavBuddy.Items.IndexOf(e.ClickedItem) If Me.TabCount > id Then Me.SelectedIndex = id End If
End Sub
You would still need to add the buttons and tabpages seperately, but there would be no coding necessary, just a simple property change.
This is a very basic example. Depending upon your specific needs, it may be possible to further enhance this solution. |
| Mick Doherty Saturday, July 14, 2007 9:38 AM |
Actually I'm doing this in C#, but that wasn't a problem...
Anyway, I tried something like that, but if the user changed tab (with shortcuts) the button wouldn't change and I wasn't able to keep both in synch without making a loop through functions that were already called...
I think I'm going to try and implement something like this: http://www.differentpla.net/content/2004/10/implementing-a-paged-options-dialog
|
| Nazgulled Saturday, July 14, 2007 1:04 PM |
Just so you know, I was able to create exactly the thing I want. A totally custom control using the that guide. I just made it work, all I need now is to make better and code it better.
Thanks for all your help thought!
|
| Nazgulled Saturday, July 14, 2007 5:34 PM |
If that doesn't work for you...
There's no need for a loop.
You could override the TabControls OnSelected() and OnDeselected() methods to synchronize the ToolStripButtons with the SelectedTab. |
| Mick Doherty Saturday, July 14, 2007 5:47 PM |
Thanks, but I won't bother, I prefer the custom control way. It's more neat!
|
| Nazgulled Saturday, July 14, 2007 9:40 PM |