how to add the text of a label to code dom?
I have a form in which th开发者_开发技巧ere are various labels and a button..on the button click event there is a code written which generates a cs file in which i want the text of the label to be displayed..
I am trying to get the values with the help of the following function in the code dom but m not able to extract the values of the label i.e. i am just getting label1.text, label2.text, etc. instead i want the values that are there in the labels and the combobox..
can anyone please help..
start.Statements.Add(new CodeVariableReferenceExpression("Info.Valid("\"combobox1.SelectedValue.ToString()\"", "\"label1.Text\"", "\"label2.Text\"", "\"label3.Text\"", "\"numericupdown.Value.ToString()\"")");
here start is the CodeMemberMethod to which all the statements are to be added, Info is another class and Valid is a method to which i need to pass all these values as arguments..
Thats right, your code shouldnt extract any values because you specifies text constants. You may use string.Format method to prepare text data. Try something like below:
string pattern = "Info.Valid(\"\"{0}\"\", \"\"{1}\"\", \"\"{2}\"\", \"\"{3}\"\", \"\"{4}\")";
string data = string.Format(pattern,
combobox1.SelectedValue.ToString(),
label1.Text,
label2.Text,
label3.Text,
numericupdown.Value.ToString());
start.Statements.Add(new CodeVariableReferenceExpression(data));
For more details check out this
精彩评论