lunes, 6 de abril de 2015

Extending TextBox component with integrated text




private void tbName_Enter(object sender, EventArgs e)
{
   lbName.Visible = false;
   tbName.BackColor = System.Drawing.Color.FromArgb(34, 34, 34); ;
}

private void tbName_Leave(object sender, EventArgs e)

{
   lbName.Visible = tbName.Text.Trim().Equals(string.Empty);
   tbName.BackColor = System.Drawing.Color.FromArgb(64, 64, 64); 
}

private void lbName_Click(object sender, EventArgs e)
{
   tbName.Focus();
}


UI CODE

// 
// lbName
// 
this.lbName.BackColor = System.Drawing.Color.FromArgb(64, 64, 64);
this.lbName.CausesValidation = false;
this.lbName.ForeColor = System.Drawing.Color.Silver;
this.lbName.Location = new System.Drawing.Point(130, 136);
this.lbName.Name = "lbName";
this.lbName.Size = new System.Drawing.Size(479, 34);
this.lbName.TabIndex = 1;
this.lbName.Text = "Data Context Available for Edition";
this.lbName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
// 
// tbName
// 
this.tbName.BackColor = System.Drawing.Color.FromArgb(64, 64, 64);
this.tbName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.tbName.Font = new System.Drawing.Font("Microsoft Sans Serif", 20F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.tbName.ForeColor = System.Drawing.Color.Silver;
this.tbName.Location = new System.Drawing.Point(128, 134);
this.tbName.Name = "tbName";
this.tbName.Size = new System.Drawing.Size(498, 38);
this.tbName.TabIndex = 2;
this.tbName.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.tbName.Enter += new System.EventHandler(this.textBox2_Enter);
this.tbName.Leave += new System.EventHandler(this.tbName_Leave);