C# TabControl ContextMenuStrip - c#

In a user control of mine I implement a tab control that should programmatically manage tab pages. I connected the tab control with a context menu strip with the menu items "Add", "Edit", "Delete" to respectively add a new tab page, edit or delete an existing one. Initially, the tab control does not have any tab pages, and in this case the context menu strip does not appear on right mouse click; if a tab page is there, the context menu strip works as required. At that, the context menu strip is attached to the tab control itself, not to any of the tab pages.
I find this state quite illogical, and my question is whether there is any possibility to make the context menu work attached to a tab control work even if the tab control is empty?

Empty TabControl does not receive mouse events. They are passed to the underlying control.
You can do the following.
Put the TabControl inside a Panel of the same size. Assign the same context menu to this Panel. Then, when TabControl is empty, mouse events will be passed to the Panel and menu will be shown too.

Related

Tab Order With Selected Area

During Design Time of a Windows Form there are a lot of controls to assign their Tab Order with VS Tab Order Button automatically (by clicking each control sequantially).
Is there a way to select a Specific Area in form (contaning limited count of controls to be tab ordered).
Otherwise Tab Order button selects all controls in the form (Labels have no Tab Order although) and it is very diffucult to see clearly related control to click.
No the designer doesn't have such feature, however, if you have such requirement, you can create some user controls and then setup the tab indexes in designer of each user control.
This way you decide about the tab indexes of the user control in the designer of the user control and the tab indexes of the user controls will be part of the user control definition and will be reused in different forms.
Also since the user control is a container control, at the designer of the form, you need to just specify the tab index for the user controls. Also you will see less controls to assign tab index.

Buttons changing Tabs

I want to make buttons change Tabs but i want the tabcontrol to be invisible (Only the page visible not the tabcontrol buttons).
I have 2 buttons Home and Settings and when the Form starts the Home page is visible and when the user clicks Settings button it changes to the Settings page and the same goes for Home button.
So what i need is for the Home and Settings tab buttons to be invisible and i want to only be able to use the buttons i created to change the pages. Hope someone understands. I use Visual Studio 2015 and C#.
Going by the name of your control (TabControl1) I am assuming this is WinForms.
You can achieve what you are describing without using a tab control at all, just move the contents of each of your tabs to seperate UserControls and then swap the visibility or positioning (or both) upon each button click.
For Home button click handler:
settingsUserControl.Visible = false;
homeUserControl.Visible = true;
Then repeat the reverse, in the Settings button click handler.
If you are using TabControl for its border, then use a Panel as a container to the UserControls.
In fact, this is similar to how Tab Controls worked in VB6, the control being hidden would be shoved 30,000 Twips off to the left, outside the view port of the tab control.

Visual C# Add Item to contextMenuStrip with link

How can I add an item to a contextmenustrip, as well as code the button_click action for it?
I'm making a web browser application, and I have a drop down menu of 'favorite' websites. When someone clicks a button, it adds the title of the website into the dropdown menu, but I also need it navigable to the website URL that was inputted. I have no idea how to add button click actions when I add a new item to a contextmenustrip.
Is this a WinForms application?
If so, in the Visual Studio designer, after you drag a contextMenuStrip from the boolbox, it allows you to type new entries at the contextMenuStrip (click where it says 'Type Here' to add a new item). If you are going back to an existing contextMenuStrip, you will have to make it appear by clicking on the contextMenuStrip item at the bottom of the designer.
Once you have the item, you can just double-click on it to whatever code you want to execute on the click event. (This is the default event; for other events you will have to double-click the appropriate event from the Properties pane.

How to Change TabPage Position in C#.NET?

I have six tabs on my Windows application. I need to put tab #6 after tab #2, how can i do it?
I couldn't drag the tab to the location i want! The 5 tabs are full of controls that took long time to name and design. Any idea how to move last tab and place it after 3rd tab?
In order to arrange the tabs in a TabControl, access the property dialog for the TabControl and find the "TabPages" property. Clicking on the little button next to the value field will display a dialog which will allow you to control the properties and position of each tab in the TabControl.
TabPages Property http://img16.imageshack.us/img16/6334/tabeditor.png
Although an answer is there: I thought this picture may speak few more words ;)
Click on Tab Control
Go to Properties Window
Click on Tab Page as highlighted in blue
Voila! The TabPage Collection Editor allows you to perform what you need. It's intuitive.

What's the equivalent of MdiWindowListItem when using a DockPanelWorkspace?

We have a composite application with a DockPanelWorkspace as its main user interface area. Above this sits a MenuStrip with a window menu set as its MdiWindowListItem. Unfortunately, as I feared, the window menu isn't populated with the open views.
Is there an equivalent in CAB that will populate a menu with a list of the open views in a workspace? If not, how should I go about implementing that feature?
MdiWindowListItem is automatically populated with items added as MdiChild. You have to develop custom logic for docked window, handling the following .
Adding menu item to the window menu (set as MdiWindowListItem)
Removing the menu item when the related window is closed
EventHandler for selecting the window when the menu is clicked
I am not familiar with DockPanelWorkspace.
So logic of selecting the window has to be sorted.
Changes of DockState like the window changes to MDIChild

Categories