C# Dicas

Criptografar senha

public static class Seguranca
{
public static string CripitografaSenhaHASH(this string Senha)
{

Mais >

Procurar serviço no Windows

//função que retorna se o serviço existe no windows ou nao
        public string findService(string s)
        {

            string s3 = null;
            try
            {

                ServiceController[] services;
                services = ServiceController.GetServices();
                for (int i = 0; i < services.Length; i++)
                {
                    if (services[i].ServiceName == s)
                    {

                        s3 = "Found";
                        break;
                    }

                }

            }
            catch (Exception x) { }
            if (s3 == null)
                return s3 = "Not Found";
            else
                return s3;
        }

Mais >

Limpar todos os TextBox de uma vez

private void limparControles()
      {
          foreach (Control cItem in this.Controls)
          {
              //A group box is found
              if (cItem is GroupBox)
              {
                  //Loop through all the group box components
                  foreach (Control cSubItem in cItem.Controls)
                  {
                      if (cSubItem is GroupBox)
                      {
                          foreach (Control cSubItem3 in cSubItem.Controls)
                          {
                              if (cSubItem3 is TextBox || cSubItem3 is MaskedTextBox)
                              {
                                  cSubItem3.Text = "";
                              }
                          }
                      }
                      else
                      {
                          //If its a label of text box disable it
                          if (cSubItem is TextBox || cSubItem is MaskedTextBox)
                          {
                              cSubItem.Text = "";
                          }
                      }
                  }
              }
          }
      }

Mais >

Retornar IP de Host com C#

private String pegaIP(string hostName)
        {
            String s = "";
            IPAddress[] addressList = Dns.GetHostByName(hostName).AddressList;
            for (int i = 0; i < addressList.Length; i++)
                s += addressList[i].ToString() + "\n";

            return s;
        }

Mais >