Ponga información en la etiqueta según lo que el usuario eligió. c# [cerrado]

I am currently trying to get a label(lets name it lblMessage) to pull information based on what the user has picked threw radio buttons and check boxes. Lets make the theme a sundae maker form.. people can select there flavor, size, and addons.

I'm just trying to make it so the label displays once they click the confirm button, a message that identifies the number of sundaes, sundae flavor and size the person ordered. like.. (You ordered 2 small hot fudge sundaes which will cost you $x.xx (where x.xx is the cost for all sundaes ordered). I tried looking this up but i couldn't seem to find what to put into the label code... =\

I am a beginner at C# ... If any other information is needed, I can provide.

preguntado el 27 de noviembre de 13 a las 03:11

1 Respuestas

What you want to do is set the text of the label. You can use the Cadena.Formato method to take a string and replace certain values with values from variables, for example:

var result = MessageBox.Show("Are you sure?", "Are you sure?", MessageBoxButtons.YesNo);
if (result == System.Windows.Forms.DialogResult.Yes)
    Decimal total = int.Parse(textBox1.Text) * 1.25m;

    // The {0} will be replaced with the first argument after the format string.
    // The total.ToString("C") tells the decimal to format the string into a currency string (http://msdn.microsoft.com/en-us/library/fzeeb5cd(v=vs.110).aspx)
    label1.Text = String.Format("You ordered {0} small hot fudge sundaes, which will cost you {1}", textBox1.Text, total.ToString("C"));

Now this example still fails if the textbox does not contain an int, but that can easily be handled using the TryParse método.

respondido 27 nov., 13:04

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.