Winform image scroll view (zoom in, zoom out, rotate, drag to view) [daily essay], winform essay
The method is tens of millions. I am just one of them [controlling pictures by controlling PictureBox, and displaying pictures in controls]... it's a little strange if you haven't done it for a few years!
Add the mouse scroll in the form structure:
1 /// <summary> 2 // form construction method 3 /// </summary> 4 public CandidateForm () 5 {6 InitializeComponent (); 7 this. mouseWheel + = new MouseEventHandler (CandidateForm_MouseWheel); 8}
Scroll listener: and keep the picture in the middle
1 /// <summary> 2 /// scroll 3 /// </summary> 4 /// <param name = "sender"> </param> 5 // /<param name = "e"> </param> 6 private void CandidateForm_MouseWheel (object sender, mouseEventArgs e) 7 {8 this. pic. dock = DockStyle. none; 9 this. pic. borderStyle = BorderStyle. fixedSingle; 10 Size size = this. pic. size; 11 size. width + = e. delta; 12 if (size. width> pic. image. width) 13 {14 pic. width = pic. image. width; 15 pic. height = pic. image. height; 16} 17 else if (size. width * pic. image. height/pic. image. width <pic. parent. height-200) 18 {19 return; 20} 21 else22 {23 pic. width = size. width; 24 pic. height = size. width * pic. image. height/pic. image. width; 25} 26 pic. left = (pic. parent. width-pic. width)/2; 27 pic. top = (pic. parent. height-pic. height)/2; 28}
Rotation:
1 private void left-hand ToolStripMenuItem_Click (object sender, EventArgs e) 2 {3 if (basicBt! = Null) 4 {5 basicBt = Tools. rotate (basicBt, 90); 6 height = this. pic. width; 7 width = this. pic. height; 8 setBasicPb (basicBt); 9} 10} 11 12 private void right-hand ToolStripMenuItem_Click (object sender, EventArgs e) 13 {14 if (basicBt! = Null) 15 {16 basicBt = Tools. rotate (basicBt, 270); 17 height = this. pic. width; 18 width = this. pic. height; 19 setBasicPb (basicBt); 20} 21}
Drag the image directly to the mouse click event, and process the PictureBox position based on the mouse drag. key code:
1 // drag 2 if (canDrag) 3 {4 pic. location = 5 new Point (pic. left + e. x-Snapshot X, pic. top + e. y-p0.Y); 6}