Bitmap bmp;
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
openFileDialog1.Filter = "*.gif|*.gif|*.jpg|*.jpg|*.bmp|*.bmp";
if (openFileDialog1.ShowDialog()==DialogResult.OK)
{
bmp = new Bitmap(openFileDialog1.FileName);
this.Invalidate();
}
}
private void button1_Paint(object sender, PaintEventArgs e)
{
if (bmp != null)
{
Graphics grap = e.Graphics;
TextureBrush theBrush = new TextureBrush(bmp);
grap.FillRectangle(theBrush, this.ClientRectangle);
}
}
運用Drawing的Api讓button呈現Image的效果