Csharp/C#教程:默认文件名SaveFileDialog分享


默认文件名SaveFileDialog

我想从值DataGridViewCells创建具有default file name SaveFileDialog

到目前为止我试过了

 private void buttonSave_Click(object sender, EventArgs e) { //first //mySaveFileDialog.FileName = myDataGridView.SelectedCells[2].Value.ToString(); //second SaveFileDialog saveFile = new SaveFileDialog(); saveFile.FileName = myDataGridView.SelectedCells[2].Value.ToString(); saveFile.ShowDialog(); } 

谁能帮我解决这个问题?

SaveFileDialog有一个用于此目的的属性:使用Silverlight的DefaultFileName或使用.NET的FileName

您问题中的(不可编译的)代码将变为:

  private void buttonSave_Click(object sender, EventArgs e) { SaveFileDialog mySaveFileDialog = new SaveFileDialog(); //Silverlight mySaveFileDialog.DefaultFileName = myDataGridView.SelectedCells[2].Value.ToString(); //.NET mySaveFileDialog.FileName = myDataGridView.SelectedCells[2].Value.ToString(); } 

问题是你需要使用:

 myDataGridView.SelectedCells[0].Value.ToString(); 

代替

 myDataGridView.SelectedCells[2].Value.ToString(); 

直到你不用鼠标或任何东西选择3个或更多细胞。 您可以索引[2]

 private void buttonSave_Click(object sender, EventArgs e) { SaveFileDialog saveFile = new SaveFileDialog(); saveFile.FileName = myDataGridView.SelectedCells[0].Value.ToString(); saveFile.ShowDialog(); } 

这对你有用吗?

您的代码应该采用以下方式:

 private void buttonSave_Click(object sender, EventArgs e) { SaveFileDialog saveFile = new SaveFileDialog(); saveFile.FileName = myDataGridView.SelectedCells[2].Value.ToString(); saveFile.ShowDialog(); } 

使用FileName但在显示对话框之前设置文件名。

请在简单的WinForm应用程序中尝试:

  static void Main() { var saveFile = new SaveFileDialog(); saveFile.FileName = "myfile.txt"; saveFile.ShowDialog(); string fileName = saveFile.FileName ; MessageBox.Show(fileName); } 

有用!

打印面板中的所有控件

上述就是C#学习教程:默认文件名SaveFileDialog分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 public Bitmap MemoryImage; public void GetPrintArea( Panel pn1) { MemoryImage = new Bitmap(panel13.Width, pn1.Height); pn1.DrawToBitmap(MemoryImage, new Rectangle(0, 0, pn1.Width, pn1.Height)); } protected override void OnPaint(PaintEventArgs e) { if (MemoryImage != null) { e.Graphics.DrawImage(MemoryImage, 0, 0); base.OnPaint(e); } } void printdoc1_PrintPage(object sender, PrintPageEventArgs e) { Rectangle pagearea = e.PageBounds; e.Graphics.DrawImage(MemoryImage, (pagearea.Width / 2) - (this.panel13.Width / 2), this.panel13.Location.Y); } Bitmap bmp = new Bitmap(MemoryImage.Width, MemoryImage.Height); panel13.DrawToBitmap(bmp, panel13.Bounds); saveFileDialog1.ShowDialog(); saveFileDialog1.Title = "Save"; saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif"; bmp.Save(saveFileDialog1.FileName); 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/984376.html

(0)
上一篇 2021年12月20日
下一篇 2021年12月20日

精彩推荐