概述
1、添加控件
2、分别实现是三个button功能
private 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、实现滑动鼠标,图片放大缩小功能
public 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、实现“十字光标”
Point 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# 公共控件之pictureBox所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复