本文整理汇总了C#中System.Windows.Forms.SaveFileDialog类的典型用法代码示例。如果您正苦于以下问题:C# SaveFileDialog类的具体用法?C# SaveFileDialog怎么用?C# SaveFileDialog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SaveFileDialog类属于System.Windows.Forms命名空间,在下文中一共展示了SaveFileDialog类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: button1_Click
private void button1_Click(object sender, System.EventArgs e)
{
Stream myStream ;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
saveFileDialog1.FilterIndex = 2 ;
saveFileDialog1.RestoreDirectory = true ;
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream = saveFileDialog1.OpenFile()) != null)
{
// Code to write the stream goes here.
myStream.Close();
}
}
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:18,代码来源:SaveFileDialog
示例2: new SaveFileDialog()
//引入命名空间
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
class ImageOpen: Form
{
protected string strProgName;
protected string strFileName;
protected Image image;
MenuItem miSaveAs;
public static void Main()
{
Application.Run(new ImageOpen());
}
public ImageOpen()
{
ResizeRedraw = true;
Menu = new MainMenu();
Menu.MenuItems.Add("&File");
Menu.MenuItems[0].MenuItems.Add(new MenuItem("&Open...",
new EventHandler(MenuFileOpenOnClick),
Shortcut.CtrlO));
Menu.MenuItems[0].Popup += new EventHandler(MenuFileOnPopup);
miSaveAs = new MenuItem("Save &As...");
miSaveAs.Click += new EventHandler(MenuFileSaveAsOnClick);
Menu.MenuItems[0].MenuItems.Add(miSaveAs);
}
void MenuFileOnPopup(object obj, EventArgs ea)
{
miSaveAs.Enabled = (image != null);
}
void MenuFileSaveAsOnClick(object obj, EventArgs ea)
{
SaveFileDialog savedlg = new SaveFileDialog();
savedlg.InitialDirectory = Path.GetDirectoryName(strFileName);
savedlg.FileName = Path.GetFileNameWithoutExtension(strFileName);
savedlg.AddExtension = true;
savedlg.Filter = "Windows Bitmap (*.bmp)|*.bmp|" +
"Graphics Interchange Format (*.gif)|*.gif|" +
"JPEG File Interchange Format (*.jpg)|" +
"*.jpg;*.jpeg;*.jfif|" +
"Portable Network Graphics (*.png)|*.png|" +
"Tagged Imaged File Format (*.tif)|*.tif;*.tiff";
if (savedlg.ShowDialog() == DialogResult.OK)
{
try
{
image.Save(savedlg.FileName);
}
catch (Exception exc)
{
MessageBox.Show(exc.Message, Text);
return;
}
strFileName = savedlg.FileName;
Text = strProgName + " - " + Path.GetFileName(strFileName);
}
}
void MenuFileOpenOnClick(object obj, EventArgs ea)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "All Image Files|*.bmp;*.ico;*.gif;*.jpeg;*.jpg;" +
"*.jfif;*.png;*.tif;*.tiff;*.wmf;*.emf|" +
"Windows Bitmap (*.bmp)|*.bmp|" +
"Windows Icon (*.ico)|*.ico|" +
"Graphics Interchange Format (*.gif)|*.gif|" +
"JPEG File Interchange Format (*.jpg)|" +
"*.jpg;*.jpeg;*.jfif|" +
"Portable Network Graphics (*.png)|*.png|" +
"Tag Image File Format (*.tif)|*.tif;*.tiff|" +
"Windows Metafile (*.wmf)|*.wmf|" +
"Enhanced Metafile (*.emf)|*.emf|" +
"All Files (*.*)|*.*";
if (dlg.ShowDialog() == DialogResult.OK)
{
try
{
image = Image.FromFile(dlg.FileName);
}
catch (Exception exc)
{
Console.WriteLine(exc.Message);
return;
}
strFileName = dlg.FileName;
Text = Path.GetFileName(strFileName);
Invalidate();
}
}
protected override void OnPaint(PaintEventArgs pea)
{
Graphics grfx = pea.Graphics;
if (image != null)
grfx.DrawImage(image, 0, 0);
}
}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:107,代码来源:SaveFileDialog
注:本文中的System.Windows.Forms.SaveFileDialog类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论