I am attempting to create a toolstrip class that inherits from the system.windows.forms.toolstrip class but specifies the styling to make consistent across our applications. The individual buttons that get added to the toolstrip have a displaystyle property that specify if you want to display an imageonly, textonly, or both. Is there a way I can specify the displaystyle for all buttons to be used in my toolstrip? I'd like to set it in my toolstrip class and have it applied across all applications rather than having to set this in every application.
Asked
Active
Viewed 304 times
0
-
If you want to use something like that across different projects, you need to "carry it around with you" like copying the code all the time or making use of your own dll file for example. Also generally IDEs allow to include references to packages from earlier/other projects – Jul 05 '17 at 18:45
-
What exactly is bothering you? You can create your own custom toolstripbutton class and add it's instances to the strip. Either by code or in the designer. You can create a separate assembly and define the class in it to use in other projects then. – DotNet Developer Jul 05 '17 at 18:47
-
We are just trying to streamline our applications and make everything looks consistent. So I was wondering if there was a way to specify that all toolstripbuttons only display text and no images. Is there anyway I can create sort of a base class and specify this so if our application references my toolstrip, the toolstripbuttons will always be rendered as just text only? – Nighttrain5150 Jul 05 '17 at 18:50
-
1Yes, do exactly that. Create a class of your own inheriting from ToolStrip, and do what you want with it. From then on, use that control on your forms instead of the stock one. – DonBoitnott Jul 05 '17 at 19:02
-
@Bahrom I think you were on the right track with your answer (now deleted). I think you just need to combine it with the answer to [this](https://stackoverflow.com/questions/20836524/prevent-winforms-designer-from-generating-property-values-for-inherited-controls) question to get the designer to stop overriding your property values. – Bradley Uffner Jul 05 '17 at 19:14
-
I restored it. I just doubted if it was what was needed. To get the designer to stop overriding property values I think its better hide serialization of the property. – DotNet Developer Jul 05 '17 at 19:27
1 Answers
1
Create a WindowsFormsControlLibrary project in your solution (for example "ConsistentControls"). Define a class (for example "ConsistentToolStripButton"). Define its capabilities like this.
using System;
using System.Windows.Forms;
namespace ConsistentControls
{
public class ConsistentToolStripButton : ToolStripButton
{
public override System.Windows.Forms.ToolStripItemDisplayStyle DisplayStyle
{
get
{
return base.DisplayStyle;
}
set
{
}
}
public ConsistentToolStripButton()
{
base.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
}
}
}
Now you can use this class in, for example "WindowsFormsApplication1", "WindowsFormsApplication2", "WindowsFormsApplication3" and so on...
Here is a screenshot of Design-Time development

DotNet Developer
- 2,973
- 1
- 15
- 24