繁体   English   中英

在C#中将PictureBox用作TrackBar

[英]Using PictureBox as a TrackBar in C#

我在图片框中制作了一个带有图片的栏。 通过单击该跟踪栏,必须有一条黑色竖线。 但是,下面显示了一个问题。

http://j1307.hizliresim.com/1c/8/q0rh1.png

您的问题是,将DateTime拖入字符串中并不会为您提供将图像保存到的受支持的文件名。

例如:

String fileName = "C:\\" + DateTime.Now + ".bmp";
File.Create(fileName);

将会引发错误,因为fileName为您提供了C:\\08/07/2013 12:41:39.bmp -这不是有效的文件路径。

要解决此问题,您可以将字符串的DateTime部分格式化为更可口的内容,例如

String formattedDateTime = DateTime.Now.ToString("s").Replace(":","-");
String fileName = String.Format(@"C:\{0}.bmp", formattedDateTime);
File.Create(fileName);

这将为您提供一个文件名,例如C:\\2013-07-08T12-48-57.bmp ,该文件名不仅会保存,而且还可以排序。

所以最后,要将其应用于您的代码,您将使用

String formattedDateTime = DateTime.Now.ToString("s").Replace(":","-") ;
String fileName = String.Format(@"C:\{0}.bmp", formattedDateTime);
img.Save(fileName);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM