• 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

    • Still won't get me in one, I prefer a human driver.
    • Sony's region restrictions on PC begin lifting, bringing back PlayStation ports for everyone by Pulasthi Ariyasinghe 2023 was when Sony began its region-locking initiative on the PC platform. The move affected over 100 countries, restricting the purchase of popular PlayStation ports and live service experiences for anyone in the regions outside of Sony's choosing. However, it seems the company is finally opening up access to these countries, starting today. While Sony has made no official announcements, which was also how the original restrictions came to be, users in these regions have begun seeing most of the publisher's catalog reappearing on their Steam store platforms. The change can be seen on affected games' SteamDB histories as well. For example, on Helldivers 2, a popular but blocked multiplayer game from before, it can be seen that the 'PurchaseRestrictedCountries' flag has been removed from a large number of countries just a few hours ago, on June 13. The controversy began in 2023 when Sony began requiring PlayStation Network accounts for their PC ports, even for games that did not have any online elements. Following an uproar, especially regarding Helldivers 2, the company reversed course and made it an optional account on PC. Unfortunately, Sony did not lift the regional restrictions it placed on the countries that do not officially support PlayStation Network accounts, which amounts to well over 100 regions. As for what may have changed the company's mind about this, Stellar Blade may have played a big role. The Sony-published action game by Shift Up just released on PC to an absolutely massive audience, with it already touting almost 200,000 concurrent players on the Steam platform. While its demo was originally region restricted, the developer had worked with Sony to remove these locks and launch the game globally. Just a few days later, almost the entire PlayStation catalog has gone through the same process. Interestingly, while massive PlayStation titles like Helldivers 2, God of War Ragnarok, Spider-Man 2, and The Last of Us Part II Remastered are back to being available across most regions, it seems Ghost of Tsushima is still under the original restrictions. It's unclear why the title has not joined the rest in shedding its locks.
    • Easy to switch off Ai on macOS, just a couple of clicks, something that is not possible on Windows, it is just hidden. Even Android it is possible at the moment to switch off AI, by not installing the app and keeping Google Assistant as it is. Not really possible to use anything else but IOS or Android for smartphones, since that is all that is available, unless I go for a non-smart phone. My problem, certainly with Windows, is that Ms thinks we all want to use AI and don't make it easy to disable. I only use my Windows machine for games these days and will be staying with Windows 10. I use my Mac for everything else, at least Apple gives the choice as i said above to turn AI off.
    • I think X3D is distinct from "X" alone, weren't most early X3D chips clock locked?
  • Recent Achievements

    • Explorer
      Case_f went up a rank
      Explorer
    • Conversation Starter
      Jamie Smith earned a badge
      Conversation Starter
    • First Post
      NeoToad777 earned a badge
      First Post
    • Week One Done
      JoeV earned a badge
      Week One Done
    • One Month Later
      VAT Services in UAE earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      537
    2. 2
      ATLien_0
      230
    3. 3
      +Edouard
      154
    4. 4
      +FloatingFatMan
      149
    5. 5
      Michael Scrip
      108
  • Tell a friend

    Love Neowin? Tell a friend!