SoFunction
Updated on 2025-03-07

C# file drag and drop and pixelBox zoom and drag functions

File drag and drop:

Effect: When dragging a file to a control in the form, the path of the control is displayed on the control. As long as you get the path, you can naturally read the contents in the file.

Set the property AllowDrop of a control to true, and then add DragDrop and DragEnter time processing functions, as follows:

private void txtAppPath_DragEnter(object sender,  e)
    {
      if (())
      {
         = ;
      }
      else
      {
         = ;
      }
    }
    private void txtAppPath_DragDrop(object sender,  e)
    {
       = (()()).GetValue(0).ToString();
    }

Image zoom and drag:

1. Implement the mouse wheel to control picture zooming;

1. Set PixtureBox properties:

Dock:none

SizeMode:StretchImage

2. Add events:

(1) Set the bound image path

private void ScrewInfoForm_Shown(object sender, EventArgs e)
    {
      //Load assembly drawings      string drawingPath = (@"\\192.168.2.136\PCS", productCode + ".png");
      try
      {
        (drawingPath);
      }
      catch (Exception ex)
      {
        ("Loading assembly drawings failed, details:" + , "Measurement", , );
        return;
      }
    }

(2) Add event 1

 += new MouseEventHandler(pbxDrawing_MouseWheel);
//Implement scroll wheel scaling    private void pbxDrawing_MouseWheel(object sender,  e)
    {
      if ( < 0)
      {
         =  * 9 / 10;
         =  * 9 / 10;
      }
      else
      {
         =  * 11 / 10;
         =  * 11 / 10;
      }
    }

(3) Add event 2

//Implement mobile pictures    int xPos;
    int yPos;
    bool MoveFlag;
    private void pbxDrawing_MouseDown(object sender, MouseEventArgs e)
    {
      ();
      MoveFlag = true;// has been pressed.      xPos = ;//Current x coordinate.      yPos = ;//Current y coordinate.    }
    //In the mouse press event of picturebox.    private void pbxDrawing_MouseUp(object sender, MouseEventArgs e)
    {
      MoveFlag = false;
    }
    //Move on picturebox    private void pbxDrawing_MouseMove(object sender, MouseEventArgs e)
    {
      if (MoveFlag)
      {
         += Convert.ToInt16( - xPos);//Set x coordinates.         += Convert.ToInt16( - yPos);//Set the y coordinate.      }
    }

Summarize

The above is the c# file drag and drop, pixelBox zoom and drag introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!