Number only input textbox

// number only textbox using TryParse
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    int value = 0;
    e.Handled = !int.TryParse(e.KeyChar.ToString(), out value);
}

// number only textbox using Regex.IsMatch
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
    if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), “\\d+”))
        e.Handled = true;
}

C# operator== vs. Equals

http://msdn.microsoft.com/en-us/library/ms173147.aspx

// Operator Overloading
if (x == y) { // 컴파일시 x와 y가 동일한지 확인

// 참조형일 경우
object x = “hello”;
object y = ‘h’ + “ello”;     // ensure it’s a different reference
if (x == y) { // 결과 => FALSE
if (x.Equals(y)) { // 결과 => TRUE

// string 형(참조형이긴 하지만)일 경우 
// Equals와  equality operators (== and !=) 을 구현하여 string 객체의 값이 동일한지 확인
string x1 = “hello”;
string y1 = ‘h’ + “ello”;     // ensure it’s a different reference
if (x1 == y1) { // 결과 => TRUE
if (x1.Equals(y1)) { // 결과 => TRUE

IEquatable.Equals

http://msdn.microsoft.com/ko-kr/library/ms131190(VS.95).aspx

// Person 클래스
public class Person : IEquatable<Person>
{
   // …
    public Person(string name, int age)
     {
         _name = name;
         _age = age;
     }

     public override string ToString()
     {
         return string.Format(“이름 : {0}\t나이 : {1}”, _name, _age);
     }

    // needed for ==
    public static bool operator == (Person p, Person q)
    {
         return p.Equals(q);
    }

    public static bool operator != (Person p, Person q)
    {
        return !p.Equals(q);
    }

    public override int GetHashCode()
    {
        return base.GetHashCode();
    }

    public override bool Equals(object obj)
    {
        return Equals((Person)obj);
    }

    public bool Equals(Person other)
    {
        if (object.ReferenceEquals(this, other))
            return true;
        return (Name==other.Name) && (Age==other.Age);
    }
}


// aList에 포함된 세 사람 중에 둘리와 일치하는 사람이 있는지 확인한다
private static void Main(string[] args)
{
    List<Person> aList = new List<Person>();
    aList.Add(new Person(“둘리”, 1000));
    aList.Add(new Person(“희동이”, 3));
    aList.Add(new Person(“고길동”, 40));

    Person s = new Person(“둘리”, 1000);
    bool result = false;
    foreach (Person p in aList)
    {
         if (p == s)
         {
             result = true;
             break;
         }
     }

    // 또는 foreach를 사용하는 방법대신, List에 Find 또는 FindIndex를 사용한다.
    Person f = aList.Find(delegate(Person o)
    {
        return o == s; // 리스트에 o가 s와 일치하는 것이 있으면 그 Person 반환
    }
);

    int index = aList.FindIndex(delegate(Person o)
    {
        return o == s; // 리스트에 o가 s와 일치하는 것이 있으면 그 index 반환
    }
);

}

GDI+

GDI+ A Higher Level API
http://www.csharphelp.com/archives3/files/archive593/GDI.pdf

Pen
http://dis.dankook.ac.kr/lectures/hci09/entry/Pen

Brush
http://dis.dankook.ac.kr/lectures/hci09/entry/Brush

Image
http://dis.dankook.ac.kr/lectures/hci09/entry/DrawImage

ImageAttribute
http://dis.dankook.ac.kr/lectures/hci09/entry/ImageAttributes

ImageTransform
http://dis.dankook.ac.kr/lectures/hci09/entry/DrawImageTransform

DoubleBuffering
http://dis.dankook.ac.kr/lectures/hci09/entry/DoubleBuffering

Graphic Path
http://dis.dankook.ac.kr/lectures/hci09/entry/PathScribble