• 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

    • A summary of the article shouldn't be an issue in theory, as the information is all based within the document itself. The problem with a lot of AI models is that they are trained off both Wikipedia as a primary source and other secondary websites which have less reliable information. As an encyclopaedia it is no doubt going to have bias in one way or another, all encyclopaedias do. The difference is that there is a process for a lot of this information to be figured out whether or not it is an opinion, or the source of that information, and to be aware of the possible bias in the first place, even your own bias as a reader. The way many people understand languages these days is quite limited, particularly in certain areas of the world. This is obvious in many types of "journalism" where some articles are thinly disguised opinion pieces, Where language is carefully curated to push a point of view despite it looking like fact. This is partly why a lot of the Western world is now so divided.
    • I paid for a year subscription, starting in December, I think. I like the user-friendliness and assets like royalty-free music and sounds. But they need to fix some of the horrific bugs before they start adding more features. For starters, you should be able to drag stuff around the timeline without it completely obliterating transitions, synchronization timing, and clip lengths. If you already set up footage and audio how you want, and try to insert more by sliding content to the right, you'll have to clean it all up again. The scroll wheel constantly stops working, and you have to minimize the window and restore it to get it back. When selecting text at the top right in special text tools, it glitches and goes to "copy" mode with a weird pop-up on top of your cursor and you can't type. These are more important than AI tools and new features. Microsoft, start by making your product less painful to use.
    • 🙄 Whats the need to launder? Do you have any reputable sources?
    • Thanks, I'll download it and see how it goes. Gonna be tough. I've used Nova Launcher for around 10+ years I think.
    • Wikipedia has become hot molasses with mostly filth masquerading as truth. Most of it is the imagination of few writers who think of themselves as above god. The narrative setup is mind boggling.
  • Recent Achievements

    • Apprentice
      Adrian Williams went up a rank
      Apprentice
    • Reacting Well
      BashOrgRu earned a badge
      Reacting Well
    • Collaborator
      CHUNWEI earned a badge
      Collaborator
    • Apprentice
      Cole Multipass went up a rank
      Apprentice
    • Posting Machine
      David Uzondu earned a badge
      Posting Machine
  • Popular Contributors

    1. 1
      +primortal
      515
    2. 2
      ATLien_0
      258
    3. 3
      +Edouard
      191
    4. 4
      +FloatingFatMan
      174
    5. 5
      snowy owl
      133
  • Tell a friend

    Love Neowin? Tell a friend!