1、添加控件
2、分别实现是三个button功能
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42private void 打开_Click(object sender, EventArgs e) { string pathname = string.Empty; OpenFileDialog file = new OpenFileDialog(); file.InitialDirectory = "."; file.Filter = "所有文件(*.*)|*.*"; file.ShowDialog(); if (file.FileName != string.Empty) { try { pathname = file.FileName; //获得文件的绝对路径 this.pictureBox1.Load(pathname); 保存.Enabled = true; 翻转90.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } } } private void 保存_Click(object sender, EventArgs e) { SaveFileDialog save = new SaveFileDialog(); save.ShowDialog(); if (save.FileName != string.Empty) { pictureBox1.Image.Save(save.FileName); } } private void 翻转90_Click(object sender, EventArgs e) { pictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone); pictureBox1.Refresh();//刷新图片框 //顺时针旋转90度 RotateFlipType.Rotate90FlipNone //逆时针旋转90度 RotateFlipType.Rotate270FlipNone //水平翻转 RotateFlipType.Rotate180FlipY //垂直翻转 RotateFlipType.Rotate180FlipX }
3、实现滑动鼠标,图片放大缩小功能
复制代码
1
2
3
4
5
6
7
8
9
10
11
12public Form1() { InitializeComponent(); pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel); } void pictureBox1_MouseWheel(object sender, MouseEventArgs e) { pictureBox1.Width += e.Delta; pictureBox1.Height += e.Delta; this.Width += e.Delta; this.Height += e.Delta; }
4、实现“十字光标”
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22Point lastPoint = new Point(-1, -1); private void picturebox_MouseMove(object sender, MouseEventArgs e) { if (e.Location != lastPoint)//保持十字光标不消失 pictureBox1.Refresh(); lastPoint = e.Location; DrawReversibleLine(lastPoint); } void DrawReversibleLine(Point p) { ControlPaint.DrawReversibleLine( pictureBox1.PointToScreen(new Point(0, p.Y)), pictureBox1.PointToScreen(new Point(pictureBox1.Width, p.Y)), SystemColors.Control); ControlPaint.DrawReversibleLine( pictureBox1.PointToScreen(new Point(p.X, 0)), pictureBox1.PointToScreen(new Point(p.X, pictureBox1.Height)), SystemColors.Control);//Color.ForestGreen }
最后
以上就是机智银耳汤最近收集整理的关于C# 公共控件之pictureBox的全部内容,更多相关C#内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复