Codigos Fonte, Artigos e Dicas
Arquivo de junho 2009
Mudar cor de linha de List Box
25/06/09
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
Mudar cor da linhas em Data Grid View
25/06/09
private void dataGridView1_CellFormatting(object sender,DataGridViewCellFormattingEventArgs e)
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.White;
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
}
Concatenar String de preço (simples)
24/06/09
private String concatenarPreco(String preco)
{
String pr = preco;
if (pr.Length == 1 || pr.Length == 2)
{
pr += ",00";
}
else
if (pr.Length == 3)
{
pr += "0";
}
Criptografar senha
23/06/09
public static class Seguranca
{
public static string CripitografaSenhaHASH(this string Senha)
{
Procurar serviço no Windows
23/06/09
//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;
}
Limpar todos os TextBox de uma vez
22/06/09
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 = "";
}
}
}
}
}
}
Criar XML com Subsonic
22/06/09
private DataSet gravarXML(string arq)
{
DataSet ds = new SubSonic.Select("nome", "qnt", "data_v").From("clientes").InnerJoin("vendas", "idcliente", "clientes", "idclientes").WhereExpression("data_v").IsBetweenAnd(data1, data2).OrderAsc("data_v").ExecuteDataSet();
ds.WriteXml(arq, XmlWriteMode.WriteSchema);
return ds;
}
Postar codigo fonte C, C#, Java e etc no Blogspot tutorial Definitivo
22/06/09
Bom hoje estava procurando um tutorial em portugues de como postar codigo fonte em c# no blogspot… so encontrei em ingles… agora vou fazer minha versão do tal tutorial…
Retornar IP de Host com C#
22/06/09
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;
}