在C#中将用户名和图像路径写入文件 [英] Writing user name and image path into a file in C#
本文介绍了在C#中将用户名和图像路径写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hy,
我有一堆图标,玩家可以从中选择自己的图标。我想用用户名来检索用户图标路径togheter以将其写入文件中,但似乎我的程序需要这样做。它写入并重写播放器名称(错误不在新行中)而不是图标的路径(该位置在我的计算机中)。 Bellow the code ...
真诚地,
private void Add_Click( object sender,EventArgs e)
{
string myInputDate = ;
// foreach(名称中的玩家名称)
< span class =code-comment> // {
String playerN = nameBox.Text;
String pathN = System.IO.Path.GetDirectoryName(pictBox.ImageLocation);
播放器播放器= 新播放器(播放器N,路径N);
myInputDate + = player.Name + , + player.Path + \ n;
// }
File.WriteAllText( @ C:\ Users \ Marius \Desktop\GameMachineWF \ GameMachineWF \Player.csv ,myInputDate);
}
解决方案
路径是文件的链接:
< pre lang =c#>< pre lang = c# >
私有 void Add_Click( object <> span sender,EventArgs e)
{
int wins = 0 跨度>;
int 得分= 0 ;
int plays = 0 ;
player = new 播放器(nameBox.Text,currentImage,score,wins,plays);
player.Write();
}
和写方法
public void 写()
{
StreamWriter sw = File.AppendText( @ 。\ Player.csv);
string line = this .Name + , + this .Paths + , + this .Score + , + this .wins + , + this .level + , + this .plays;
sw.WriteLine(line);
sw.Close();
}
并使用currentImage参数添加播放器方法
private void AddPlayer_Load( object sender,EventArgs e)
{
System.IO.DirectoryInfo director = new System.IO.DirectoryInfo( @ 。\ gamei \);
尝试
{
如果((director.Exists))
{
System.IO.FileInfo file = null ;
foreach (System.IO.FileInfo eachfile in director.GetFiles() )
{
file = eachfile;
if (file.Extension == .jpg)
{
lista.Add(file.FullName);
imageLen ++;
}
}
pictBox.Image = Image.FromFile(lista [ 0 ]。ToString ());
currentImage = lista [ 0 ]。ToString();
i = 0 ;
}
Hy,
I have a bunch of icons from which the player can choose as his own Icon. I want to retrive the user icon path togheter with is user name to write it in a file but it seems my program dosent wnat to do that. It writes and also rewrites player name (wrong not in a new line) and not the path of the icon (the location is in my computer). Bellow the code ...
Sincerly,
private void Add_Click(object sender, EventArgs e)
{
string myInputDate = " ";
//foreach (Player name in Name)
//{
String playerN = nameBox.Text;
String pathN = System.IO.Path.GetDirectoryName(pictBox.ImageLocation);
Player player = new Player(playerN,pathN);
myInputDate += player.Name + "," + player.Path + "\n";
// }
File.WriteAllText(@"C:\Users\Marius\Desktop\GameMachineWF\GameMachineWF\Player.csv", myInputDate);
}
解决方案
Path is the link of the file:
<pre lang="c#"> private void Add_Click(object sender, EventArgs e) { int wins =0; int score =0; int plays =0; player = new Player(nameBox.Text, currentImage,score, wins,plays); player.Write(); }
And the write method
public void Write () { StreamWriter sw = File.AppendText(@".\Player.csv"); string line = this.Name + "," + this.Paths + "," + this.Score + "," + this.wins + "," + this.level + "," + this.plays; sw.WriteLine(line); sw.Close(); }
And Add Player method with currentImage parameter
private void AddPlayer_Load(object sender, EventArgs e) { System.IO.DirectoryInfo director = new System.IO.DirectoryInfo(@".\imagini\"); try { if ((director.Exists)) { System.IO.FileInfo file = null; foreach ( System.IO.FileInfo eachfile in director.GetFiles()) { file = eachfile; if (file.Extension == ".jpg") { lista.Add(file.FullName); imageLen++; } } pictBox.Image = Image.FromFile(lista[0].ToString()); currentImage = lista[0].ToString(); i = 0; }
这篇关于在C#中将用户名和图像路径写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文