I am using Windows Forms application using C#.I would like to know, how can I disable the TabPages while it is not open or selected and it can be open by using another button.
Specifically, I want to disable the TabControl of TabPages and TabPages can be controlled by button click using C#.
In your code you have to remove the tab and re-add it when you want it
tabControl1.TabPages.Remove(tabPage1); // Hide the tab page
tabControl1.TabPages.Insert(0, tabPage1);// Show the tab page (insert it to the correct position)
For example:
Hiding a TabPage
private void ButtonHide_Click(object sender, EventArgs e)
{
tabControl1.TabPages.Remove(tabPage1);
}
Showing a TabPage
private void ButtonShow_Click(object sender, EventArgs e)
{
tabControl1.TabPages.Add(tabPage1);
}
Related
I can't believe that disabling specific tabpages (visible but greyed out that means not clickable) is not possible in Visual Studio C# Form app. I have found just a workaround that I couldn't bring to work.(See link below)
I wanted to ask this question again, because perhaps there is another solution/workaround in the meantime.
How to highlight/grey-out Tabcontrol Tabpage
For just making the tab nonclickable (what is also OK for me) I have used this code, but not working
private void tabControl1_Selecting(object sender,TabControlCancelEventArgs e)
{
if (!e.TabPage.Enabled)
{
e.Cancel = true;
}
}
For example if you want to disable tabPage2 use this code in form load event. It will not show in intellisense but you can type.
tabPage2.Enabled = false;
Then use tab control selecting event like this
private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
{
if (e.TabPageIndex < 0) return;
e.Cancel = !e.TabPage.Enabled;
}
this is my frmMain image
I have been struggling with this all day. I have 7 buttons in my nav menu. I have my main form which all those buttons are placed and 7 forms that I will connect to my 7 buttons. 1 form for each button. When I go to another form the previous form I opened is still there. I tried using hide and close to exit the other forms but it was not working for me. I'm also using none border form
btnItems to frmItems
btnUsers to frmUsers
btnSuppliers to frmSuppliers
btnStocks to frmStocks (and so on with the 3 more buttons connected to different forms)
This is the code.
private void btnItems_Click(object sender, EventArgs e)
{frmItems op = new frmItems();
op.Show();
}
private void btnSuppliers_Click(object sender, EventArgs e)
{
frmSuppliers op = new frmSuppliers();
op.Show();
}
Although I don't understand EXACTLY what you are trying to accomplish, is showing the forms as a modal dialog an option? This would ensure that a window must be closed before allowing control to go back to the main form and allow another window to be opened.
private void btnSuppliers_Click(object sender, EventArgs e)
{
using (var op = new frmSuppliers())
op.ShowDialog(this);
}
I want to show my google calendar in my application's tabs. How can I do it?
private void tabPage6_Click(object sender, EventArgs e)
{
//I want to add the code in this tab
}
You need to use a WeBrowser control for this. Drag and drop a WebBrowser control from Tools, suppose name of the WebBrowser control is webBrowser1 the use below code to open calendar
private void tabPage6_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("https://www.google.com/calendar/");
webBrowser1.Show();`
}
I have a C# Windows Forms App that contain a menu bar.
I want to display a Help Message when I press on the "HELP" menu button.
All that I can see when I press view code is this:
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
}
I think that I need to create inside the function a MessageBox or an event that will display the desired message.
Do you have any idea how should I do this, please?
Below should work for what your asking. If you are on your form you can double click the button you want to interact with, and Visual Studio should take you to the empty method.
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("This is supposed to be helpful");
}
I have some problem about window form in VS C# . I make a tabcontrol. it 's compound with tabpage1, tabpage2
. All tabpage will add same panel. when I click for switch tab it should show the panel. but It's not work. It' will show first tabpage but it's not show in other tabpage when i switched tab.
public partial class Form2 : Form
{
public Form2(.....){
..........
InitializeComponent();
...........
panelButton.Controls.Add(btnArr1[i]);
tabControl1.TabPages[0].Controls.Add(panelButton); //It's work
tabControl1.TabPages[1].Controls.Add(panelButton); //it's not show panel
}
}
In another way I try to make event when i click another tabpage. Like this code.
private void tabPage1_Click_1(object sender, EventArgs e)
{
tabControl1.TabPages[0].Controls.Add(panelButton); //It 's work
}
and
private void tabPage2_Click_2(object sender, EventArgs e)
{
tabControl1.TabPages[1].Controls.Add(panelButton); //It is not show panel.
}
What Wrong?
You are trying to add the single object (panelButton) in the different tabs. You should create two panelButtons for each tab, or you should to remove panelButton from the current tab, before adding it in the selected.
you can't add controls with same referece to two different tabPages
the solution is to make a new instance of panelButton and add it to second tab,
Do Not forget that all contorls inside your panelButton must be init too