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

Draw Freedraw line & rubber band line
http://dis.dankook.ac.kr/lectures/hci10/entry/Rubber-band-line-drawing

Draw shapes
http://dis.dankook.ac.kr/lectures/hci10/entry/Draw-Shape

DrawImageObjects
http://dis.dankook.ac.kr/lectures/hci10/entry/DrawImageObjects

Valid double number in C#

텍스트 박스에 “12.5”, “.3”, “-12” 등과 같은 양수/음수의 double 숫자만 입력받을 수 있도록 하려면
(그외에 “abcd”같은 문자나 “12.3.4” 같은 이상한 숫자는 입력받을 수 없도록하기위해)

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
// accept only digit(0-9) with ‘.’ (dot) and ‘-‘ (minus)
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != ‘.’ && e.KeyChar != ‘-‘)
e.Handled = true;
// accept only one decimal point (.32)
if (e.KeyChar == ‘.’ && (sender as TextBox).Text.IndexOf(‘.’) > -1)
e.Handled = true;
// accept only minus sign at the beginning
if (e.KeyChar == ‘-‘ && (sender as TextBox).Text.Length > 0)
e.Handled = true;
}

How to: Sort ListView Items

How to: Sort ListView Items
http://msdn.microsoft.com/en-us/library/ms229643(VS.80).aspx

class ListViewItemComparer : IComparer
{
private int column;
public ListViewItemComparer() : this(0) {}
public ListViewItemComparer(int column)
{
this.column = column;
}

public int Compare(object x, object y) // string compare
{
return String.Compare(((ListViewItem)x).SubItems[column].Text,
((ListViewItem)y).SubItems[column].Text);
}
}

/////
public partial class Form1 : Form
{
[…]
private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
{

// Set the column number that is to be sorted; default to ascending.
this.listView1.ListViewItemSorter = new ListViewItemComparer(e.Column);

// Perform the sort with these new sort options.
this.listView1.Sort();
}
}

Generic List Class Sort Method

public void Sort(Comparison<T> comparison)
http://msdn.microsoft.com/en-us/library/w56d4y5z.aspx

List<Person> pList = new List<Person>();
pList.Sort(ComparePersonByID); // pList를 ID로 정렬하기

[…]
public class Person : IComparable<Person>
{
public static Comparison<Person> ComparePersonByID =
delegate(Person p1, Person p2)
{
return p1.ID.CompareTo(p2.ID);
};

[…]
}

pList.Sort(ComparePersonByID); // pList를 ID로 정렬하기 (Comparison delegate)

public class Person : IComparable<Person>
{
public static Comparison<Person> ComparePersonByID =
delegate(Person p1, Person p2)
{
return p1.ID.CompareTo(p2.ID);
};

[…]
}

pList.Sort(new PersonIDComparer()); // pList를 ID로 정렬하기 (IComparer)

public class PersonIDComparer : IComparer<Person>
{
public int Compare(Person p1, Person p2)
{
return p1.ID.CompareTo(p2.ID);
}
}

pList.Sort((p, q) => p.ID.CompareTo(q.ID)); // pList를 ID로 정렬하기 (lambda)