Muito bom poder viajar e renovar a mente. Peço a todos PAREM. Isso vai mudar suas vidas.
10/20/2008
7/01/2008
TextBox só de Inteiros no .NET CF
Olá desenvolvedores .NET
Se você quer um TextBox só de inteiros e com CharacterCasing (que não há no .NET CF) apenas crie esta classe no seu projeto e arraste-o para o formulário.
Segue a classe. Existem mais 2 proprieades no componente:
OnlyNumbers
UpperCasing
Sete-os ao seu gosto e bom trabalho.
--
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
namespace DeviceApplication3
{
public class TextBoxEx : TextBox
{
bool upper;
bool only_numbers;
private const int GWL_STYLE = (-16);
private const int IM_UPPERCASE = 0x0008;
private const int IM_LOWERCASE = 0x0010;
private const int IM_NUMBER = 0x2000;
IntPtr hwnd;
public bool OnlyNumbers
{
get { return only_numbers; }
set { only_numbers = value; }
}
OnlyNumbers
public bool UpperCasing
{
get { return upper; }
set { upper = value; }
}
public void setarInteiros(){
}
public void validarCaracIntRegex(KeyPressEventArgs e)
{
}
[DllImport("coredll.dll")]
private extern static int SetWindowLong(IntPtr Hwnd, int Index, int NewIndex);
[DllImport("coredll.dll")]
private extern static int GetWindowLong(IntPtr Hwnd, int Index);
[DllImport("coredll.dll")]
private extern static IntPtr GetCapture();
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (OnlyNumbers) // Só numeros
{
this.Capture = true;
hwnd = GetCapture();
this.Capture = false;
int previousStyle = GetWindowLong(hwnd, GWL_STYLE);
SetWindowLong(hwnd, GWL_STYLE, previousStyle | IM_NUMBER);
}
else // Só maiúsculas
{
if (UpperCasing)
{
if (Char.IsLetter(e.KeyChar))
{
// save the current caret position
int pos = this.SelectionStart;
// insert the upper case character
this.Text = this.Text.Insert(this.SelectionStart,
Char.ToUpper(e.KeyChar).ToString());
// and update the current caret position
this.SelectionStart = pos + 1;
e.Handled = true;
}
base.OnKeyPress(e);
}
}
}
}
}
Se você quer um TextBox só de inteiros e com CharacterCasing (que não há no .NET CF) apenas crie esta classe no seu projeto e arraste-o para o formulário.
Segue a classe. Existem mais 2 proprieades no componente:
OnlyNumbers
UpperCasing
Sete-os ao seu gosto e bom trabalho.
--
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
namespace DeviceApplication3
{
public class TextBoxEx : TextBox
{
bool upper;
bool only_numbers;
private const int GWL_STYLE = (-16);
private const int IM_UPPERCASE = 0x0008;
private const int IM_LOWERCASE = 0x0010;
private const int IM_NUMBER = 0x2000;
IntPtr hwnd;
public bool OnlyNumbers
{
get { return only_numbers; }
set { only_numbers = value; }
}
OnlyNumbers
public bool UpperCasing
{
get { return upper; }
set { upper = value; }
}
public void setarInteiros(){
}
public void validarCaracIntRegex(KeyPressEventArgs e)
{
}
[DllImport("coredll.dll")]
private extern static int SetWindowLong(IntPtr Hwnd, int Index, int NewIndex);
[DllImport("coredll.dll")]
private extern static int GetWindowLong(IntPtr Hwnd, int Index);
[DllImport("coredll.dll")]
private extern static IntPtr GetCapture();
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (OnlyNumbers) // Só numeros
{
this.Capture = true;
hwnd = GetCapture();
this.Capture = false;
int previousStyle = GetWindowLong(hwnd, GWL_STYLE);
SetWindowLong(hwnd, GWL_STYLE, previousStyle | IM_NUMBER);
}
else // Só maiúsculas
{
if (UpperCasing)
{
if (Char.IsLetter(e.KeyChar))
{
// save the current caret position
int pos = this.SelectionStart;
// insert the upper case character
this.Text = this.Text.Insert(this.SelectionStart,
Char.ToUpper(e.KeyChar).ToString());
// and update the current caret position
this.SelectionStart = pos + 1;
e.Handled = true;
}
base.OnKeyPress(e);
}
}
}
}
}
4/19/2008
O lado bom do caso Isabella

Estou aqui de volta depois de um longo tempo. Me sinto forçado a escrever sobre o caso Isabella Nardoni, que drasticamente morreu e ao que tudo indica pelas mãos de seus responsáveis.
Mas sempre prefiro olhar as coisas pelo lado bom e encontrei um lado bom neste caso. Na verdade fui forçado a encontrar. Mostrarei o porque a seguir.
Depois de tudo isso que aconteceu e do que virá com certeza estou certo de uma coisa. Hoje estamos mais carinhosos com nossos filhos, principalmente com os pequeninos. Hoje estamos dando muito mais valor às vidas de nossas crianças. Levamo-nas mais ao parque e damos mais beijos de bom dia e boa noite nelas.

Quem tem filha pequena, principalmente próxima à idade de Isabella sente muito com o caso. Luta ainda mais pela saúde e integridade dessas meninas. Hoje os pais pensam no trabalho muito mais em suas filhinas, em seus anjinhos. Lutam muito mais para que não aconteça tragédias com suas filhas e tentam educá-las para que não se tornem monstros como os que cometeram tal barbare.
Mas voltando ao lado bom de tudo de ruim que aconteceu. Hoje O valor de um aniversário é muito mais lembrado pois houveram crianças que não puderam se quer comer o bolo do seu aniversário por terem sidos mortos brutalmente bem próximo deste lindo dia. Hoje o sentimento de repúdio à dignidade humana está mais acirrado. Hoje a cidadania está exarcebada e o clamor por justiça mais consolidado.
Hoje não aceitamos a violência com mais tranquilidade. Hoje voltamos algumas décadas atrás e nos revoltamos com o que é simplesmente errado. Hoje somos muito menos maus, bem menos maus. Que não precisamos mais de crimes assim e que Isabella seja nosso último caso de barbare entre pais e filhos.
Filha, teu pai nunca vai de machucar.
Ezequias
1/26/2008
Contar Linhas de Código C# no Windows Forms
Cansado de procurar onde ver quantas linhas de código tinha meu projeto resolvi contar na marra mesmo.
Se alguém souber como habilitar a contagem de linhas de código de um projeto por favor me digam.
Segue o código abaixo:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using Microsoft.Build.Tasks;
using Microsoft.Build.Framework;
namespace ContarLinhasCodigo
{
public partial class Form1 : Form
{
string DiretorioRaiz = "C:/Codigo Fonte";
public Form1()
{
InitializeComponent();
DirectoryInfo dir = new DirectoryInfo(DiretorioRaiz);
IEnumerator arquivos = null;
try
{
arquivos = dir.GetFiles("*.cs", SearchOption.AllDirectories).GetEnumerator();
}
catch (DirectoryNotFoundException)
{
lbTotalLinhas.Text = "Diretório não encontrado";
return;
}
object arquivo;
long totLinhas = 0;
int linhasArquivo = 0;
TextReader tr = null;
while (arquivos.MoveNext())
{
arquivo = arquivos.Current;
if ((arquivo as FileSystemInfo).Name.Contains("Designer"))
continue;
#region Contar Linha do arquivo
tr = new StreamReader((arquivo as FileSystemInfo).FullName);
while (tr.ReadLine() != null)
{
linhasArquivo++;
totLinhas++;
}
Console.WriteLine((arquivo as FileSystemInfo).Name + ":" + linhasArquivo);
linhasArquivo = 0;
#endregion
}
Console.WriteLine("Total de Linhas do Projeto: " + totLinhas);
Text = "Total de Linhas de: " + DiretorioRaiz;
lbTotalLinhas.Text = totLinhas.ToString();
}
}
}
Ezequias
Se alguém souber como habilitar a contagem de linhas de código de um projeto por favor me digam.
Segue o código abaixo:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using Microsoft.Build.Tasks;
using Microsoft.Build.Framework;
namespace ContarLinhasCodigo
{
public partial class Form1 : Form
{
string DiretorioRaiz = "C:/Codigo Fonte";
public Form1()
{
InitializeComponent();
DirectoryInfo dir = new DirectoryInfo(DiretorioRaiz);
IEnumerator arquivos = null;
try
{
arquivos = dir.GetFiles("*.cs", SearchOption.AllDirectories).GetEnumerator();
}
catch (DirectoryNotFoundException)
{
lbTotalLinhas.Text = "Diretório não encontrado";
return;
}
object arquivo;
long totLinhas = 0;
int linhasArquivo = 0;
TextReader tr = null;
while (arquivos.MoveNext())
{
arquivo = arquivos.Current;
if ((arquivo as FileSystemInfo).Name.Contains("Designer"))
continue;
#region Contar Linha do arquivo
tr = new StreamReader((arquivo as FileSystemInfo).FullName);
while (tr.ReadLine() != null)
{
linhasArquivo++;
totLinhas++;
}
Console.WriteLine((arquivo as FileSystemInfo).Name + ":" + linhasArquivo);
linhasArquivo = 0;
#endregion
}
Console.WriteLine("Total de Linhas do Projeto: " + totLinhas);
Text = "Total de Linhas de: " + DiretorioRaiz;
lbTotalLinhas.Text = totLinhas.ToString();
}
}
}
Ezequias
Assinar:
Postagens (Atom)