I would like to be able to change the style of the ContextMenuStrip currently available in .NET, I've always found it very ugly.
For example, this is the one in the Framework:
And I would like to use this system-style menu in my program:
Is there any way I can use the normal context strip in a managed app?
Try to use the old ContextMenu control, e.g.
ContextMenu menu = new ContextMenu();
menu.MenuItems.Add("Hello");
menu.MenuItems.Add("-"); // yes, this makes a separator !!!
menu.MenuItems.Add("World");
Image:
Related
I want to use the Create-Wall-Button from Architecture in my Ribbon.
I've tried debugging and found the splitbutton here: Autodesk.Windows.ComponentManager.Ribbon.Tabs[0].Panels[1].Source.Items[0]
How can I copy this SplitButton to my Ribbon or what I have to call in a new Button to use this function?
Thank you.
It is posible to clone an built-in command button and add it to another tab, however you would need a couple of tricks and of course the non-supported Autodesk.Windows dll.
I think what you are looking for is the method PostCommand from the UIApplication. Just create a new command and the requested Postable Command will be executed after your own command is completed:
var app = cmdData.Application;
var cmdId = RevitCommandId.LookupPostableCommandId(PostableCommand.StructuralWall);
app.PostCommand(cmdId);
I have a menustrip that I create using the forms designer. I then want to programmatically add a toolstrip toolbar UNDER the menustrip. The reason is that this toolbar is a set of tools that I add as a plugin to the main application. As such, when the plugin is loaded, I create the toolbar.
When I manually add the toolstrip to the form using the forms designer, the toolstrip is correctly positioned under the menustrip. However when I add it programmatically, it snaps to the topmost part of the form, above the menustrip. Here's the code I use to programmatically add the toolstrip:
stereoBar = new ToolStrip();
stereoBar.Anchor = (AnchorStyles)(AnchorStyles.Top | AnchorStyles.Left);
//y location is set to 22, the width of the menustrip
stereoBar.Location = new System.Drawing.Point(0, 22);
stereoBar.Dock = DockStyle.Top;
stereoBar.Name = "StereoToolbar";
stereoBar.Text = "Stereo Plugin Toolbar";
stereoBar.ShowItemToolTips = true;
stereoBar.GripMargin = new Padding(2);
Controls.Add(stereoBar);
Is there anything simple I am missing here?
Thanks in advance!
As described also in this answer, when docking controls in a form the order in which you add them to the form matters; i.e. when adding multiple controls that all dock to the top, the last control that gets added will be the topmost.
So, because you add your toolstrip programmatically and your menu strip via designer, the designer code gets executed first thus having the menu strip always at the bottom.
I think there are three ways out of the dilemma:
First approach
As Hans Passant pointed out, the easiest way to get things into the right order would be to simply call
stereoBar.BringToFront();
right after you added it to the forms' controls.
Second approach
To circumvent this you could also also add the menu strip programmatically and do this after you added the tool strip.
Third approach
Another way out may be to add another container to the form (Panel or groupbox for example) via designer that also docks to the top that simply just functions as a placeholder where you add your tool strip to (so you do not add to the form directly anymore)
I am using Visual Studio 2010, and I have come across a need to use the ToolStripSplitButton button. I figured out from the reference material that ToolStripSplitButton is a form found under the System.Windows.Forms.
When I attempt to add this to my toolbox to try to use, I am unable to find ToolStripSplitButton, does anybody know how I can add this to my Visual Studio 2010 so I can use it? I don't care if it's not in the toolbox, I just want to make sure the assembly reference is present so I can actually use it.
ToolStripSplitButton can be used only as ToolStripItem of a ToolStrip (contained in ToolStrip.Items). It's designed so that you can't use it as a normal control. It doesn't have a Parent property, and I guess it also doesn't have a Handle property. The inheritance tree is:
ToolStripSplitButton
-> ToolStripDropDownItem
-> ToolStripItem
-> Component
-> ...
Normally, you have to add some ToolStrip to host ToolStripSplitButton.
If you want to use code, here is a simple example:
ToolStrip toolStrip1 = new ToolStrip();
ToolStripSplitButton splitButton1 = new ToolStripSplitButton("Hi there"){Owner = toolStrip1};
//you can add items to ToolStripSplitButton via ToolStripSplitButton.DropDownItems
More info ToolStripSplitButton
It's inherited from and dependent on ToolStripDropDown so you can't use it as a stand-alone control.
You can use it as a child control for ToolStripDropDown.
So my question is:
I got an Windows Forms application in C# and an webBrowser control in this application. When you for example right-click on a video in youtube, a context menu shows up. Now, is it possible to programmatically rightclick in the webBrowser control an then, again programmatically, click a specific entry in that context menu?
Yes it is, but you always have to start from the same pixel, or better said an actual pixel range, so you can be sure that the clicked result will be the required one. Also you cant click an item by specifying its text, you must do everything programatticaly, from the graphics point of view(just work on the X - Y Axis since its only 2 dimensional). That is the way most web bots are made for various purposes.
Do you really have to simulate a click of the context menu or is just having the desired action good enough? If so than you can just get the item from the ContextMenu.Items list and assuming it a button raise its Click event. If you do need to at least show the context menu while do this you can call the ContextMenu.Show event. This all assumes that the contextmenu for your WebBrowser control is public (not some third party inherited control that hides it or something).
Is it possible to add a TrackBar control to a ContextMenu? So when I right click, my ContextMenu will drop down and a TrackBar will appear as a menu item?
If your context menu is a ContexMenuStrip, you can create an item in this way:
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.MenuStrip |
ToolStripItemDesignerAvailability.ContextMenuStrip)]
public class TrackBarMenuItem : ToolStripControlHost
{
private TrackBar trackBar;
public TrackBarMenuItem():base(new TrackBar())
{
this.trackBar = this.Control as TrackBar;
}
// Add properties, events etc. you want to expose...
}
Thanks to the ToolStripItemDesignerAvailability attribute, you can even see the item in the Forms Designer, as shown in the image below:
P.S.
This solution comes from this MSDN example
Yes, you need to set the context menu to user draw and draw the menu items yourself. You will have to create a custom MenuItem the implementes a TrackBar
For what it's worth for anyone who stumbles across this having problems with:
Constructor on type 'System.Windows.Forms.ToolStripControlHost' not found.
The only way I got it to work was by putting the derived control in it's own file. When it is in the same file as another control it confuses the designer.