快速业务通道

ASF.net窗体对话框的实现

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-05-22
aces:
'' Imports System.IO
'' Imports System.Drawing.Imaging
'' Without these import statements at the beginning of your code,
'' the code example will not function.
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
'' Display an SaveFileDialog so the user can save the Image
'' assigned to Button2.
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif"
saveFileDialog1.Title = "Save an Image File"
saveFileDialog1.ShowDialog()
'' If the file name is not an empty string open it for saving.
If saveFileDialog1.FileName <> "" Then
'' Save the Image via a FileStream created by the OpenFile method.
Dim fs As FileStream = CType(saveFileDialog1.OpenFile(), FileStream)
'' Save the Image in the appropriate ImageFormat based upon the
'' file type selected in the dialog box.
'' NOTE that the FilterIndex property is one-based.
Select Case saveFileDialog1.FilterIndex
Case 1
Me.button2.Image.Save(fs, ImageFormat.Jpeg)
Case 2
Me.button2.Image.Save(fs, ImageFormat.Bmp)
Case 3
Me.button2.Image.Save(fs, ImageFormat.Gif)
End Select
fs.Close()
End If
End Sub
// C#
// NOTE: You must import the following namespaces:
// using System.IO;
// using System.Drawing.Imaging;
// Without these import statements at the beginning of your code,
// the code example will not function.
private void button2_Click(object sender, System.EventArgs e)
{
// Display an SaveFileDialog so the user can save the Image
// assigned to Button2.
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
saveFileDialog1.Title = "Save an Image File";
saveFileDialog1.ShowDialog();
// If the file name is not an empty string open it for saving.
if(saveFileDialog1.FileName != "")
{
// Save the Image via a FileStream created by the OpenFile method.
FileStream fs = (FileStream)saveFileDialog1.OpenFile();
// Save the Image in the appropriate ImageFormat based upon the
// File type selected in the dialog box.
// NOTE that the FilterIndex property is one-based.
switch(saveFileDialog1.FilterIndex)
{
case 1 :
this.button2.Image.Save(fs,ImageFormat.Jpeg);
break;
case 2 :
this.button2.Image.Save(fs,ImageFormat.Bmp);
break;
case 3 :
this.button2.Image.Save(fs,ImageFormat.Gif);
break;
}
fs.Close();
}
}

关于写入文件流的进一步信息,请参阅 FileStream.BeginWrite 方法。

ColorDialog 组件

此对话框显示颜色列表,并且返回所选的颜色。

与前两种对话框不同,ColorDialog 组件很容易实现其主要功能(挑选颜色)。选取的颜色将成为 Color 属性的设定值。因此,使用颜色就和设定属性值一样简单。在下面的例子中,按钮控制的 Click 事件将会开启一个 ColorDialog 组件。一旦用户选中某种颜色,并且单击了 OK ,按钮的背景将被设成所选的颜色。本例假设存在名为 Button1 的 Button 组件和名为 ColorDialog1 的 ColorDialog 组件。

'' Visual Basic
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If ColorDialog1.Sho

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号