我设立了三种事件 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才能避免这个问题呢?
{
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才能避免这个问题呢?
解决方案 »
- 监听端口时怎么判断有没有新连接?
- 麻烦各位网友帮我看看这段代码。先谢谢了。
- 求教 读写文件流效率问题~
- 如何把gridview中数据导入SQL数据库?
- 急!!! C# windows服务 如何捕获“服务在启动时暂停”的错误
- datagridview打印问题
- DataGridView小问题,请进
- const int a=4与int a=4有什么区别??Convert.ToDecimal与decimal.Parse()又有什么区别???
- 请问,以13开头的11位数字串的正规表达式怎么写啊?谢谢!
- 插入,替换'('字符的问题!
- 关于Linq的小问题
- OracleConnection 链接oracle怎么连接不上服务器。。求助
iFlag = 1;
然后再调用上面的代码。其余类似。
{
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;” 我填写的值
{
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(); }
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的设置,再往下选择就又不好使了!
如果是的话就这样
给个例子
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
}这样就可以了
没看懂你说的意思。。