SaveFileDialog

From IronPython Cookbook

The SaveFileDialog is very easy to use:

import clr
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')

from System.Drawing import Bitmap
from System.Drawing.Imaging import ImageFormat
from System.Windows.Forms import DialogResult, SaveFileDialog

# Not a very interesting image
image = Bitmap(1, 1)

dialog = SaveFileDialog()
dialog.Title = 'Save Chart as Jpg Image'
dialog.Filter = 'Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*'

if dialog.ShowDialog() == DialogResult.OK:
    # Should really check what format they *really* want!
    try:
        image.Save(dialog.FileName, ImageFormat.Jpeg)
    except IOError, e:
        print 'An error occurred:', e


Back to Contents.

TOOLBOX
LANGUAGES