无论如何要读写.png文件和链接.txt文件名为.png文件相同吗?
它最多以窗户形式制成
public Photo(string filename)
{
bitmap = new Bitmap(filename); /*shows the picture.png */
CreationDate = File.GetCreationTime(filename).ToString(); /*shows creationtime of picture*/
Filelink = filename; /*shows filename opened*/
FileName = Path.GetFileName(filename); /*shows opened file path*/
/*Description = FileMode.Open.ToString(filename);*/
private void Button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog
{
Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG|All files (*.*)|*.*"
};
if (ofd.ShowDialog() == DialogResult.OK)
{
try
{
Photo photoph = new Photo(ofd.FileName);
/*dataGridView1.Rows.Add(photoph.bitmap, photoph.FileName, photoph.Filelink, photoph.CreationDate);*/
listing.Add(ofd.FileName, dataGridView1);
}
catch
{
MessageBox.Show("Impossible to open file. Choose another one", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
Its made in Windows Forms at the most, in a button
public Photo(string filename)
{
bitmap = new Bitmap(filename); /*shows the picture.png */
CreationDate = File.GetCreationTime(filename).ToString(); /*shows creationtime of picture*/
Filelink = filename; /*shows filename opened*/
FileName = Path.GetFileName(filename); /*shows opened file path*/
/*Description = FileMode.Open.ToString(filename);*/
private void Button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog
{
Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG|All files (*.*)|*.*"
};
if (ofd.ShowDialog() == DialogResult.OK)
{
try
{
Photo photoph = new Photo(ofd.FileName);
/*dataGridView1.Rows.Add(photoph.bitmap, photoph.FileName, photoph.Filelink, photoph.CreationDate);*/
listing.Add(ofd.FileName, dataGridView1);
}
catch
{
MessageBox.Show("Impossible to open file. Choose another one", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谢谢大家。我已经找到了解决方案并替换了:
Thanks everyone. I already found solution and made it with Replace:
如果我正确理解,则可以使用
MultiSelect
OpenFileDialog的属性。这样,您可以打开多个文件(在您的情况下,具有不同扩展名的同一文件名)并将其显示给用户。If I understand correctly, you can use
Multiselect
property of OpenFileDialog. In this way you can open multiple file (in your case same file name with different extensions) and show them to users.