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;
}
}
}
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With