winForm pictureBox拖动图片and动态new 窗体&移动Panel窗体头
2013-09-25 12:30
399 查看
public void getScreen()
{
this.saveFileDialog2.Filter = "Image files (*.JPG)|*.JPG";
this.saveFileDialog2.FilterIndex = 0;
this.saveFileDialog2.RestoreDirectory = true;
this.saveFileDialog2.Title = "导出文件保存路径";
this.saveFileDialog2.FileName = "屏幕截图";
if (this.saveFileDialog2.ShowDialog() == DialogResult.Cancel)
{
this.Cursor = Cursors.Default;
}
else
{
this.Refresh();
Image image = new Bitmap(0x800, 0x600);
Graphics graphics = Graphics.FromImage(image);
graphics.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(800, 600));
IntPtr hdc = graphics.GetHdc();
graphics.ReleaseHdc(hdc);
image.Save(this.saveFileDialog2.FileName);
MessageBox.Show("OK", "提示!");
}
}
==================pictureBox拖动图片====================================
private void pictureBox1_MouseHover(object sender, EventArgs e)
{
if (this.pictureBox1.Image != null)
{
this.pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
Cursor = Cursors.Hand;
}
}
private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
Cursor = Cursors.Default;
p.X = 0;
p.Y = 0;
driftX = 0;
driftY = 0;
mx = 0;
my = 0;
}
bool wselected = false;
Point p = new Point();
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
wselected = true;
p.X = e.X;
p.Y = e.Y;
}
int driftX = 0, driftY = 0;
int mx = 0, my = 0;
Graphics g;
Bitmap bm;
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
try
{
if (wselected && this.pictureBox1.Image != null&&Cursors.Hand==Cursor)
{
this.Invalidate();
driftX = p.X - e.X;
driftY = p.Y - e.Y;
mx = mx - driftX;
my = my - driftY;
bm = new Bitmap(this.pictureBox1.Image);
g = pictureBox1.CreateGraphics();
g.Clear(pictureBox1.BackColor);
g.DrawImage(bm, mx, my);
bm.Dispose();
g.Dispose();
p.X = e.X;
p.Y = e.Y;
}
}
finally
{ }
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
wselected = false;
}
=============图片另存为================
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Jpg 图片|*.jpg|Bmp 图片|*.bmp|Gif 图片|*.gif|Png 图片|*.png|Wmf 图片|*.wmf";
saveFileDialog.FilterIndex = 0;
if (this.pictureBox1.Image == null)
{
MessageBox.Show("没有预览图片!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (pictureBox1.Image != null)
{
Bitmap bit = new Bitmap(pictureBox1.Image);
bit.Save(saveFileDialog.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
bit.Dispose();
}
}
//////////////////////////动态new 窗体
Type t = Type.GetType("MyTest.Form6");//窗体名要加上程序集名称
Form f = (Form)System.Activator.CreateInstance(t, new object[] { new string[] { "测试1", "测试2" } });
f.Show();
//winform Panel 作标题栏(移动Panel)
private bool IsMouseDown = false;
private Point mouseOffset;
private void panelTop_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
IsMouseDown = true;
}
mouseOffset = new Point(-e.X, -e.Y);
}
private void panelTop_MouseMove(object sender, MouseEventArgs e)
{
if (IsMouseDown == true)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
this.Location = mousePos;
}
}
private void panelTop_MouseUp(object sender, MouseEventArgs e)
{
IsMouseDown = false;
}
//winform Panel 作标题栏(移动Panel)/////结束
相关文章推荐
- WinForm - PictureBox显示图片及动态改变
- WinForm 无边框窗体 拖动工作区移动窗体
- .Net winform拖动工作区移动窗体
- WinForm 无边框窗体 拖动工作区移动窗体
- Winform 使用panel 自定义拖动窗体
- winform 鼠标拖动移动图片位置
- WinForm 无边框窗体 拖动工作区移动窗体
- C#生成灰度图片:拖动图片到picturebox显示,拖动picturebox图片到资源管理器 (Drag & drop )
- Winform窗体图片的拖动,放大,缩小,复位,打印预览,鼠标滑轮的放大缩小
- pygame简单动态图 & 动态图片的移动
- [VB.net][WinForm]Panel控件移动\鼠标拖动
- pygame简单动态图 & 动态图片的移动
- 【winform】鼠标拖动时显示虚线框,减少窗体绘制
- Winform鼠标拖动改变控件大小、移动控件位置
- android 拖拽图片&拖动浮动按钮到处跑
- C# Winform中如何实现窗体之…
- Siebel Tools: Create new LOV Type and Values & Create Static Picklist Using Tools
- winform 利用线程 实现窗体图片轮播
- winform 动态生成panel 动态生成透明panel 带边框的panel 并注册事件
- winform中怎么动态修改窗体的大小