I have several tab pages collection. By default when user open the apps, the first tab page is the start tab page, then user will close the tab page. Now I would like to create a situation where when the user go to the menu strip, click for example the "tab page 1 button", then the "tab page 1" will appear in the tab control. Any expertise can help me please...
Use the SelectedTab() method. It has three overloads.
If you have a reference to the tab:
tabControl1.SelectTab(tabPage2);
If you only know the index:
tabControl1.SelectTab(1); // 0-based index, this shows the second tab
If you only know the name:
tabControl1.SelectTab("tabPage2");
You say your users can click an [x] that removes the tab.
I'll assume it's removed by the easiest means, something like:
tabControl1.TabPages.Remove(tabPage1);
You can't focus on a tab that's not part of the tab control, so you'll have to add it back first.
tabControl1.TabPages.Add(tabPage1); // add tab as last tab in tabcontrol
tabControl1.TabPages.Insert(0, tabPage1); // or insert it at a specific index
tabControl1.SelectTab(tabPage1);
To select the tab page of the TabPage control, not only could user click the title to switch pages, but set the selectedTabPageIndex property (or like this) to do it.
Just have a try.
i am also facing this problem. Finally i solve by following code.
Scenario
My tab Control have many tabs and i make a [x] sign for closing that tab.
on click [x] my tab is remove from Tab Control.
Now when i click on button, i open the tab (that was Removed)
Code
private void openProductTab_Click(object sender, EventArgs e)
{
if (tabControlMdi.TabPages.Contains(tabProduct))//tab already present
{
tabControlMdi.SelectTab(tabProduct); // select by name
}
else
{
tabControlMdi.TabPages.Add(tabProduct); // add removed tab
tabControlMdi.SelectTab(tabProduct); // select by name
}
}
private void invoiceGenerationToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (Form form in Application.OpenForms)
{
if (form.GetType() == typeof(RETransactions.frmInvoicegeneration))
{
form.Activate();
foreach (TabPage item in tabControl1.TabPages)
{
if (item.Text == "Invoice Generation")
{
tabControl1.SelectTab(item);
}
}
return;
}
}
RETransactions.frmInvoicegeneration rTenancy = new RETransactions.frmInvoicegeneration();
rTenancy.Show();
rTenancy.TopLevel = false;
TabPage tabp = new TabPage("Invoice Generation");
tabp.Controls.Add(rTenancy);
tabControl1.TabPages.Add(tabp);
tabControl1.SelectTab(tabp);
tabp.BackColor = Color.Gainsboro;
}
// i hope it will work ... thank you
Related
In my design there are three buttons. I want to open new windows on each button click. I have done upto open a new window. But when I click on the second button it opens in the same popup window. How can I avoid this and open three windows when click on these three buttons?
c# code
protected void btnApprove_Click(object sender, EventArgs e)
{
string ddlVal = ddlComp.SelectedValue.ToString();
if (ddlVal != "--Select The Competition--")
{
Session["ddlVal"] = ddlComp.SelectedValue.ToString();
ScriptManager.RegisterStartupScript(this, typeof(string), "APPROVE_WINDOW", "var Mleft = (screen.width/2)-(760/2);var Mtop = (screen.height/2)-(700/2);window.open( 'approved.aspx', null, 'resizable=yes, status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,top=\'+Mtop+\', left=\'+Mleft+\'' );", true);
}
else
{
WebMsgBox.Show("Select a competition");
}
}
This is the code I have used for all the three buttons with different page names
You can pass the name parameter as '_blank' instead of null.
Change the below line in your code
window.open( 'approved.aspx', null,
to
window.open( 'approved.aspx', '_blank',
If you're referring to top-level browser windows, you cannot - browsers disable this for obvious reasons (pop-up blockers, etc). You also cannot have more than one JavaScript alert() window open at a time.
Your WebMsgBox class wraps the alert() function. So this not possible.
You will need to change your client-code to instead display multiple elements (e.g. absolutely-positioned <div> boxes with a modal rectangular appearance).
I want to build my own web browser, but I'm stuck on operation for adding new tab, does anyone have any idea to make it done?
The final result will should like this.
you can try this:-
if (tabControl1.SelectedTab.Text == "+")
{
AddNewTab();
}
foreach (Control item in tabControl1.SelectedTab.Controls)
{
if (item.GetType() == typeof(WebBrowser))
{
WebBrowser wb = (WebBrowser)item;
toolStripButton1.Enabled = wb.CanGoBack;
toolStripButton2.Enabled = wb.CanGoForward;
}
}
The way I'd go about it would be (using a TabControl or similar) to create a special tab with just the plus icon you want. Then handle the tab changed event, check if you've switched to the special tab, and if so, cancel the tab change, create a new tab and set that to be displayed instead.
I have a tab control in my WPF application with multiple tabs. Each tab gives access to several buttons, text boxes, drop downs. Now before moving to the next tab valid entries in each of the controls in the tab is to be checked or jumping to the next tab should not be allowed. How can this be done?
I was able to use IsEnable property to do this. But I want it like, when I click on the next tab it should, without entering the next tab, display a warning that such and such entry in the present tab is not valid.
If you adhere to the Selected event you can do something like this:
// Keep a global variable for the previous index
int prevIndex = 0;
private void tabControl_Selected(object sender, TabControlEventArgs e)
{
TabControl tc = sender as TabControl;
if (tc != null)
{
bool letSwitchHappen = validateTabControls(tc.SelectedIndex);
if (!letSwitchHappen)
{
tc.SelectedIndex = prevIndex;
}
prevIndex = tc.SelectedIndex;
}
}
Where validateTabControls is something like:
private bool validateTabControls(int tabIndex)
{
bool validEntries = false;
// Some code here to set validEntries according to the control at tabIndex
return validEntries;
}
Take a look at this example from Josh Smith.
It shows explicitly how to do this, and Josh is well-known (and respected) in the WPF world.
I'm looking for solution for my problem. I want to change location for tabcontrol's TabButtons or add control assigned to tabpage but outside TabControl. TabPages are added dynamically. Example:
Form1___________ _ [] X
_______________________
Some TabPage content
Tab1 | Tab2 | Tab3 | < >
TextBox assigned to Tab's
________________________
So if I change tabs by clicking on Tab1,Tab2,Tab3 TabPage + TextBox content should change depending on Tab. The first idea was to put TabButtons on bottom and add ArrayList what contains TextBox content, catch TabControl change tab event and change TextBox content, but there was an issue with editing and adding that content. In few words: I wan't to put TabButtons between 2 controls(for example between two textboxes).Do you have any ideas?
If I understand what you're asking for... You want when you click on a tab, it controls two different things? Like two different text boxes?
If that is true, you should be able to do it like this.
foreach (thing in your ArrayList)
{
TabPage tabPage = new TabPage("Name of tab"); // Add a new tab page
RichTextBox rtb = new System.Windows.Forms.RichTextBox();//RTF box
TextBox tb = new System.Windows.Forms.TextBox(); //Text box
//Set up size, position and properties
rtb.LoadFile("some/Path/to/a/file");
//set up size, position of properties
tb.Text = "Some text I want to display";
tabPage.Controls.Add(rtb); //Add both boxes to that tab
tabPage.Controls.Add(tb);
tabControl1.TabPages.Add(tabPage); //Add that page to the tab control
}
Only thing you should have to mess around with is the layout. And make sure to have the tabControl added with the designer.
you can create your own textbox class which inherits from textbox class :
class MyOwnTextBox:TextBox
{
public int parent_tab;
}
So you can add your textbox by assigning a parent_tab id to them . so in tab button click event , you can do something like that :
foreach(MyOwnTextBox txt in this.Controls)
{
if(txt.parent_tab==1) txt.visible=false;
}
You could also place the tabs on the left or the right side of your tab control. That is not perfect, but would come closer to your idea than placing them above or below the tab control.
You can add a new tab page dynamically like this
tabControl1.TabPages.Add("My new Tab");
I'm not sure I understand exactly what your trying to do. If you want to change the tab from another object, just use:
TabController.SelectTab(0);
If you want to remove a TabPage and add it to another, use:
TabController.Controls.Remove(TabPage1);
TabController2.Controls.Add(TabPage1);
Edit: From further read, I think you want something like this:
this.TabController.ControlAdded += AddLinksToBottomOfTabs;
public void mainSettingsTabController_ControlAdded(object sender, ControlEventArgs e)
{
//Create label with e.Control.Name as the title and
//add it to wherever you want it added.
}
Goal:
Right clicking in the listview and choose different option.
Problem:
There are two problem:
*When I'm right clicking, the left corner of the menu is not exactly located in the arrow's spot location.
*How do I create a line in the menu?
The main problem about the menu
Need support to create these two redmark.
private void lstV_Stock_MouseUp(object sender, MouseEventArgs e)
{
switch (e.Button)
{
// Right mouse click
case MouseButtons.Right:
ContextMenu myContextMenu = new ContextMenu();
MenuItem menuItem1 = new MenuItem("New product");
MenuItem menuItem2 = new MenuItem("Delete");
MenuItem menuItem3 = new MenuItem("Add quantity");
// Clear all previously added MenuItems.
myContextMenu.MenuItems.Clear();
myContextMenu.MenuItems.Add(menuItem1);
myContextMenu.MenuItems.Add(menuItem2);
myContextMenu.MenuItems.Add(menuItem3);
if (lstV_Stock.SelectedItems.Count > 0)
{
foreach (ListViewItem item in lstV_Stock.SelectedItems)
{
myContextMenu.MenuItems[1].Visible = true;
myContextMenu.MenuItems[2].Visible = true;
myContextMenu.MenuItems[0].Visible = false;
}
}
else
{
myContextMenu.MenuItems[1].Visible = false;
myContextMenu.MenuItems[2].Visible = false;
myContextMenu.MenuItems[0].Visible = true;
}
myContextMenu.Show(lstV_Stock, this.PointToClient(Cursor.Position), LeftRightAlignment.Right);
menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
break;
}
For the positioning, you can replace your
myContextMenu.Show(lstV_Stock, this.PointToClient(Cursor.Position), LeftRightAlignment.Right);
to
myContextMenu.Show(lstV_Stock, e.Location(), LeftRightAlignment.Right);
or the point e.X,e.Y. Not from this.PointToClient, but from the MouseEventArgs generating the event. You can check wahat MouseEvent have here.
To create a "line" you have to create a MenuItem with text "-"
Problem
If you just set the ListView.ContextMenu property and remove all your own right-click code, the menu should show up correctly.
For the line you need a ToolStripSeparator item. The designer will create one when you type '-' as the Text. You can drag them in the designer.
So, using a ContextMenu is the way to go here. Those "Lines" you're referring to are called Separaters.
If you're creating the COntext Menu in Design View, then click the Context Menu, then right-click inside the menu, and click Insert > Separater.
You can then drag it up or down, or into a sub-menu if you wish.