fork download
  1. using System;
  2. using System.Drawing;
  3. using System.Drawing.Imaging;
  4. using System.Windows.Forms;
  5. namespace picImgDropMoveTest
  6. {
  7. public partial class Form1 : Form
  8. {
  9. PictureBox pictureBox1 = new PictureBox();
  10. PictureBox pictureBox2 = new PictureBox();
  11. Bitmap bm;
  12. Metafile mf;//
  13.  
  14. public Form1()
  15. {
  16. pictureBox1.BorderStyle = BorderStyle.FixedSingle;
  17. pictureBox1.Location = new Point(10, 20);
  18. pictureBox1.Size = new Size(200, 200);
  19. pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
  20. pictureBox1.DragDrop += _DragDrop;
  21. pictureBox1.MouseDown += pic_MD;
  22. pictureBox1.DragEnter += _DragEnter;
  23. pictureBox2.BorderStyle = BorderStyle.FixedSingle;
  24. pictureBox2.Location = new Point(220, 20);
  25. pictureBox2.Size = new Size(200, 200);
  26. pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
  27. pictureBox2.DragDrop += pictureBox2_DragDrop;
  28. pictureBox2.DragEnter += pictureBox2_DragEnter;
  29. this.ClientSize = new Size(440, 240);
  30. this.Controls.Add(this.pictureBox2);
  31. this.Controls.Add(this.pictureBox1);
  32. pictureBox1.AllowDrop = true;
  33. pictureBox2.AllowDrop = true;
  34. }
  35. private void _DragEnter(object sender, DragEventArgs e)
  36. {
  37. if (e.Data.GetDataPresent(DataFormats.FileDrop))
  38. e.Effect = DragDropEffects.Copy;
  39. else
  40. e.Effect = DragDropEffects.None;
  41. }
  42. private void _DragDrop(object sender, DragEventArgs e)
  43. {
  44. string[] FilePath;
  45. FilePath = (string[])e.Data.GetData(DataFormats.FileDrop, false);
  46. string fname = FilePath.Length > 0 ? FilePath[0] : "";
  47. if ("" == fname) return;
  48. pictureBox1.LoadAsync(fname);
  49. }
  50. private void pic_MD(object sender, MouseEventArgs e)
  51. {
  52. if (e.Button != MouseButtons.Left) return;
  53. bm = pictureBox1.Image as Bitmap;
  54. mf = pictureBox1.Image as Metafile;//
  55. if ((bm == null && mf == null) || bm == pictureBox1.ErrorImage) return;//if (bm == null|| bm == pictureBox1.ErrorImage) return;
  56. DataObject dataObj = bm != null ? new DataObject(DataFormats.Bitmap, bm) : new DataObject(DataFormats.MetafilePict, mf);// DataObject dataObj = new DataObject(DataFormats.Bitmap, bm);
  57. DragDropEffects dde = pictureBox1.DoDragDrop(dataObj, DragDropEffects.Copy);
  58. }
  59. private void pictureBox2_DragEnter(object sender, DragEventArgs e)
  60. {
  61. if (e.Data.GetDataPresent(DataFormats.Bitmap) || e.Data.GetDataPresent(DataFormats.MetafilePict))// if (e.Data.GetDataPresent(DataFormats.Bitmap))
  62. e.Effect = DragDropEffects.Copy;
  63. else
  64. e.Effect = DragDropEffects.None;
  65. }
  66. private void pictureBox2_DragDrop(object sender, DragEventArgs e)
  67. {
  68. if (bm == null && mf == null) return;//if (bm == null) return;
  69. if (bm != null) pictureBox2.Image = bm; else pictureBox2.Image = mf;//pictureBox2.Image = bm;
  70. }
  71. }
  72.  
  73. static class Program
  74. {
  75. [STAThread]
  76. static void Main()
  77. {
  78. Application.EnableVisualStyles();
  79. Application.SetCompatibleTextRenderingDefault(false);
  80. Application.Run(new Form1());
  81. }
  82. }
  83.  
  84. }
  85.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(4,22): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
prog.cs(7,30): error CS0246: The type or namespace name `Form' could not be found. Are you missing an assembly reference?
prog.cs(9,1): error CS0246: The type or namespace name `PictureBox' could not be found. Are you missing an assembly reference?
prog.cs(10,1): error CS0246: The type or namespace name `PictureBox' could not be found. Are you missing an assembly reference?
prog.cs(35,40): error CS0246: The type or namespace name `DragEventArgs' could not be found. Are you missing an assembly reference?
prog.cs(42,39): error CS0246: The type or namespace name `DragEventArgs' could not be found. Are you missing an assembly reference?
prog.cs(50,36): error CS0246: The type or namespace name `MouseEventArgs' could not be found. Are you missing an assembly reference?
prog.cs(59,51): error CS0246: The type or namespace name `DragEventArgs' could not be found. Are you missing an assembly reference?
prog.cs(66,50): error CS0246: The type or namespace name `DragEventArgs' could not be found. Are you missing an assembly reference?
Compilation failed: 9 error(s), 0 warnings
stdout
Standard output is empty