My program creating textboxes in panel1. I can give them a values on runtime. But i can't take values from textboxes left to the right.textboxes look like this and i want to take values like 5, 215, 409, 607. My english so bad sorry about this. Please can someone help me :(
CodePudding user response:
Did you tried Text property on the textbox object. let say if your Textbox is TextBox1 then you need to use to read value from the text box "TextBox1.Text"?
You can visit MSDN Help for textbox if you need to learn more
CodePudding user response:
You can get the Text
-values quite easily with LINQ, even without using the names of the textboxes.
Here is an example:
// creating a quick test-form with a panel:
var frm = new Form();
var pnl = new Panel() {Dock = DockStyle.Fill};
frm.Controls.Add(pnl);
for(int i = 1; i<10; i )
{
var tb = new TextBox() {Location = new Point(i*100, 15), Text = i.ToString(), Width = 80};
pnl.Controls.Add(tb);
}
// get Texts from left to right
var textList = pnl.Controls.
OfType<TextBox>().
OrderBy(tb => tb.Left).
Select(tb=> tb.Text).
ToList();
CodePudding user response:
var GetAllTexts = string.Join("", panel1.Controls.OfType<TextBox>().Select(box => box.Text));
Console.WriteLine(GetAllTexts);