在c#中上传图像,在wpf中显示消息框
本文关键字:显示 消息 wpf 图像 | 更新日期: 2023-09-27 18:08:50
我正在制作一个程序,该程序将只上传位图。如果用户试图上传任何其他扩展,它应该弹出一个错误消息。
OpenFileDialog op = new OpenFileDialog();
op.Title = "Open Image";
op.Filter = "bmp files (*.bmp)|*.bmp";
if (op.ShowDialog() == true)
{
image.Source = new BitmapImage(new Uri(op.FileName));
}
if ( op.ShowDialog() !== FilterEventArgs)
{
MessageBox.Show ( your path doesn't bmp );
}
我如何纠正这段代码,什么是正确的参数放入if语句来显示消息框?
Image image = new Image();
OpenFileDialog op = new OpenFileDialog();
op.Title = "Open Image";
op.Filter = "bmp files (*.bmp)|*.bmp";
bool bNotBmp = true;
while (op.ShowDialog() == true && bNotBmp == true)
{
FileInfo FileInf = new FileInfo(op.FileName);
string ImgExtension = FileInf.Extension;
if (FileInf.Extension.ToString().ToLower() != ".bmp")
{
MessageBox.Show("Please upload only bmp file");
}
else
{
bNotBmp = false;
}
}
MessageBox.Show("Write image or operation cancelled.");
OpenFileDialog op = new OpenFileDialog();
op.Title = "Open Image";
op.Filter = "bmp files (*.bmp)|*.bmp";
var result = op.ShowDialog();
if (result == DialogResult.OK)
{
if(System.IO.Path.GetExtension(op.FileName).ToLower() == ".bmp"){
image.Source = new BitmapImage(new Uri(op.FileName));
}
else{
MessageBox.Show ("The file must have a .bmp extension");
}
}