• 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

    • In the case of the orange one it literally was just an Android app, someone already extracted it from the device and ran it on an android phone.
    • There were rumors of both - these third-party devices and a first-party Microsoft's handheld - the latter one was cancelled or postponed indefinitely. The difference is in licensing games - for a lot of thirdparty games Microsoft has distribution license only for consoles. I know that for some time already the hardware is the same, but legally they are totally different devices. That's why Microsoft wasn't on the hook for 30% cut from purchases on Xbox, but lowered its cut on Windows Store to just 12%.
    • Very true, they are trying to extract more revenue from viewers, and I agree with you that it will likely backfire on them and ultimately drive people to other platforms. I do think YouTube could ultimately win the battle against ad block if they want to, blocking ads is inherently significantly more complicated than enforcing them. We could easily get to a point where the best an ad-blocker can do is cover ads with a black screen while you wait out the deration. It isn't like software on your computer can force Google's servers to send the video content sooner than they deem appropriate. As for as dollars, I think you have your numbers mixed up a little. $29 is YouTube's revenue number, not worth or profit. YouTube being owned by Google means their worth and profit numbers are not directly known. Based on Google's reporting, it costs them more than YouTube's revue to run the platform. Maybe they are playing with the numbers a little, and certainly Google gets value from YouTube beyond direct revenue.
    • YouTube comments are not displaying correctly for some users by Aditya Tiwari Image by ElisaRiva via Pixabay YouTube comments have long been used to express opinions, ask questions, provide feedback, share insights, or simply react to the video you're watching. However, this can sometimes go south, and unexpected bugs can ruin the experience. The Google-owned video sharing platform reached out to its community support forum to announce that YouTube comments are not displaying correctly for some users. YouTube has listed various ways the known issue can appear on your screen. For instance, comments are only visible when the "Newest First" filter is chosen; they might disappear or hide when "Top Comments" is selected, or they may not display at all. Some users may not be able to sort comments by "Top Comments," or their comments may disappear after being posted. "We're aware that some of you are experiencing an issue where comments aren't showing up beneath certain videos, and we're looking into it now," YouTube said, adding that it will follow up on the issue with an update. However, it didn't mention the regions where the problem is most prominent or specify the platforms (Android, iOS, or desktop) that are affected. This comes about a week after YouTube ran into a different problem: the bottom navigation bar on its Android app wasn't displaying for users in different countries. YouTube has now marked that issue as fixed. In recent updates, the video streaming giant took down a video that taught people how to self-host their media, citing policy violations. Its latest update for iOS brings bad news for people running old iPhones; several of them are now incompatible with the YouTube app. While YouTube has introduced features like Google Lens for Shorts, voting for playlists, and trending podcasts charts, it plans to insert more ads into its cheaper premium tier later this month.
  • Popular Contributors

    1. 1
      +primortal
      472
    2. 2
      +FloatingFatMan
      278
    3. 3
      ATLien_0
      246
    4. 4
      snowy owl
      204
    5. 5
      Edouard
      190
  • Tell a friend

    Love Neowin? Tell a friend!