header
CodePanic! > C#.NET Tips > 今ここ

■四角形を描画する

PictureBoxに四角形を描画する例です。
gra_rect.jpg(14564 byte)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        System.Diagnostics.PerformanceCounter pc = new System.Diagnostics.PerformanceCounter();

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            using (Graphics gra = pictureBox1.CreateGraphics())
            {
                // 四角形
                gra.DrawRectangle(Pens.Black, 0, 0, 30, 30);

                // 中が塗りつぶされた四角形
                gra.FillRectangle(Brushes.Blue, 40, 0, 50, 50);
            }
        }
    }
}





zFCodePress C#vO~OTips


Copyright © 2008.07 - shougo suzaki
ゥRN\Agbvy[WB