我设立了三种事件                      switch (this.iFlag)
              {
                case 1: g.FillEllipse(MyBrush, this.button1.ClientRectangle);
                    break;
                case 2: g.FillEllipse(MyBrush, (this.button1.Width - this.button1.Height)
                     / 2, 0, this.button1.Height, this.button1.Height);
                    break;
                case 3: g.FillPie(MyBrush, 0, 0, this.button1.Width, this.button1.Height,
                     60, 240);
                    break;
               }
          
用三个button来选择,但是当定义iFlag时
                        private System.Int32 iFlag = 2;iFlag =()  只能选择一种事件,这样一来form上的三个button来选择就不起作用了,我应该如何定义iFlag才能避免这个问题呢?

解决方案 »

  1.   

    在Button1_Click里面写
    iFlag = 1;
    然后再调用上面的代码。其余类似。
      

  2.   

           private void button3_Click(object sender, System.EventArgs e)
            {
                this.iFlag = 1;
                this.button2.Refresh();        }        private void button4_Click(object sender, System.EventArgs e)
            {
                this.iFlag = 2;
                this.button2.Refresh();        }        private void button5_Click(object sender, System.EventArgs e)
            {
                this.iFlag = 3;
                this.button2.Refresh();        }
    我都定义过了,但它最后只默认  “private System.Int32 iFlag = 2;” 我填写的值
      

  3.   

          private void button3_Click(object sender, System.EventArgs e) 
            { 
                this.iFlag = 1; 
                this.button3.Refresh();         }         private void button4_Click(object sender, System.EventArgs e) 
            { 
                this.iFlag = 2; 
                this.button4.Refresh();         }         private void button5_Click(object sender, System.EventArgs e) 
            { 
                this.iFlag = 3; 
                this.button5.Refresh();         } 
      

  4.   

    还是不好使!
    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;namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
            {
                if (this.StrFileName.Trim() == "")
                    return;
                System.Drawing.Bitmap MyBitmap = new Bitmap(this.StrFileName);
                Graphics g = e.Graphics;
                TextureBrush MyBrush = new TextureBrush(MyBitmap);
                switch (this.iFlag)
                {
                    case 1: 
                        g.FillEllipse(MyBrush, this.button1.ClientRectangle);
                        break;
                    case 2: 
                        g.FillEllipse(MyBrush, (this.button1.Width - this.button1.Height)
                         / 2, 0, this.button1.Height, this.button1.Height);
                        break;
                    case 3: 
                        g.FillPie(MyBrush, 0, 0, this.button1.Width, this.button1.Height,
                         60, 240);
                        break;
            }        }
            private void button3_Click(object sender, System.EventArgs e)
            {
                this.iFlag = 1;
                this.button3.Refresh();        }        private void button4_Click(object sender, System.EventArgs e)
            {
                this.iFlag = 2;
                this.button4.Refresh();        }        private void button5_Click(object sender, System.EventArgs e)
            {
                this.iFlag = 3;
                this.button5.Refresh();        }
            private System.String StrFileName = "";
            private System.Int32 iFlag = 3;        private void button2_Click(object sender, System.EventArgs e)
            {
                this.openFileDialog1.ShowDialog();
                this.StrFileName = this.openFileDialog1.FileName;
                this.button2.Refresh();
            }        private void button1_Click(object sender, EventArgs e)
            {        }   
                 
        }
    }现在是在“private System.Int32 iFlag = 2;”设定下的形状能够回到事件1的设置,再往下选择就又不好使了!
      

  5.   

    晕 没看明白  是不是要3个button都想用到button1_Paint事件??
    如果是的话就这样
    给个例子
            private void Form6_Load(object sender, EventArgs e)
            {
                this.button1.Paint += new PaintEventHandler(MyButton_Paint);
                this.button2.Paint += new PaintEventHandler(MyButton_Paint);
                this.button3.Paint += new PaintEventHandler(MyButton_Paint);
            }        private void MyButton_Paint(object sender, PaintEventArgs e)
            {
                //code
            }这样就可以了
    没看懂你说的意思。。