62,271
社区成员
发帖
与我相关
我的任务
分享
private void DTM_ChangePic_Click(object sender, EventArgs e)
{
string PicSrc = "";
openFileDialog1.FileName = "";
openFileDialog1.Filter = "图片文件(*.jpg)|*.jpg|(*.JPEG)|*.jpeg|(*.PNG)|*.png";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string selectedImg = openFileDialog1.FileName;
string names = selectedImg.Substring(selectedImg.LastIndexOf("\\") + 1).ToLower();
Directory.CreateDirectory(@"C:\aa");//创建本地文件夹
PicSrc = @"C:\aa\" + names;
File.Copy(selectedImg, PicSrc);//保存选择文件
pictureBox1.BackgroundImage = Image.FromFile(selectedImg);
SavaPicSrc(PicSrc);
}
}
public void SavaPicSrc(string FileName)
{
XmlDocument xmlDoc = new XmlDocument();
XmlDeclaration del = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
xmlDoc.AppendChild(del);
XmlElement root = xmlDoc.CreateElement("Info");//根节点
XmlElement User = xmlDoc.CreateElement("Pic");
User.SetAttribute("src", FileName);
root.AppendChild(User);
xmlDoc.AppendChild(root);
xmlDoc.Save("PicSrc.xml");
}