|
-
May 4th, 2006, 11:24 AM
#1
Thread Starter
Junior Member
[2.0] TabControl in C#
I am creating a windows application in C# using Visual Studio 2005.
I get an error when I try to Hide Salary tab by discarding what I created earlier...
Error: Cannot implicitly convert type 'void' to 'System.Windows.Forms.TabPage'
Line: tabpg = this.tabctrlEmployeeInfo.TabPages.Add("tabpgSalary");
Thank you,
This is the entire code Function
---------------------------------------------------------------------------------------------------------------------
//Called to dynamically show/hide the "Salary" tab page
//
private void showSalaryToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.showSalaryToolStripMenuItem.Text.StartsWith("Show"))
{
//Show Salary tab, which we create on the fly
//
TabPage tabpg;
tabpg = new TabPage("Salary");
tabpg.Name = "tabpgSalary";
tabpg.ForeColor = Color.Red;
Label lbl;
lbl = new Label();
lbl.Text = "Salary:";
lbl.Location = new Point(30, 40);
TextBox txt;
txt = new TextBox();
txt.Name = "txtSalary";
txt.Location = new Point(100, 37);
txt.ReadOnly = true;
txt.Size = new Size(200, 26);
tabpg.Controls.Add(txt);
tabpg.Controls.Add(lbl);
this.tabctrlEmployeeInfo.TabPages.Add(tabpg);
if (this.employee != null)
{
//we have an employee being displayed, show their salary
txt.DataBindings.Add("Text", this.employee, "FormattedSalary");
}
this.showSalaryToolStripMenuItem.Text = "Hide Salary"; //flip menu text
}
else
{
//
//Hide Salary tab by discarding what we created earlier...
//
TabPage tabpg;
tabpg = this.tabctrlEmployeeInfo.TabPages.Add("tabpgSalary");
this.tabctrlEmployeeInfo.TabPages.Remove(tabpg);
this.showSalaryToolStripMenuItem.Text = "Show Salary"; //flip menu text
}
}
-
May 4th, 2006, 12:42 PM
#2
Re: [2.0] TabControl in C#
Why are you adding a tabpage to tabpg then trying to remove it? If you want it hidden, just change it's Visible property to false.
-
May 4th, 2006, 12:47 PM
#3
Thread Starter
Junior Member
Re: [2.0] TabControl in C#
 Originally Posted by kasracer
Why are you adding a tabpage to tabpg then trying to remove it? If you want it hidden, just change it's Visible property to false.
Thank you,
Please could you give me the syntax to change the tabcontrol's visible property to false.
Regards
-
May 4th, 2006, 12:58 PM
#4
Re: [2.0] TabControl in C#
MyTabControl.Visible = false;
or if you want to make your tabpage invisible
MyTabPage.Visible = false;
-
May 4th, 2006, 01:20 PM
#5
Thread Starter
Junior Member
Re: [2.0] TabControl in C#
 Originally Posted by kasracer
MyTabControl.Visible = false;
or if you want to make your tabpage invisible
MyTabPage.Visible = false;
Thank you,
But I see no visible property for my TabPage.
As you already know, I am creating this TabPage Dynamically.
And I want to Hide and Show this Tab.
Thank you
-
May 4th, 2006, 02:46 PM
#6
Re: [2.0] TabControl in C#
Oh sorry, I forgot it does not have a Visible property. Use the Hide() and Show() methods.
-
May 4th, 2006, 06:21 PM
#7
Re: [2.0] TabControl in C#
Hide and Show don't work with tab pages. If you want a tab page to not be visible then you have to remove it from the tab control. Your immediate problem is this line:
Code:
tabpg = this.tabctrlEmployeeInfo.TabPages.Add("tabpgSalary");
That is trying to assign the result of the Add method to a TabPage variable, but that method doesn't return a TabPage object, or anything else for that matter. I think what you mean is:
Code:
tabpg = this.tabctrlEmployeeInfo.TabPages("tabpgSalary");
without the Add. That will get the TabPage with that name.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|