PersonListViewXMLSerializer (계층적인 XML 구성예)
Category Archives: C# Programming
XMLElement & XMLAttribute
XML Element
http://dis.dankook.ac.kr/lectures/hci11/entry/XMLElement
XML Attribute
http://dis.dankook.ac.kr/lectures/hci11/entry/XMLAttribute
XML Element & Attribute
http://dis.dankook.ac.kr/lectures/hci11/entry/XMLElement-Attribute
XML Serialization Tutorial
XML Serialization Tutorial
http://www.diranieh.com/NETSerialization/XMLSerialization.htm
Serialization
Person Serialization (Using BinaryFormatter or SoapFormatter)
http://dis.dankook.ac.kr/lectures/hci09/entry/Simple-Serialization
Person XML Serialization (Using XML Serializer or Soap XML Serializer)
http://dis.dankook.ac.kr/lectures/hci09/entry/XML-Serialization
Person Using ISerialable Interface
http://dis.dankook.ac.kr/lectures/hci09/entry/ISerialable
PersonList Serialization (Using BinaryFormatter or SoapFormatter)
http://dis.dankook.ac.kr/lectures/hci09/entry/PersonList-Serialization
Draw Shape To Bitmap in Memory
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
// Create a Bitmap image in memory and set its CompositingMode
Bitmap bmp = new Bitmap(this.Size.Width, this.Size.Height,
PixelFormat.Format32bppArgb);
Graphics gBmp = Graphics.FromImage(bmp);
gBmp.CompositingMode = CompositingMode.SourceCopy;
// Pen으로 대각선과 사각형 그리기 (to bitmap in memory)
Pen p = new Pen(Color.Black, 3);
Rectangle r = new Rectangle(10, 10, this.Size.Width/2, this.Size.Height/2);
gBmp.DrawLine(p, 10, 10, this.Size.Width / 2 + 10, this.Size.Height / 2 + 10);
gBmp.DrawLine(p, this.Size.Width / 2 + 10, 10, 10, this.Size.Height / 2 + 10);
gBmp.DrawRectangle(p, r);
// Brush로 파란사각형 그리기 (to bitmap in memory)
Brush b = new SolidBrush(Color.Blue);
Rectangle r2 = new Rectangle(this.Size.Width / 2 + 10, this.Size.Height / 2 + 10,
this.Size.Width / 2 – 10, this.Size.Height / 2 – 10);
gBmp.FillRectangle(b, r2);
// Brush로 빨간삼각형 그리기 (to bitmap in memory)
Brush b2 = new SolidBrush(Color.Red);
Point[] pt = new Point[3];
pt[0].X = 400; pt[0].Y = 10;
pt[1].X = 300; pt[1].Y = 210;
pt[2].X = 500; pt[2].Y = 210;
gBmp.FillPolygon(b2, pt);
// HatchBrush로 타원 그리기 (to bitmap in memory)
HatchBrush hb = new HatchBrush(HatchStyle.DiagonalCross,
Color.Yellow, Color.Brown);
gBmp.FillEllipse(hb, 10, 220, 200, 100);
// DrawArc 메소드 사용하여 호 그리기 (to bitmap in memory)
Pen p2 = new Pen(Color.Green, 3);
Rectangle r3 = new Rectangle(220, 220, 200, 100);
gBmp.DrawArc(p2, r3, 0, 180);
// draw the bitmap on our window
g.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height);
bmp.Dispose();
gBmp.Dispose();
}
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” 같은 이상한 숫자는 입력받을 수 없도록하기위해)
다음과 같은 Regex 구문을 사용한다.
{
if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), @”^[0-9]*(?:\.[0-9]*)?$”))
e.Handled = true;
}
문자의 입력을 막고, 숫자와 .과 백스페이스키를 입력받을 수 있게 하는 코드
{
if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), @”^[0-9]*(?:\.[0-9]*)?$”))
e.Handled = 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 반환
});
}
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);
};
[…]
}
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();
}
}