Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need help on displaying multiple text boxes for C#?

Tags:

c#

textbox

I am trying to make a mailing label program using WinForms where you enter your name, state, city, etc. and it click on a button and it display all the text you entered in each box and displays it on one label. I am close but when i run my program, there is no space between the words. Here is my code:

namespace Mail_Label_Program
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnDisplay_Click(object sender, EventArgs e)
        {
            lblMessage.Text = txtFirst.Text + txtLast.Text;
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            //This closes the program.
            this.Close();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            //This clears all textbox forms.
            txtFirst.Text = string.Empty;
            txtLast.Text = string.Empty;
            txtCity.Text = string.Empty;
            txtStreet.Text = string.Empty;
            txtState.Text = string.Empty;
            txtZip.Text = string.Empty;
        }
    }
}
like image 798
Gunnar Avatar asked Nov 30 '25 09:11

Gunnar


1 Answers

Replace this:

lblMessage.Text = txtFirst.Text + txtLast.Text;

With this:

lblMessage.Text = txtFirst.Text + " " + txtLast.Text;

If someone enters leading/trailing blanks you might like this:

lblMessage.Text = trim(txtFirst.Text) + " " + (txtLast.Text);
like image 124
dcaswell Avatar answered Dec 02 '25 22:12

dcaswell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!