1

我想将普通工具箱按钮添加到我的 Windows 窗体应用程序中,它会覆盖窗体的 onpaint 方法以将窗体的形状更改为椭圆形。当我在加载事件中添加创建新按钮的代码时,根本没有可见的效果,我看不到任何按钮。

请帮助我如何使用图形和普通控件。

我在这里粘贴代码

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