只允许8个字符
问题描述:
所以,我终于得到了我的代码工作的方式我想...但..只允许8个字符
在下降,我想要的文件的标题下降的MessageBox.Show
显示。
我让它工作......但我只能读取最多8个字符。它将显示标题完美的任何标题8个字符或更少。
超过8个字符的任何字符显示为全部大写字母,并在末尾有〜1个字符。 示例:文件名称Penguins.jpg将显示“企鹅”。文件名称Penguinsarecool.jpg将显示“PENGUI〜1”。
这里是一个事先知情同意:
请让我知道如果你需要任何其他信息。 我感谢你的帮助!
这里是我的代码:
public void B1_DragDrop(object sender, DragEventArgs e)
{
string B1fileName = ((string[])((DataObject)e.Data).GetData("FileName"))[0];
string B1result = Path.GetFileNameWithoutExtension(B1fileName);
MessageBox.Show(B1result);
}
答
尝试DataFormats.FileDrop
代替"FileName"
作为GetData
参数。它指定Windows文件放置格式。这应该工作:如果你没有
public void B1_DragDrop(object sender, DragEventArgs e)
{
string B1fileName = ((string[])e.Data.GetData(DataFormats.FileDrop))[0];
string B1result = Path.GetFileNameWithoutExtension(B1fileName);
MessageBox.Show(B1result);
}
+0
当我最初尝试过你的建议时,“路径”。保持错误...所以我一直尝试不同的方法。然后我知道你需要***“使用System.IO”才能使用Path。正常工作。刚刚尝试过您的修改(再次),它完美的工作!谢谢! – crlic306 2014-10-07 19:47:44
好奇'新的FileInfo(B1fileName).Name'你会得到.. – 2014-10-07 18:43:46
@ crlic306,我看你在计算器问其他问题,您正在使用有提取文件名的正确方法,就像我在下面建议的一样。那么为什么你改变你的代码并寻求帮助? – 2014-10-07 19:28:36