星期四, 6月 04, 2015

[C#] 在 Paint 事件內繪圖

最近閱讀一些繪圖相關的論壇討論,大神都建議要在 Paint 事件內進行繪圖動作,測試了解為甚麼
namespace WindowsFormsApplication1
{
    public partial class frmWhyPaint : Form
    {
        public frmWhyPaint()
        {
            InitializeComponent();
        }

        private void btnCreatePie_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            g.FillPie(Brushes.Blue, 300, 100, 100, 100, 0, 360); 
        }

        private void frmWhyPaint_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.FillPie(Brushes.Red, 100, 100, 100, 100, 0, 360);
        }
    }
}

開始程式後利用 Button 產生右邊的藍圓

[C#] 在 Paint 事件內繪圖-1

把視窗最小化後,再放大,利用 Button 建立的藍圓,消失了

[C#] 在 Paint 事件內繪圖-2

拉視窗下緣,把兩個圓切一半

[C#] 在 Paint 事件內繪圖-3

再把視窗還原,發現到 Button 產生的藍圓,只剩下一半囉

[C#] 在 Paint 事件內繪圖-4

沒有留言:

張貼留言