Marca d agua em textbox CSharp

07/09/2015

0

SQL

há um jeito mais facil de adicionar marca d'agua em text box?
Ps.: Está funcionando bem

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UserWindow
{
    public partial class frmLogin : Form
    {
        public frmLogin()
        {
            InitializeComponent();
            //------------------------------------------------design marca d'agua
            txtUsuario.ForeColor = SystemColors.GrayText;
            txtUsuario.Text = "Digite seu nome de usuário";
            this.txtUsuario.Leave += new System.EventHandler(this.txtUsuario_Leave);
            this.txtUsuario.Enter += new System.EventHandler(this.txtUsuario_Enter);
            //------------------------------------------------design marca d'agua
            txtSenha.ForeColor = SystemColors.GrayText;
            txtSenha.Text = "Digite sua senha (6 a 12 caracteres)";
            this.txtSenha.Leave += new System.EventHandler(this.txtSenha_Leave);
            this.txtSenha.Enter += new System.EventHandler(this.txtSenha_Enter);
            txtSenha.UseSystemPasswordChar = false;
        }

        private void txtUsuario_Leave(object sender, EventArgs e)
        {
            //------------------------------------------------design marca d'agua

            if (txtUsuario.Text.Length == 0)
            {
                txtUsuario.Text = "Digite seu nome de usuário";
                txtUsuario.ForeColor = SystemColors.GrayText;
            }
    
        }

        private void txtUsuario_Enter(object sender, EventArgs e)
        {
            //------------------------------------------------design marca d'agua
            if (txtUsuario.Text == "Digite seu nome de usuário")
            {
                txtUsuario.Text = "";
                txtUsuario.ForeColor = SystemColors.WindowText;
            }
        }

        private void txtSenha_Leave(object sender, EventArgs e)
        {
            //------------------------------------------------design marca d'agua
            if (txtSenha.Text.Length == 0)
            {
                txtSenha.Text = "Digite sua senha (6 a 12 caracteres)";
                txtSenha.ForeColor = SystemColors.GrayText;
                txtSenha.UseSystemPasswordChar = false;
            }
        }

        private void txtSenha_Enter(object sender, EventArgs e)
        {
            //------------------------------------------------design marca d'agua
            if (txtSenha.Text == "Digite sua senha (6 a 12 caracteres)")
            {
                txtSenha.Text = "";
                txtSenha.ForeColor = SystemColors.WindowText;

                txtSenha.UseSystemPasswordChar = true;
            }
        }

        private void btnEntrar_Click(object sender, EventArgs e)
        {
            if (txtUsuario.Text != "Adm" || txtSenha.Text != "123asd")
            {
                //------------------------------------se diferente, aparece mensagem de erro
                MessageBox.Show("Nome de usuário e/ou senha estão incorretos", "Mensagem de erro",
                MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
            else
            {

            }
        }

        private void btnCancelar_Click(object sender, EventArgs e)
        {
            txtUsuario.Text = "";
            txtSenha.Text = "";

            //------------------------------------------------design marca d'agua

            if (txtUsuario.Text.Length == 0)
            {
                txtUsuario.Text = "Digite seu nome de usuário";
                txtUsuario.ForeColor = SystemColors.GrayText;
            }
            //------------------------------------------------design marca d'agua
            //-----------------------------------------------limpa as textBox
            if (txtSenha.Text.Length == 0)
            {
                txtSenha.Text = "Digite sua senha (6 a 12 caracteres)";
                txtSenha.ForeColor = SystemColors.GrayText;
                txtSenha.UseSystemPasswordChar = false;
            }
        }
    }
}
Juan Takara

Juan Takara

Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar