C#Windows应用程序中图片框中的图像上传问题 [英] image upload problem in picture box in C# windows application
问题描述
大家好
我正在执行C#Windows项目,我必须通过单击图片框事件无按钮事件在图片框中上传图像
有人可以帮忙给图片框添加代码吗,通过它我可以上传图片框事件
谢谢与问候
Indrajit Dasgupta
Hi All
I am doing C# windows project where I have to upload a image in a picture box through clicking the picture box event no button event
Can any one please help code for the picture box through which I can upload Picture in picture box event
Thanks & Regards
Indrajit Dasgupta
推荐答案
处理PictureBox.Click事件:
Handle the PictureBox.Click event:
private void pictureBox1_Click(object sender, EventArgs e)
{
PictureBox p = sender as PictureBox;
if (p != null)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
p.Image = Image.FromFile(ofd.FileName);
}
}
}
您可能希望将对话框中的文件限制为仅图像文件,为此使用Filter属性.
这里有一个提示,告诉您如何获取仅图像过滤器: ^ ]
You may want to restrict the files in the dialog to just Image files, use the Filter property for that.
There is a Tip here which tells you how to get the images-only filter: A FileDialog.Filter generator for all supported images[^]
这篇关于C#Windows应用程序中图片框中的图像上传问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!