You set this variable in your calling code
newMessageBox.lblTitle.Text = txtTitle;
which means you have passed the value to the new instance of the class CustomMessageBox, hence it is available for all non-static class methods.
However, I don't see that you are using
lblTitle.Text
inside
private void CustomMessageBox_Paint(object sender, PaintEventArgs e)
So what do you expect to happen?
That said, a little Object Oriented pointer.
It is not a good practice to expose private member variables to the outside world like you do with
lblTitle.Text
Better wrap this variable in a public property:
public string DialogTitle
{
get
{
return lblTitle.Text;
}
set
{
lblTitle.Text = value;
}
}
This is what they call encapsulation.