现在两个问题
1、要图片控件PICTUREBOX屏幕居中
2、第2个就是要控制下面代码中图片在轮换中出现的次数,比如我让"成龙.jpg"只能被选中3次,已经被选中3次以后就imageslist中remove掉。"布什.jpg"只能被选4次。如果不用数据库能实现吗?
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int i;
int r;
string[] names = new string[] { "刘翔", "毕福建", "布什"}; private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
timer1.Enabled = true;
label1.Visible = false;
label2.Visible = false;
}
if (e.KeyCode == Keys.Enter)
{
timer1.Enabled = false;
label1.Visible = true;
r = 0;
r = i % names.Length;
label1.Text = "恭喜您!抽中了:" + names[r];
}
if (e.KeyData == Keys.Escape) Application.Exit();
{
} } private void timer1_Tick(object sender, EventArgs e)
{
List<Image> lst = new List<Image>();//保存图片
lst.Add(Image.FromFile("C:\\choujiang\\毕福剑.jpg"));
lst.Add(Image.FromFile("C:\\choujiang\\布什.jpg"));
lst.Add(Image.FromFile("C:\\choujiang\\成龙.jpg"));
if (i>=lst.Count)
{
i = 0;
}
else
{
this.pictureBox1.Image = lst[i];
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
i = i + 1;
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
} }
}
1、要图片控件PICTUREBOX屏幕居中
2、第2个就是要控制下面代码中图片在轮换中出现的次数,比如我让"成龙.jpg"只能被选中3次,已经被选中3次以后就imageslist中remove掉。"布什.jpg"只能被选4次。如果不用数据库能实现吗?
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int i;
int r;
string[] names = new string[] { "刘翔", "毕福建", "布什"}; private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
timer1.Enabled = true;
label1.Visible = false;
label2.Visible = false;
}
if (e.KeyCode == Keys.Enter)
{
timer1.Enabled = false;
label1.Visible = true;
r = 0;
r = i % names.Length;
label1.Text = "恭喜您!抽中了:" + names[r];
}
if (e.KeyData == Keys.Escape) Application.Exit();
{
} } private void timer1_Tick(object sender, EventArgs e)
{
List<Image> lst = new List<Image>();//保存图片
lst.Add(Image.FromFile("C:\\choujiang\\毕福剑.jpg"));
lst.Add(Image.FromFile("C:\\choujiang\\布什.jpg"));
lst.Add(Image.FromFile("C:\\choujiang\\成龙.jpg"));
if (i>=lst.Count)
{
i = 0;
}
else
{
this.pictureBox1.Image = lst[i];
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
i = i + 1;
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
} }
}
如果我用数据库
lst.Add(Image.FromFile("C:\\choujiang\\毕福剑.jpg"));
lst.Add(Image.FromFile("C:\\choujiang\\布什.jpg"));
lst.Add(Image.FromFile("C:\\choujiang\\成龙.jpg"));这地方怎么写?
System.IO.Stream stream = new MemoryStream(bts);
System.Drawing.Bitmap bmp = new Bitmap(stream);
PictureBox pbx = new PictureBox();
pbx.Image = bmp;