我創建了一個方法,當我拖放時移動PictureBox。但是,當我拖動圖片框,圖像具有圖像的真實大小,我想圖像具有圖片框的大小當我拖動時拖放移動PictureBox-圖像的大小
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
picBox = (PictureBox)sender;
var dragImage = (Bitmap)picBox.Image;
IntPtr icon = dragImage.GetHicon();
Cursor.Current = new Cursor(icon);
DoDragDrop(pictureBox1.Image, DragDropEffects.Copy);
DestroyIcon(icon);
}
}
protected override void OnGiveFeedback(GiveFeedbackEventArgs e)
{
e.UseDefaultCursors = false;
}
protected override void OnDragEnter(DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Bitmap))) e.Effect = DragDropEffects.Copy;
}
protected override void OnDragDrop(DragEventArgs e)
{
picBox.Location = this.PointToClient(new Point(e.X - picBox.Width/2, e.Y - picBox.Height/2));
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
extern static bool DestroyIcon(IntPtr handle);
你的意思是說你想讓圖像縮小以適應picturebox? –
http://www.dotnetcurry.com/ShowArticle.aspx?ID=179 – MethodMan
@glace是的,我需要縮小圖片框 – Ladessa