コード例 #1
0
ファイル: Form1.cs プロジェクト: bangush/csharp
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (bcropAll)
                {
                    TabPage    tp  = SelectedTab;
                    PictureBox pb  = tp.PB();
                    Bitmap     src = new Bitmap(pb.Image);
                    cropAllRect = pb.CR();
                    tabControl1.TabPages.Remove(SelectedTab);
                    icntlist = cropAllFiles.Count;
                    icnt     = 0;
                    foreach (var file in cropAllFiles)
                    {
                        ThreadPool.QueueUserWorkItem(CropAll, file);
                    }
                }
                else
                {
                    TabPage    tp       = SelectedTab;
                    PictureBox pb       = tp.PB();
                    Bitmap     src      = new Bitmap(pb.Image);
                    Rectangle  cropRect = pb.CR();
                    Bitmap     target   = new Bitmap(cropRect.Width, cropRect.Height);

                    using (Graphics g = Graphics.FromImage(target))
                    {
                        g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height), cropRect, GraphicsUnit.Pixel);
                        g.Save();
                    }
                    pb.Image = target;
                    pb.Refresh();
                }
            }
        }