- '半形轉全形
- Public Function ToWchr(ByRef data As String) As String
- Dim sb As New StringBuilder
- Dim ascii As Integer = 0
-
- For Each c As Char In data.ToCharArray()
- ascii = Convert.ToInt32(c)
- If ascii = 32 Then
- sb.Append(Convert.ToChar(12288))
- Else
- sb.Append(Convert.ToChar(ascii + IIf(ascii <>
- End If
- Next
-
- Return sb.ToString
- End Function
-
- ' 全形 轉 半形
- Public Function ToNchr(ByRef data As String) As String
- Dim sb As New StringBuilder
- Dim ascii As Integer = 0
-
- For Each c As Char In data.Replace("〔", "[").Replace("〕", "]").Replace("'", "'").ToCharArray()
- ascii = Convert.ToInt32(c)
- If ascii = 12288 Then
- sb.Append(Convert.ToChar(32))
- Else
- If ascii > 65280 And ascii <>Then
- sb.Append(Convert.ToChar(ascii - 65248))
- Else
- sb.Append(Convert.ToChar(ascii))
- End If
- End If
- Next
-
- Return sb.ToString
- End Function
2009年9月28日 星期一
全形/半形 互換
2009年9月21日 星期一
Winform 設定輸入法
如何改變輸入法
//1.設定輸入法,依comboBox1選擇
InputLanguage MyInput = InputLanguage.InstalledInputLanguages[this.comboBox1.SelectedIndex];
//2.設定輸入法
InputLanguage.CurrentInputLanguage = MyInput; 完整程式碼 private void Form1_Load(object sender, EventArgs e)
{
//清除
this.listBox1.Items.Clear();
//1.收集系統已安裝的輸入法
InputLanguageCollection myInput = InputLanguage.InstalledInputLanguages;
//2.列舉輸入法
foreach (InputLanguage input in myInput)
{
//加入控制項
this.comboBox1.Items.Add(input.LayoutName);
}
//3.取得目前輸入法
InputLanguage CurrentInput = InputLanguage.CurrentInputLanguage;
listBox1.Items.Add("目前輸入法名稱為: " + "\t" + CurrentInput.LayoutName);
//4.取得輸入法區域
listBox1.Items.Add("目前輸入法文化特性為: " + "\t" + CurrentInput.Culture.DisplayName);
//5.取得預設的輸入法
InputLanguage DefaultInput = InputLanguage.DefaultInputLanguage;
listBox1.Items.Add("預設輸入法文化特性為: " + "\t" + DefaultInput.LayoutName);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//清除
this.listBox1.Items.Clear();
//1.設定輸入法,依comboBox1選擇
InputLanguage MyInput = InputLanguage.InstalledInputLanguages[this.comboBox1.SelectedIndex];
//2.設定輸入法
InputLanguage.CurrentInputLanguage = MyInput;
//3.取得目前輸入訊息
InputLanguage CurrentInput = InputLanguage.CurrentInputLanguage;
listBox1.Items.Add("目前輸入法名稱為: " + "\t" + CurrentInput.LayoutName);
//4.取得輸入法區域
listBox1.Items.Add("目前輸入法文化特性為: " + "\t" + CurrentInput.Culture.DisplayName);
//5.取得預設輸入法
InputLanguage DefaultInput = InputLanguage.DefaultInputLanguage;
listBox1.Items.Add("預設輸入法文化特性為: " + "\t" + DefaultInput.LayoutName);
}
2009年9月8日 星期二
C# Textbox Enable 時改變字體及背景顏色
//重寫OnEnabledChanged
protected override void OnEnabledChanged(EventArgs e)
{
if (Enabled==false){
SetStyle(ControlStyles.UserPaint,true);
}
else{
SetStyle(ControlStyles.UserPaint,false);
}
base.OnEnabledChanged(e);
}
//重寫OnPaint
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
if (Enabled==false){
pe.Graphics.FillRectangle(new SolidBrush(SystemColors.ControlLight),
pe.ClipRectangle);
//文字描畫
int x=0,y=0;
Size s = pe.Graphics.MeasureString(Text,Font).ToSize();
x=Width-s.Width;
y=(Height-s.Height)/2;
pe.Graphics.DrawString(this.Text, this.Font, Brushes.Black , x, y);
}
}
protected override void OnEnabledChanged(EventArgs e)
{
if (Enabled==false){
SetStyle(ControlStyles.UserPaint,true);
}
else{
SetStyle(ControlStyles.UserPaint,false);
}
base.OnEnabledChanged(e);
}
//重寫OnPaint
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
if (Enabled==false){
pe.Graphics.FillRectangle(new SolidBrush(SystemColors.ControlLight),
pe.ClipRectangle);
//文字描畫
int x=0,y=0;
Size s = pe.Graphics.MeasureString(Text,Font).ToSize();
x=Width-s.Width;
y=(Height-s.Height)/2;
pe.Graphics.DrawString(this.Text, this.Font, Brushes.Black , x, y);
}
}
2009年9月7日 星期一
How to find objects in Generics with List.Find() method
How to find objects in Generics with List.Find() method
I've been looking for help on how to find objects in Generics with List.Find() method .... and ... take a look what I have found.
In the follow example, I created a simple class:
public class Person
{
private int _id;
private string _name;
public int ID { get{ return _id;} set{ _id = value;}}
public int Name { get{ return _name;} set{ _name= value;}}
public Person(int id, string name)
{
_id = id;
_name = name;
}
}
In the example, there's a simple class with two private attributes. Now we're going to create a typed List of this object and take advantage of the Find() method
public void CreateAndSearchList()
{
//create and fill the collection
List myList = new List();
myList.Add(new Person(1, "AndreySanches"));
myList.Add(new Person(2, "AlexandreTarifa"));
myList.Add(new Person(3, "EmersonFacunte"));
//find a specific object
Person myLocatedObject = myList.Find(delegate(Person p) {return p.ID == 1; });
}
I've been looking for help on how to find objects in Generics with List.Find() method .... and ... take a look what I have found.
In the follow example, I created a simple class:
public class Person
{
private int _id;
private string _name;
public int ID { get{ return _id;} set{ _id = value;}}
public int Name { get{ return _name;} set{ _name= value;}}
public Person(int id, string name)
{
_id = id;
_name = name;
}
}
In the example, there's a simple class with two private attributes. Now we're going to create a typed List of this object and take advantage of the Find() method
public void CreateAndSearchList()
{
//create and fill the collection
List
myList.Add(new Person(1, "AndreySanches"));
myList.Add(new Person(2, "AlexandreTarifa"));
myList.Add(new Person(3, "EmersonFacunte"));
//find a specific object
Person myLocatedObject = myList.Find(delegate(Person p) {return p.ID == 1; });
}
訂閱:
意見 (Atom)