2个回答
展开全部
之前遇到过一个人提过类似的问题,下面是当时做的例子:
(一个窗体,上面有一个按钮,点击按钮触发事件)
private void button1_Click(object sender, EventArgs e)
{
//this.Hide();
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
//停止定时器;
timer.Stop();
//Bitmap bit = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
Bitmap bit = new Bitmap(this.Width, this.Height);
Graphics g = Graphics.FromImage(bit);
//g.CopyFromScreen(new Point(0, 0), new Point(0, 0), bit.Size);
g.CopyFromScreen(new Point(this.Location.X,this.Location.Y), new Point(0, 0), bit.Size);
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "bmp|*.bmp|jpg|*.jpg|gif|*.gif";
if (saveFileDialog.ShowDialog() != DialogResult.Cancel)
{
bit.Save(saveFileDialog.FileName);
}
g.Dispose();
this.Visible = true;
}
(一个窗体,上面有一个按钮,点击按钮触发事件)
private void button1_Click(object sender, EventArgs e)
{
//this.Hide();
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
//停止定时器;
timer.Stop();
//Bitmap bit = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
Bitmap bit = new Bitmap(this.Width, this.Height);
Graphics g = Graphics.FromImage(bit);
//g.CopyFromScreen(new Point(0, 0), new Point(0, 0), bit.Size);
g.CopyFromScreen(new Point(this.Location.X,this.Location.Y), new Point(0, 0), bit.Size);
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "bmp|*.bmp|jpg|*.jpg|gif|*.gif";
if (saveFileDialog.ShowDialog() != DialogResult.Cancel)
{
bit.Save(saveFileDialog.FileName);
}
g.Dispose();
this.Visible = true;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询