码迷,mamicode.com
首页 > Windows程序 > 详细

Winform 图片鼠标滚动查看(放大,缩小,旋转,拖动查看)[日常随笔]

时间:2015-12-02 22:45:47      阅读:925      评论:0      收藏:0      [点我收藏+]

标签:

方法千千万,我只是其中一笔[通过控制PictureBox来控制图片,图片完全施展在控件中]...几久不做,还真有点陌生!

窗体构造中添加鼠标滚动:

1 /// <summary>
2         /// 窗体构造方法
3         /// </summary>
4         public CandidateForm()
5         {
6             InitializeComponent();
7             this.MouseWheel += new MouseEventHandler(CandidateForm_MouseWheel);
8         }

滚动监听:并且保持图片正中

 1 /// <summary>
 2         /// 鼠标滚动
 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             else
22             {
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         }

旋转:

 1 private void 左旋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 右旋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         }

 

拖动待续...

Winform 图片鼠标滚动查看(放大,缩小,旋转,拖动查看)[日常随笔]

标签:

原文地址:http://www.cnblogs.com/peixuanzhihou/p/5014412.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!