DesignTime Help Needed - Tab Buttons Forget DesignMode

eyotasoft

Newcomer
Joined
Apr 5, 2010
Messages
7
Hi,

I've decided to explore providing design time support for custom component's and as my first effort I have opted to take on building a tab control. Working from some good examples I have just about managed this, but I am now stuck with the problem that once tab's have been added at design time they initially work perfectly and all code seems to be serialized ok, however after a build for example (or anything that causes the design view to refresh) the tab buttons for any 'existing' tab pages that have been serialized will loose their design time ability.

I've been scratching my head for a little while on this one now as I know that this wasn't always a problem and is likely a result of a change I've made ... but I can't however for the life of me figure it out.

A sample project is attached (vb). If anyone can point out where I'm going wrong it would be greatly appreciated.

Many thanks in advance,
Jamie.
 
I don't see a sample project, Jamie, but here's one idea: Are you building just the project that you are working on? You might want to check and make sure you are building the project that contains your custom control as well.

I'm more of a C# guy myself, and I've never figured out how to add another project to a solution using VB (looked into it once because someone here liked VB - I wound up giving up and saying, "That's why I use C#.")
 
Hi Joe,

thanks for the reply and yep I am building the control (in fact mainly only building the control as I was working in 'design time').

The differences between C# and VB aren't all that big in my opinion but I still write VB as it rolls of the tongue a lot quicker for me. If you know the fix in C# though I wont complain :p

I've actually attached the component this time ;-) Still not managed to work out why the second time round the tab buttons that get added for each tab page don't get added back as designable even though everything else does ... it has to be something to do with the way it's getting initialized and I can only assume the control designer isn't getting triggered in the same way once tab pages have been added to my tab control.

Thanks
Jamie.
 

Attachments

Ah I must of sent the wrong zip as that shouldn't of been in there. Nothing important just some custom controls I was working on.

New zip attached that should work straight off.
 

Attachments

I still don't see a reference for "esFramework.WinForms.UI" reference.

Well done code, for VB. :)

So, what exactly am I looking for? I can get the form to load up, even with the missing reference.

It comes up with a form and three (3) custom tabs in a custom tab control.

I can click on a tab to select it, and click on a tab's "custom close" button to remove it.

How do I duplicate the bug you are experiencing? What serialize routine is not working? (i.e. Form Name and Method Name ...maybe even line number of the creature that does not work)
 
I've removed the Winforms.UI reference as it didn't need be there.

The problem isn't during runtime, it behaves properly when you execute. The issue is if you open Form1 as it is then you will be presented with a form, my custom tab control and a few tab pages already added .... Because these pages are 'already added' then I am unable to select a tab page or click a close button .... however if I then select the tab control and click the smart tag and click 'Add View Page' then another tab will be added and this tab page and any further ones added will then work correctly (however the other 'already added' tabs still do not).

So essentially what is happening is you add a tab page to the tab control, that then gets serialized in the designer.vb file so next time you open the form or it rebuilds then everything will get constructed again on screen, but it seems that this causes it loose the ability to work in design time.

that make sense? I've tried so many different ways to resolve this with no effect, but it seems to me like it should work as it is :(

Jamie.
 
Still not completely following you. So, are you trying to close a tab in design view by clicking on the little close button? In design view?

One thing I noticed: I did a search on your project using the key phrase "Add View Page", since this is what you use to add a tab. In File esTabControl.vb there is a routine called "esTabControlDesigner" that looks like this:
Visual Basic:
    Public Overrides ReadOnly Property Verbs() As System.ComponentModel.Design.DesignerVerbCollection
        Get
            Dim v As New DesignerVerbCollection()

            'Verb to add buttons
            If Control.Dock = DockStyle.None Then
                v.Add(New DesignerVerb("&Dock in Parent", AddressOf OnDockToParent))
            Else
                v.Add(New DesignerVerb("&Undock from Parent", AddressOf OnDockToParent))
            End If
            v.Add(New DesignerVerb("&Add View Page", AddressOf OnAddTabPage))
            Return v
        End Get
    End Property
In the same file, I also found another routine called "" that looks like this:
Visual Basic:
    Private Sub OnAddTabPage(ByVal sender As Object, ByVal e As EventArgs)
        Dim TabPage As esTabPage
        Dim h As IDesignerHost = DirectCast(GetService(GetType(IDesignerHost)), IDesignerHost)
        Dim dt As DesignerTransaction
        Dim c As IComponentChangeService = DirectCast(GetService(GetType(IComponentChangeService)), IComponentChangeService)

        'Add a new button to the collection
        dt = h.CreateTransaction("Add View Page")
        TabPage = DirectCast(h.CreateComponent(GetType(esTabPage)), esTabPage)
        TabPage.Dock = DockStyle.Fill
        c.OnComponentChanging(MyControl, Nothing)
        Dim indx As Integer = MyControl.TabPages.Add(TabPage)
        'button.Index = indx
        'MyControl.AddTabButton(button)

        c.OnComponentChanged(MyControl, Nothing, Nothing, Nothing)
        dt.Commit()
    End Sub
First, you might want to make sure the text matches on both. One has the ampersand (&) and one does not.

Next, you should look into creating a "&Remove View Page" option, so you can remove items at design time as well. Is that what you are trying to accomplish?
 
You are more or less there. Yes I am trying to close (or select) a tab during design time. However the problem with this only occurs if you were to create a form and add a few tabs + controls .. then close the form and re-open it again, now try and access the tabs that you added before closing the form ... they no longer work how they did before you closed.

What you have highlighted from searching for 'Add View Page' and the ampersand isn't the problem as far as I'm aware .... the one missing the ampersand appears to me as some kind of transactional approach for adding components and 'add view page' is only a name, albeit a badly title one for what's actually happening.

Technically the code is all fine, there is in my mind something minor stopping the buttons being enabled for design time when they are not added during the current design session.
 
It comes up with a form and three (3) custom tabs in a custom tab control.

I can click on a tab to select it, and click on a tab's "custom close" button to remove it.

That to me sounds like it is actually working correctly for you ... maybe its just me :S Every time you open that form do the tab buttons / pages work as intended?
 
aha problem solved! amazing what a few beers and a different perspective can do for a problem :)

Essentially whilst I was trying to work out how to handle adding tab buttons I had managed to overcomplicate things and come to the rather stupid conclusion that the buttons should get added by the actual tab page collection class! I have now moved the add button invoke to a more sensible place and its works .. woo hoo!

anyway thanks again for your help, typically though it comes down to me being an idiot half way through :p
 
Back
Top