• 0

Visual Inheritance of a ToolStrip


Question

Hi,

This is a known and previously reported problem and promised to be fixed in the "NEXT" version of Visual Studio over and over again. What we need is all developers racking up to the issue I created at Microsoft Connect and start pushing the number of approvals high enough so the VS team can get off their ass and fix this things once and for all.

Come on guys, go to the issue and vote for it to be fixed and confirm that you can reproduce this bug.

Microsoft Connect : http://connect.microsoft.com/VisualStudio/feedback/details/552017/visual-inheritance-of-a-toolstrip

I am trying to create an infrastructure library to be used by all my projects where one of the project in that library contains the base forms for different things like ViewBase, EditBase, SearchBase & DialogBase. They all are inherited from a Base form which contains a toolstrip control with 3 common buttons for OK, Close & About.

Now depending on the type of base form I would like to add few more buttons and controls on the toolstrip during the design time. For example the SearchBase would have a Search, Clear buttons and so forth and so on.

It it worth noting that I change the modifier of the toolstrip to Protected. None of the inherited form allows me to add a new button or anything on the toolstrip. So I made the modifier public and the same behaviour. All the properties of the toolstrip control are disabled. Why is this? This is kind of a show stopper as I can't rely on the standard controls provided and have to look for third party controls.

Steps to reproduce this.

Create a new blank solution

Add a new project of type class library

Delete the default Class1 file

Add a Windows Form named "FormBase"

Add a ToolStrip control on the form and set the modifier to "Protected"

Add a button and a label (Don't have to but this is for visual testing)

Compile the solution

Now add an Inherited Windows Form named "FormSearchBase" and inherit it from the "FormBase"

I have posted this to Microsoft Connect as a bug but if it gets more support and approval then there is a higher chance of it being fixed.

Cheers :)

Link to comment
https://www.neowin.net/forum/topic/893544-visual-inheritance-of-a-toolstrip/
Share on other sites

3 answers to this question

Recommended Posts

  • 0

What I think you are missing is that the way the WinForms designer works; when it generates code, it's actually just generating code which isn't executed till runtime. The designer simply provides a visual representation of that resolved code. When you inherit a form, the InitialiseComponent() method (which is private, and not virtual) is executed through the constructor of the base class. You then open the form which inherits from your base form, but the controls placed on the base form can't be designed, because the designer is now working with a different designer file.

i.e.

Form1.cs <- constructor, any other code.

Form1.Designer.cs <- design time code.

Form2.cs <- constructor, any other code, inherits from Form1

Form2.Designer.cs <- design time code.

You can't make the designer generated method InitialiseComponent() protected and virtual because the designer invokes this method through Reflection, and is expecting a private method, so it won't be able to find it, not to mention the fact that it is regenerated when you make changes in the designer.

If you want to enable the scenario you are suggesting, the designer is probably not the way to do it. It's better do this through code, adding things manually, but controlled. You just lose design time support.

Edited by Antaris
WinForms, not WebForms!
  • 0

Wow a very decent response which is what I was hoping for.

It's not a webforms designer but it's a windows forms application. I know what you mean by the default constructor and all but the visual inheritance works for all the other controls except, ToolStrip, MenuStrip and few base controls that a developer can't live without in a large scale applications that needs a massive amount of visual inheritance. All third party components do support this and I would have expected this behaviour from Microsoft's flagship product and common controls that we all are so much used to. The main reason to raise this issue is, this was partially working in Vs2003, people complained so they promised to fix this in VS2005 as it was too late to fix in VS2003. Along came VS2005 it was not working at all and the same promise to fix this in VS2008. Now we are at VS2010 and same story!

  • 0

Microsoft have locked down Visual Inheritance for complex controls because they couldn't figure out how to manage the designer-serialization of child item controls over an inheritance tree in a simple way.

A simple workaround (which achieves the same effect) is to drop an invisible toolstrip on the sub-form and merge it with the base-forms toolstrip at load time.

I've developed MergableToolStrip controls you can use free of charge here - Visual Inheritance For MenuStrip, ToolStrip and StatusStrip Controls

  • Like 1
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Been happy with Windows 11 myself even since first release in 2021, sure it hasn't always been perfect, but nothing is per say.. Issues i did have was minor ones, which is normal with any OS really. I still use Windows 10 at times on my unsupported Gaming Laptop, and i find myself using the Windows 11 Desktop more. Eventually replacing Gaming Laptop with a Windows 11 Compatible one somehow, someway this year or possibly next year at the latest, but its gonna happen--(May save all my Bing reward points except the 1000 to have extended support for 10) then work on getting quality Replacement hard)
    • Geez, this is dumb. I use my laptop sometimes in the dark when doing astrophotography to control my astro-PC... this explains why I have to keep entering my PIN when logging back in. So stupid. I can't see the keyboard in the dark, and I can't have lights everywhere to light it up because everything is very light sensitive (including my eyes!).
    • Naturally. I don't care about brand loyalty at all as it's all about price/performance/reliability etc (even what RejZoR said below is a great point to). basically bang-for-the-buck. because at the end of the day... one wants the cheapest possible price to maintain a certain minimum level of performance (or thereabouts). because generally after a certain point with CPU and GPU's the price starts to sky rocket without that much difference in performance where it really matters. p.s. historically I have bought more Intel CPU's and NVIDIA GPU's but I have had some AMD CPU's and one AMD GPU.
    • Both of these companies as well as Qualcomm and Apple need competition. Otherwise, they just coast. I don't prefer macOS, though I like some of Apple's hardware, but if anyone needs competition, it is Apple. Their prices are already outrageous and they need to have a reason to produce good hardware and at least keep prices remotely reasonable. (It is criminal what they charge for RAM upgrades especially.) Qualcomm needs to push AMD and Intel not to be so sloppy with the performance/efficiency aspect. Granted, AMD has been doing quite well in this respect considering they are not an ARM architecture. I personally want to have more options that truly compete with Macbook Air and Macbook Pro's on the Windows side. It is difficult to achieve what Apple does since they control the entire stack and that is fundamentally different for Windows PCs other than maybe Microsoft Surface PCs.
  • Recent Achievements

    • Week One Done
      Hartej earned a badge
      Week One Done
    • One Year In
      TsunadeMama earned a badge
      One Year In
    • Week One Done
      shaheen earned a badge
      Week One Done
    • Dedicated
      Cole Multipass earned a badge
      Dedicated
    • Week One Done
      Alexander 001 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      570
    2. 2
      +FloatingFatMan
      182
    3. 3
      ATLien_0
      179
    4. 4
      Skyfrog
      111
    5. 5
      Som
      106
  • Tell a friend

    Love Neowin? Tell a friend!