dllee

  點部落 :: Home :: Syndication :: 我的收藏 ::  :: Login
  文章數 - 104, 回應數 - 20, 引用數 - 0

每月文章

文章分類

前年用 C# 寫過九珠算盤,但這兩年來沒有再多作 C# 練習,連兩年前看一半的 Graphics Programming with GDI+ 又都還它了 語言就是這樣,一不說,就忘了如何說。

 

C#九珠算盤

在寫九珠算盤時,使用自定物件,由一串珠到一個算盤。Simple Paint Object 是取自九珠算盤內的自定物件之最精簡的物件,只要把要畫的東西,寫在 MyPaint 內即可,原始碼如下:


  1. public class SimplePaintObject : System.Windows.Forms.Panel  
  2. {  
  3.   public SimplePaintObject()  
  4.   {  
  5.     this.Paint += new PaintEventHandler(this.MyPaint);  
  6.     // DoubleBuffer 減少閃爍  
  7.     this.SetStyle(ControlStyles.AllPaintingInWmPaint  
  8.                   | ControlStyles.UserPaint  
  9.                   | ControlStyles.DoubleBuffer, true);  
  10.   }  
  11.   protected virtual void MyPaint(object sender, System.Windows.Forms.PaintEventArgs e)  
  12.   {  
  13.     // Obtain the Graphics object  
  14.     Graphics g = e.Graphics;  
  15.     // Set the smoothing mode of the surface  
  16.     g.SmoothingMode = SmoothingMode.AntiAlias;  
  17.     // Paint it  
  18.     Rectangle r = this.ClientRectangle;  
  19.     r.Height--;  
  20.     r.Width--;  
  21.     g.DrawRectangle(Pens.Blue, r);  
  22.   }  
  23. }  

在 MyPaint 中利用 Graphics 去作畫,可讓元件在被要求重繪時,自動叫用,這樣繪製的東西就不會因其他視窗蓋掉再移開而清除了。

最近,想寫一個注音練習的程式給兒子作練習,加強ㄥㄣ的辨別,將使用此 Simple Paint Object 作出繪製國字加注音的字,等有成果再貼圖來看看吧。


posted on 2008/4/29 01:25 | 我要推薦 | 閱讀數 : 266 | 文章分類 [ 程式語言.C# ] 訂閱

Feedback

目前沒有回應.

回應

標題:
姓名:
電子郵件:(將不會被顯示)
個人網頁:
內容: 

登入後使用進階評論
Please add 4 and 5 and type the answer here: