User Control
-
How do you mean - save to where ? To a file ? To each other ?
Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
to save each other
-
to save each other
Expose the
TextBox.Text
property as a property of yourUserControl
. egpublic string TextBoxText
{
get { return textBox1.Text; }
set { textBox1.Text = value; }
} -
I am doing a project and I just created a user control(consist of text boxes, labels and combo boxes) that added in more than one tab pages. I am being able to add the user control in the tab pages. e.g. The same user control added in three tabpages. But I would like to save the value of the text boxes of the user controls added in the respective tab pages. how could i?
-
I am doing a project and I just created a user control(consist of text boxes, labels and combo boxes) that added in more than one tab pages. I am being able to add the user control in the tab pages. e.g. The same user control added in three tabpages. But I would like to save the value of the text boxes of the user controls added in the respective tab pages. how could i?
I have 4 different cases for you: If you need the same TextBox in each of your tab pages, you may consider adding one TextBox to the TabControl (i.e. outside the tab pages) rather than to each individual page. If you need the same TextBox on some of your tab pages, you may still put it on the tab control (outside the tab pages) and you could alter its Visible state according to which tab page is currently active. If you need the same TextBox on some of your tab pages, and the instances have identical properties (such as font, backcolor, location, size, etc), then I would use Visual Studio Designer to add such TextBox to one of the pages, then programmatically add the same instance of TextBox to the other relevant tab pages. Something like tabpage.Controls.Add(myExistingTextBoxFromTabPage1); Then there is no doubt whatever relevant tab page you select you would see the same TextBox content, since there is actually only one instance. This will save you a lot of code that would otherwise be needed to keep multiple TextBoxes in sync. If your TextBoxes have different attributes on different tab pages, more code will be unavoidable. :)
Luc Pattyn
-
I have 4 different cases for you: If you need the same TextBox in each of your tab pages, you may consider adding one TextBox to the TabControl (i.e. outside the tab pages) rather than to each individual page. If you need the same TextBox on some of your tab pages, you may still put it on the tab control (outside the tab pages) and you could alter its Visible state according to which tab page is currently active. If you need the same TextBox on some of your tab pages, and the instances have identical properties (such as font, backcolor, location, size, etc), then I would use Visual Studio Designer to add such TextBox to one of the pages, then programmatically add the same instance of TextBox to the other relevant tab pages. Something like tabpage.Controls.Add(myExistingTextBoxFromTabPage1); Then there is no doubt whatever relevant tab page you select you would see the same TextBox content, since there is actually only one instance. This will save you a lot of code that would otherwise be needed to keep multiple TextBoxes in sync. If your TextBoxes have different attributes on different tab pages, more code will be unavoidable. :)
Luc Pattyn
I created a user control that contains labels, textboxes and comboboxes and added it in my tabpages(4 tabpages) dynamically through programming. I created a class named clsProject and declared a read write property Name from where textboxes will get there values. e.g "txtName.Text = clsProject.Name" My Question is : I would like to display it in all my tabpages. But how could I? I would like to do this in following manner. tabcontrol1.tabpages1.textName.text = clsProject.Name tabcontrol1.tabpages2.textName.text = clsProject.Name So that I can save the corresponding tab pages text box control values in a routine name Save(), if the user changes the Name of for each tabpages. e.g. Void Save() { clsProject.Name = tabcontrol1.tabpages1.textName.text clsProject.Name = tabcontrol1.tabpages2.textName.text } Can you tell me how can I resolve this problem ?
-
I created a user control that contains labels, textboxes and comboboxes and added it in my tabpages(4 tabpages) dynamically through programming. I created a class named clsProject and declared a read write property Name from where textboxes will get there values. e.g "txtName.Text = clsProject.Name" My Question is : I would like to display it in all my tabpages. But how could I? I would like to do this in following manner. tabcontrol1.tabpages1.textName.text = clsProject.Name tabcontrol1.tabpages2.textName.text = clsProject.Name So that I can save the corresponding tab pages text box control values in a routine name Save(), if the user changes the Name of for each tabpages. e.g. Void Save() { clsProject.Name = tabcontrol1.tabpages1.textName.text clsProject.Name = tabcontrol1.tabpages2.textName.text } Can you tell me how can I resolve this problem ?
-
Expose the
TextBox.Text
property as a property of yourUserControl
. egpublic string TextBoxText
{
get { return textBox1.Text; }
set { textBox1.Text = value; }
}I created a user control that contains labels, textboxes and comboboxes and added it in my tabpages(4 tabpages) dynamically through programming. I created a class named clsProject and declared a read write property Name from where textboxes will get there values. e.g "txtName.Text = clsProject.Name" My Question is : I would like to display it in all my tabpages. But how could I? I would like to do this in following manner. tabcontrol1.tabpages1.textName.text = clsProject.Name tabcontrol1.tabpages2.textName.text = clsProject.Name So that I can save the corresponding tab pages text box control values in a routine name Save(), if the user changes the Name of for each tabpages. e.g. Void Save() { clsProject.Name = tabcontrol1.tabpages1.textName.text clsProject.Name = tabcontrol1.tabpages2.textName.text } Can you tell me how can I resolve this problem ?
-
How do you mean - save to where ? To a file ? To each other ?
Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
I created a user control that contains labels, textboxes and comboboxes and added it in my tabpages(4 tabpages) dynamically through programming. I created a class named clsProject and declared a read write property Name from where textboxes will get there values. e.g "txtName.Text = clsProject.Name" My Question is : I would like to display it in all my tabpages. But how could I? I would like to do this in following manner. tabcontrol1.tabpages1.textName.text = clsProject.Name tabcontrol1.tabpages2.textName.text = clsProject.Name So that I can save the corresponding tab pages text box control values in a routine name Save(), if the user changes the Name of for each tabpages. e.g. Void Save() { clsProject.Name = tabcontrol1.tabpages1.textName.text clsProject.Name = tabcontrol1.tabpages2.textName.text } Can you tell me how can I resolve this problem ?
-
I created a user control that contains labels, textboxes and comboboxes and added it in my tabpages(4 tabpages) dynamically through programming. I created a class named clsProject and declared a read write property Name from where textboxes will get there values. e.g "txtName.Text = clsProject.Name" My Question is : I would like to display it in all my tabpages. But how could I? I would like to do this in following manner. tabcontrol1.tabpages1.textName.text = clsProject.Name tabcontrol1.tabpages2.textName.text = clsProject.Name So that I can save the corresponding tab pages text box control values in a routine name Save(), if the user changes the Name of for each tabpages. e.g. Void Save() { clsProject.Name = tabcontrol1.tabpages1.textName.text clsProject.Name = tabcontrol1.tabpages2.textName.text } Can you tell me how can I resolve this problem ?
If you want them to all be the same, then make a static property that stores the string, and a static array of textboxes, which each textbox adds itself to. Then, changing it in one instance, will change it in all. The other option is to set up a delegate, so each control lets the parent form know when it's changed, and it sets them all, with the sort of code you have above.
Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
-
I created a user control that contains labels, textboxes and comboboxes and added it in my tabpages(4 tabpages) dynamically through programming. I created a class named clsProject and declared a read write property Name from where textboxes will get there values. e.g "txtName.Text = clsProject.Name" My Question is : I would like to display it in all my tabpages. But how could I? I would like to do this in following manner. tabcontrol1.tabpages1.textName.text = clsProject.Name tabcontrol1.tabpages2.textName.text = clsProject.Name So that I can save the corresponding tab pages text box control values in a routine name Save(), if the user changes the Name of for each tabpages. e.g. Void Save() { clsProject.Name = tabcontrol1.tabpages1.textName.text clsProject.Name = tabcontrol1.tabpages2.textName.text } Can you tell me how can I resolve this problem ?
I really can't understand what you are after! Also in your code snipets you have two sequencial commands that practically ony the second has meaning. By the way posting the same in two different persons trying to help and asking different questions is not the way.
-
I created a user control that contains labels, textboxes and comboboxes and added it in my tabpages(4 tabpages) dynamically through programming. I created a class named clsProject and declared a read write property Name from where textboxes will get there values. e.g "txtName.Text = clsProject.Name" My Question is : I would like to display it in all my tabpages. But how could I? I would like to do this in following manner. tabcontrol1.tabpages1.textName.text = clsProject.Name tabcontrol1.tabpages2.textName.text = clsProject.Name So that I can save the corresponding tab pages text box control values in a routine name Save(), if the user changes the Name of for each tabpages. e.g. Void Save() { clsProject.Name = tabcontrol1.tabpages1.textName.text clsProject.Name = tabcontrol1.tabpages2.textName.text } Can you tell me how can I resolve this problem ?
Since you want the TextBox visible on each of the tab pages, I would go for one of these two possibilities: 1) -with Designer (or programmatically) add the TextBox on the first tab page (say it is named "textName1"), and leave the same place free on all other tab pages - programmatically add the SAME TextBox to the other tab pages. Something like:
bool firstPage=true;
foreach (TabPage page in myTabControl) {
if (!firstPage) page.Controls.Add(textName1);
firstPage=false;
}Of course you could also use the tab page names explicitly:
tabPage2.Control.Add(textName1); tabPage3.Control.Add(textName1); tabPage4.Control.Add(textName1);
or 2) do not add the TextBox to one or more tab pages, but add it to the form that is holding the tab control (not "to the tab control" as I had put in my previous post, that was slightly wrong, really to the form holding the tab control). In both cases, there is only one TextBox control, it is named textName1, so you have to set its text only once, have to save its text only once, etc. :)
Luc Pattyn