S-Hend

SJH Task 3 2024 - Data Types Test

May 21st, 2024
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsApp1
  12. {
  13.     public partial class FormG3DataTypeDragDrop : Form
  14.     {
  15.         public static class Globals
  16.         {
  17.             public static string strDragObject ="blank";
  18.         }
  19.  
  20.         public FormG3DataTypeDragDrop()
  21.         {
  22.             InitializeComponent();
  23.            
  24.         }
  25.  
  26.         private void btnReturn_Click(object sender, EventArgs e)
  27.         {
  28.             this.Owner.Show();
  29.             this.Close();
  30.         }
  31.  
  32.         private void pbDragDate1_MouseDown(object sender, MouseEventArgs e)
  33.         {
  34.  
  35.             // set the Global Drag Object to indicate a 'Date'
  36.             Globals.strDragObject = "Date";
  37.  
  38.             //Defines sender as a picturebox so we can use it
  39.  
  40.             PictureBox codeBlockDate1 = sender as PictureBox;
  41.  
  42.             //Define a data object and store the image and the tag
  43.  
  44.             DataObject dragImageDate1 = new DataObject();
  45.  
  46.             dragImageDate1.SetData(DataFormats.Bitmap, true, codeBlockDate1.Image);
  47.  
  48.             dragImageDate1.SetData(DataFormats.Text, true, codeBlockDate1.Tag);
  49.  
  50.  
  51.  
  52.             //Copies the data object as we drag
  53.  
  54.             DoDragDrop(dragImageDate1, DragDropEffects.Copy);
  55.         }
  56.  
  57.         private void pbDragNumber1_MouseDown(object sender, MouseEventArgs e)
  58.         {
  59.  
  60.             // set the Global Drag Object to indicate a 'Number'
  61.             Globals.strDragObject = "Number";
  62.  
  63.             //Defines sender as a picturebox so we can use it
  64.  
  65.             PictureBox codeBlockNumber1 = sender as PictureBox;
  66.  
  67.             //Define a data object and store the image and the tag
  68.  
  69.             DataObject dragImageNumber1 = new DataObject();
  70.  
  71.             dragImageNumber1.SetData(DataFormats.Bitmap, true, codeBlockNumber1.Image);
  72.  
  73.             dragImageNumber1.SetData(DataFormats.Text, true, codeBlockNumber1.Tag);
  74.  
  75.             //Copies the data object as we drag
  76.  
  77.             DoDragDrop(dragImageNumber1, DragDropEffects.Copy);
  78.         }
  79.  
  80.         private void pbDragString1_MouseDown(object sender, MouseEventArgs e)
  81.         {
  82.  
  83.             // set the Global Drag Object to indicate a 'String'
  84.             Globals.strDragObject = "String";
  85.  
  86.             //Defines sender as a picturebox so we can use it
  87.  
  88.             PictureBox codeBlockString1 = sender as PictureBox;
  89.  
  90.             //Define a data object and store the image and the tag
  91.  
  92.             DataObject dragImageString1 = new DataObject();
  93.  
  94.             dragImageString1.SetData(DataFormats.Bitmap, true, codeBlockString1.Image);
  95.  
  96.             dragImageString1.SetData(DataFormats.Text, true, codeBlockString1.Tag);
  97.  
  98.             //Copies the data object as we drag
  99.  
  100.             DoDragDrop(dragImageString1, DragDropEffects.Copy);
  101.         }
  102.  
  103.         private void gbNumberDataType_DragDrop(object sender, DragEventArgs e)
  104.         {
  105.            
  106.         }
  107.  
  108.         private void FormG3DataTypeDragDrop_Load(object sender, EventArgs e)
  109.         {
  110.  
  111.         }
  112.  
  113.         private void label1_Click(object sender, EventArgs e)
  114.         {
  115.  
  116.         }
  117.  
  118.         private void lblDragNumberHere_DragEnter(object sender, DragEventArgs e)
  119.         {
  120.             e.Effect = DragDropEffects.Copy;
  121.         }
  122.  
  123.         private void lblDragNumberHere_DragDrop(object sender, DragEventArgs e)
  124.         {
  125.  
  126.             // Check if the Global Drag Object is set to 'Number'. If so, allow the image to be dropped. Otherwise - do not drop the image.
  127.             if (Globals.strDragObject == "Number")
  128.             {
  129.                 Label picbox = (Label)sender;
  130.                 Graphics g = picbox.CreateGraphics();
  131.  
  132.                 g.DrawImage((Image)e.Data.GetData(DataFormats.Bitmap), new Point(0, 0));
  133.             } else
  134.                 {
  135.                 // find a way of saying "wrong data type!"
  136.                 Globals.strDragObject = "Blank";
  137.                 }
  138.         }
  139.  
  140.         private void lblDragNumberHere_Click(object sender, EventArgs e)
  141.         {
  142.  
  143.         }
  144.  
  145.         private void lbDragStringHere_DragEnter(object sender, DragEventArgs e)
  146.         {
  147.             e.Effect = DragDropEffects.Copy;
  148.         }
  149.  
  150.         private void lbDragDateHere_DragEnter(object sender, DragEventArgs e)
  151.         {
  152.             e.Effect = DragDropEffects.Copy;
  153.         }
  154.  
  155.         private void lbDragStringHere_DragDrop(object sender, DragEventArgs e)
  156.         {
  157.             // Check if the Global Drag Object is set to 'String'. If so, allow the image to be dropped. Otherwise - do not drop the image.
  158.             if (Globals.strDragObject == "String")
  159.             {
  160.                 Label picbox = (Label)sender;
  161.                 Graphics g = picbox.CreateGraphics();
  162.  
  163.                 g.DrawImage((Image)e.Data.GetData(DataFormats.Bitmap), new Point(0, 0));
  164.             }
  165.             else
  166.             {
  167.                 // find a way of saying "wrong data type!"
  168.                 Globals.strDragObject = "Blank";
  169.             }
  170.         }
  171.  
  172.         private void lbDragDateHere_DragDrop(object sender, DragEventArgs e)
  173.         {
  174.             // Check if the Global Drag Object is set to 'Date'. If so, allow the image to be dropped. Otherwise - do not drop the image.
  175.             if (Globals.strDragObject == "Date")
  176.             {
  177.                 Label picbox = (Label)sender;
  178.                 Graphics g = picbox.CreateGraphics();
  179.  
  180.                 g.DrawImage((Image)e.Data.GetData(DataFormats.Bitmap), new Point(0, 0));
  181.             }
  182.             else
  183.             {
  184.                 // find a way of saying "wrong data type!"
  185.                 Globals.strDragObject = "Blank";
  186.             }
  187.         }
  188.  
  189.         private void pbDragDate1_Click(object sender, EventArgs e)
  190.         {
  191.  
  192.         }
  193.  
  194.         private void gbStringDataType_Enter(object sender, EventArgs e)
  195.         {
  196.  
  197.         }
  198.  
  199.         private void lbDragStringHere_Click(object sender, EventArgs e)
  200.         {
  201.  
  202.         }
  203.  
  204.         private void pbDragNumber1_Click(object sender, EventArgs e)
  205.         {
  206.  
  207.         }
  208.  
  209.         private void pbDragString1_Click(object sender, EventArgs e)
  210.         {
  211.  
  212.         }
  213.  
  214.         private void gbNumberDataType_Enter(object sender, EventArgs e)
  215.         {
  216.  
  217.         }
  218.  
  219.         private void gbDateDataType_Enter(object sender, EventArgs e)
  220.         {
  221.  
  222.         }
  223.     }
  224. }
Add Comment
Please, Sign In to add comment