如何从图片框获取图像名称 [英] how to get image name from a picturebox

查看:183
本文介绍了如何从图片框获取图像名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个Windows窗体上有一个PictureBox,现在我想获取已经在PictureBox中设置的图像的名称.
我试过了:

I have a PictureBox on one of my windows form, now I would like to get the name of the image which is already set in the PictureBox.
I tried:

string imagepath = pictureBox3.ImageLocation.ToString();

//and to get only name of image.

string picname = imagepath.Substring(imagepath.LastIndexOf('\\'));

推荐答案

这可能不起作用-这取决于您如何将图像加载到PictureBox中. br/> 如果您在设计时修复了图像,则可以通过在属性窗格中设置源来修复该图像,那么就没有要提取的URL.
如果从资源加载图像,则也可能不起作用.
如果在运行时从图像或位图加载PictureBox.Image属性,则没有要获取的URL.

我唯一能看到ImageLocation包含有用内容的实例是在使用PictureBox.Load方法时.

您想达到什么目的,您认为这会有所帮助?
This may not work - it depends on how you have loaded the image into the PictureBox.
If you fix the image at design time, by setting an source in the properties pane, then there is no URL to fetch.
If you load the image from a resource, it may not work either.
If you load the PictureBox.Image property at runtime from an Image or Bitmap, then there is no URL to fetch.

The only instance I can see where ImageLocation contains anything useful, is when you use PictureBox.Load method.

What are you trying to achieve, that you think this would help?


这篇关于如何从图片框获取图像名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆