Click here to Skip to main content
15,912,932 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
  Form prompt = new Form()
            {
                Width = 500,
                Height = 150,
                FormBorderStyle = FormBorderStyle.FixedDialog,
                Text = caption,
                StartPosition = FormStartPosition.CenterScreen
            };
            Label textLabel = new Label() { Left = 50, Top = 20, Text = text };
            TextBox textBox = new TextBox() { Left = 50, Top = 50, Width = 400 };
            Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK };
           confirmation.Click += (sender, e) => { prompt.Close(); };
            prompt.Controls.Add(textBox);
            prompt.Controls.Add(confirmation);
            prompt.Controls.Add(textLabel);
            prompt.AcceptButton = confirmation;

             prompt.ShowDialog() == DialogResult.OK ? textBox.Text : "";

What I have tried:

prompt.ShowDialog() == DialogResult.OK ? textBox.Text : "";


only assignment call increment decrement and new object can be used as a statement in c#
Posted
Updated 10-Jun-19 20:03pm

1 solution

Look at your code, and I'll simplify it a little:
prompt.ShowDialog() == DialogResult.OK ? textBox.Text : "";
CallMyMethod() == 0 ? "A" : "B";
That isn't a usable statement, because it "returns" one of two strings, but it does nothing with it! The system looks at that and goes 'What am I supposed to do with "A" or "B"? I have nowhere to put them!'

You need an assignment to make that work:
string result = CallMyMethod() == 0 ? "A" : "B";
Gives it somewhere to store the result, so that'll compile.
So perhaps try:
string result = prompt.ShowDialog() == DialogResult.OK ? textBox.Text : "";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900