1

通常のツールボックス ボタンを Windows フォーム アプリケーションに追加して、フォームの onpaint メソッドをオーバーライドしてフォームの形状を楕円形に変更したいと考えています。load イベントに新しいボタンを作成するコードを追加すると、目に見える効果はまったくなく、ボタンが表示されません。

通常のコントロールと一緒にグラフィックを使用する方法を教えてください。

私はここにコードを貼り付けています

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

namespace gadget2
{
    public partial class Form1 : Form
    {
        Button[] b = new Button[3];
        GraphicsPath shape = new GraphicsPath();
        public Form1()
        {
            InitializeComponent();
        }
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        { 
            shape.AddEllipse(50, 50, 200, 200);
            this.Region = new System.Drawing.Region(shape);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 3; i++)
            {
                b[i] = new Button();
                b[i].AutoSize = false;
                b[i].Width = 100;
                b[i].Height = 100;
                b[i].Location = new Point(255, 70 + i * 30);
                this.Controls.Add(b[i]);
                b[i].Show();
                b[i].BackColor = Color.Black;
                b[i].BringToFront();
            }  
        }

    private void button1_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Mayank");
    }

    private void button2_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Mayank");
    }

    private void button3_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Mayank");
    }
}

}

4

0 に答える 0