⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 10.4.txt

📁 《Microsoft Visual C# .NET 2003开发技巧大全》源代码
💻 TXT
字号:
Listing 10.4 Cropping Images
private void menuCrop_Click(object sender, System.EventArgs e)
{
if( image != null )
{
this.Cursor = Cursors.Cross;
cropping = true;
}
}
private void Form1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if( cropping == true )
{
cropRect.X = e.X;
cropRect.Y = e.Y;
}
}
private void Form1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if( cropping == true )
{
cropRect.Width = e.X - cropRect.X;
cropRect.Height = e.Y - cropRect.Y;
Invalidate();
}
}
private void Form1_MouseUp(object sender,System.Windows.Forms.MouseEventArgs e)
{
if( cropping == true )
{
cropping = false;
// move old picture
Image oldImage = (Image) image.Clone();
// create new image object
image = new Bitmap( cropRect.Width, cropRect.Height );
// get graphics object from new image
Graphics g = Graphics.FromImage( image );
// draw old image into new image using crop rect
g.DrawImage( oldImage, new Rectangle(0,0,image.Width, image.Height),
cropRect.X, cropRect.Y, cropRect.Width,
cropRect.Height, GraphicsUnit.Pixel );
// reset
cropRect.X = cropRect.Y = -1;
this.Cursor = Cursors.Default;
Invalidate();
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -