在C#中将用户名和图像路径写入文件

编程入门 行业动态 更新时间:2024-10-27 20:28:45
本文介绍了在C#中将用户名和图像路径写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Hy, 我有一堆图标,玩家可以从中选择自己的图标。我想用用户名来检索用户图标路径togheter以将其写入文件中,但似乎我的程序需要这样做。它写入并重写播放器名称(错误不在新行中)而不是图标的路径(该位置在我的计算机中)。 Bellow the code ... 真诚地,

private void Add_Click( object sender,EventArgs e) { string myInputDate = ; // foreach(名称中的玩家名称) // { 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# > 私有 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#中将用户名和图像路径写入文件

本文发布于:2023-11-09 17:08:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572942.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中将   路径   图像   用户名   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!