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
Monthly Archives: November 2012
lecture12
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
lecture11
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;
        }
Final Extra 10%
기말고사
담당교수: 단국대학교 멀티미디어공학전공 박경신
 
* 전체폴더를 HCI12-FinalExtra-<학번>-<이름>으로 바꾸고, zip을 한 후 e-learning에 제출한다. (11월30일까지)
 5520485258.doc
1. 건조지수(Aridity Index)를 구하고, 기후의 상태를 알려주는 프로그램을 작성한다. (기말고사 Extra 10%)
 
(1) 사용자에게 연강수량(Precipitation)과 연평균기온(Temperature)를 입력 받는다. 연강수량의 단위는 mm이고, 연평균기온의 단위는 oC이다.
 
(2) 건조지수를 다음 공식으로 계산하고 결과를 화면에 출력한다.
 건조지수 AI = Precipitation/ (Temperature + 10)
(3) 다음 기준에 따라 기후의 상태를 판단해서 화면에 출력한다.
AI >= 60 => Perhumid
30 <= AI < 60 => Humid
20 <= AI < 30 => SubHumid
15 <= AI < 20 => SemiArid
5 <= AI < 15 => Arid
AI < 5 => ExtremelyArid
 
ReadRssFeed
       public static List<RssFeedItem> ReadRssFeed(string url)
        {
            //create a new list of the rss feed items to return
            List<RssFeedItem> rssFeedItems = new List<RssFeedItem>();
            //create an http request which will be used to retrieve the rss feed
            HttpWebRequest rssFeed = (HttpWebRequest)WebRequest.Create(url);
            rssFeed.Timeout = 200000;
            //use a dataset to retrieve the rss feed
            using (DataSet rssData = new DataSet())
            {
                //read the xml from the stream of the web request
                rssData.ReadXml(rssFeed.GetResponse().GetResponseStream());
                //loop through the rss items in the dataset and populate the list of rss feed items
                foreach (DataRow dataRow in rssData.Tables[“item”].Rows)
                {
                    rssFeedItems.Add(new RssFeedItem
                    {
                        Title = Convert.ToString(dataRow[“title”]),
                        PublishDate = Convert.ToDateTime(dataRow[“pubDate”]),
                        Description = Convert.ToString(dataRow[“description”]),
                        Link = Convert.ToString(dataRow[“link”])
                    });
                }
            }
            //return the rss feed items
            return rssFeedItems;
        }
HW4
연습문제 (4)
□ 단원 : C# WinForm
□ 목표 : 상속 & Collections & FileIO & Controls & GDI+ & Dialog & XML
□ 주요 연습 내용 : RSS Feed, Listview, PictureBox, Paint, Print
□ 준비자료 : QuakeData.cs, 실시간 지진데이터 사이트, Resources 아이콘과 이미지http://earthquake.usgs.gov/earthquakes/shakemap/rss.xml
Sample xml file:2513662341.xml2300498696.cs5556590159.hwp
[연습문제] Ex4 (Due by 12/07 금 24시까지) 
-cyber 강의실 (cyber.dku.edu)로 source code, executable file, solution/project VC# file, 보고서를 학번_이름_Ex4.zip으로 묶어서 낼 것. 보고서 (30%)
[연습문제]
1. Form1.cs (메인 폼)에 각종 컨트롤을 추가한다. (10%)
2. Form2.cs (지도 폼)에 각종 컨트롤을 추가한다. (10%)
3. Form1.cs에 이벤트 핸들러 & RssQuakeDataManager.cs (20%)
– 메인폼이 로드될때 초기화
– 종료 버튼 클릭시 프로그램 종료
– RssFeed 버튼 클릭시 새로운 RssFeed 시작
– Mapview 버튼 클릭시 Form2 실행
– 콤보박스 아이템 선택시 리스트뷰의 뷰를 변동
– 리스트뷰에서 아이템 선택시 웹사이트 실행
– image는 XML 파일을 파싱해서 <description>안에 
http://earthquake.usgs.gov/eqcenter/shakemap/thumbs/shakemap_global_c000dzlx.jpg
웹사이트에서부터 이미지를 로딩함!!
4. Form2.cs에 이벤트 핸들러 (10%)
– 지도뷰폼이 로드될 때 초기화
– 지도뷰폼이 Resize될 때 다시그리기
– 픽쳐박스 그리기
– 프린트 출력
5. Form1.cs의 listView1 정렬 & ListViewItemComparer.cs & RssQuakeDataManager.cs (10점)
– 리스트뷰 칼럼 클릭시 칼럼명으로 정렬
6. Form1.cs의 파일입출력 & RssQuakeDataManager.cs (10점)
– 텍스트파일 읽기
– 텍스트파일 저장
7. 본인이 원하는 기능을 더 추가하고, 결과를 모두 출력해서 넣는다.


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 반환
    });
}
 DrawShapeToBitmapInMemory.zip