
窗体对话框组件与微软视窗 *** 作系统中的对话框是一样的 也就是说 PrintDialog 组件是 打印 对话框 OpenFileDialog 组件是 打开文件 对话框 依此类推
与以往的 Microsoft Visual Basic 等 Windows 程序设计语言相似 NET 框架提供了 Windows 用户耳熟能详的对话框 对话框的具体用途(如 Printdialog 可用于文件打印等)通常是多种多样的 故而在 NET 框架提供的基础类中不包含用于文件打印 颜色选择等具体 *** 作的代码 而你却可以根据应用程序的需要灵活地实现它们 因此 在 NET 框架下 你不但可以直接应用标准对话框 而且能根据用户的选择作出不同的响应 本文提供的代码其用途就在于此
注意 关于各种对话框的属性 方法和事件的完整描述 可以在相应类的 Members 页面中找到 比如要查看 OpenFileDialog 组件的某一方法 就可以在文档索引的 OpenFileDialog class all members 栏目中找到相关的主题
1.OpenFileDialog 组件
OpenFileDialog 对话框使得用户能够通过浏览本地或者远程的文件系统以打开所选文件 它将返回文件路径和所选的文件名
OpenFileDialog 组件和SaveFileDialog 组件(下文将会详细描述)包含了用于浏览和选取文件所必需的基本代码 有了它们 你就不必为这些功能编写任何代码 进而能够专心实现打开或者保存文件等具体 *** 作
注意 FileDialog 类的 FilterIndex 属性(由于继承的原因 为 OpenFileDialog 和 SaveFileDialog 类所共有) 使用 one based 索引(译者注 指从 开始编号的索引) 此特性将在下文的代码中用到(并且会在相应位置再次强调) 当应用程序通过类型过滤器打开文件时 或者需要保存为特定格式的文件(比如 保存为纯文本文件而不是二进制文件)时 这一点是非常重要的 人们在使用 FilterIndex 属性时却经常忘了它 因此现在务必要把它记住
下列代码通过 Button 控件的 Click 事件调用 OpenFileDialog 组件 当用户选中某个文件 并且单击 OK 的时候 所选的文件将被打开 在本例中 文件内容将被显示在消息框内 以证实文件流被读入
本例假设存在名为 Button 的 Button 控件和名为 OpenFileDialog 的 OpenFileDialog 控件
Visual Basic NOTE: You must import the following namespace: Imports System IO Without this import statement at the beginning of your code the example will not function Private Sub Button _Click(ByVal sender As System Object _ ByVal e As System EventArgs) Handles Button Click If OpenFileDialog ShowDialog() = DialogResult OK Then Dim sr As New StreamReader(OpenFileDialog FileName) MessageBox Show(sr ReadToEnd) sr Close() End If End Sub
// C# // NOTE: You must import the following namespace: // using System IO; // Without this import statement at the beginning // of your code the example will not function private void button _Click(object sender System EventArgs e) { if(openFileDialog ShowDialog() == DialogResult OK) { StreamReader sr = new StreamReader(openFileDialog FileName); MessageBox Show(sr ReadToEnd()); sr Close(); } }
打开文件还可以使用 OpenFileDialog 组件的 OpenFile 方法 它将返回文件的每一个字节 在下面的例子中 一个 OpenFileDialog 组件将被实例化 它使用了 cursor 过滤器 以限定用户只能选取光标文件(扩展名为 cur) 一旦某个 cur 文件被选中 窗体的光标就被设成该文件描绘的光标形状
本例假设存在名为 Button 的 Button 控件
Visual Basic Private Sub Button _Click(ByVal sender As System Object _ ByVal e As System EventArgs) Handles Button Click Display an OpenFileDialog so the user can select a Cursor Dim openFileDialog As New OpenFileDialog() openFileDialog Filter = Cursor Files| cur openFileDialog Title = Select a Cursor File
Show the Dialog If the user clicked OK in the dialog and a CUR file was selected open it If openFileDialog ShowDialog() = DialogResult OK Then If openFileDialog FileName <> Then Assign the cursor in the Stream to the Form s Cursor property Me Cursor = New Cursor(openFileDialog OpenFile()) End If End If End Sub
// C# private void button _Click(object sender System EventArgs e) { // Display an OpenFileDialog so the user can select a Cursor OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog Filter = Cursor Files| cur ; openFileDialog Title = Select a Cursor File ;
// Show the Dialog // If the user clicked OK in the dialog and // a CUR file was selected open it if (openFileDialog ShowDialog() == DialogResult OK) { if(openFileDialog FileName != ) { // Assign the cursor in the Stream to the Form s Cursor property this Cursor = new Cursor(openFileDialog OpenFile()); } } }
关于读取文件流的进一步信息 请参阅FileStream BeginRead 方法
2.SaveFileDialog 组件
本对话框允许用户浏览文件系统并且选取将被写入的文件 当然 你还必须为文件写入编写具体代码
下列代码通过 Button 控件的 Click 事件调用 SaveFileDialog 组件 当用户选中某个文件 并且单击 OK 的时候 RichTextBox 控件里的内容将被保存到所选的文件中
本例假设存在名为 Button 的 Button 控件 名为 RichTextBox 的 RichTextBox 控件和名为 OpenFileDialog 的 SaveFileDialog 控件
Visual Basic NOTE: You must import the following namespace: Imports System IO Without this import statement at the beginning of your code the code example will not function Private Sub Button _Click(ByVal sender As System Object _ ByVal e As System EventArgs) Handles Button Click If SaveFileDialog ShowDialog() = DialogResult OK Then RichTextBox SaveFile(SaveFileDialog FileName _ RichTextBoxStreamType PlainText) End If End Sub
// C# // NOTE: You must import the following namespace: // using System IO; // Without this import statement at the beginning // of your code the code example will not function private void button _Click(object sender System EventArgs e) { if((saveFileDialog ShowDialog() == DialogResult OK) { richTextBox SaveFile(saveFileDialog FileName RichTextBoxStreamType PlainText); } }
保存文件还可以用 SaveFileDialog 组件的 OpenFile 方法 它将提供一个用于写入的 Stream 对象
在下面的例子中 有一个包含的 Button 控件 当你单击这个按钮的时候 一个 SaveFileDialog 组件将被打开 它将使用 gif jpeg 和 bmp 类型的文件过滤器 一旦用户通过 Save File 对话框内选中此类文件 按钮上的将被存入其中
本例假设存在名为 Button 的 Button 控件 并且它的 Image 属性被设为某个扩展名为 gif jpeg 或者 bmp 的文件
Visual Basic NOTE: You must import the following namespaces: 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 Button _Click(ByVal sender As System Object _ ByVal e As System EventArgs) Handles Button Click Display an SaveFileDialog so the user can save the Image assigned to Button Dim saveFileDialog As New SaveFileDialog() saveFileDialog Filter = JPeg Image| jpg|Bitmap Image| bmp|Gif Image| gif saveFileDialog Title = Save an Image File saveFileDialog ShowDialog()
If the file name is not an empty string open it for saving If saveFileDialog FileName <> Then Save the Image via a FileStream created by the OpenFile method Dim fs As FileStream = CType(saveFileDialog 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 saveFileDialog FilterIndex Case Me button Image Save(fs ImageFormat Jpeg)
Case Me button Image Save(fs ImageFormat Bmp)
Case Me button 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 button _Click(object sender System EventArgs e) { // Display an SaveFileDialog so the user can save the Image // assigned to Button SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog Filter = JPeg Image| jpg|Bitmap Image| bmp|Gif Image| gif ; saveFileDialog Title = Save an Image File ; saveFileDialog ShowDialog();
// If the file name is not an empty string open it for saving if(saveFileDialog FileName != ) { // Save the Image via a FileStream created by the OpenFile method FileStream fs = (FileStream)saveFileDialog 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(saveFileDialog FilterIndex) { case : this button Image Save(fs ImageFormat Jpeg); break;
case : this button Image Save(fs ImageFormat Bmp); break;
case : this button Image Save(fs ImageFormat Gif); break; }
fs Close(); } }
关于写入文件流的进一步信息 请参阅 FileStream BeginWrite 方法
3.ColorDialog 组件
此对话框显示颜色列表 并且返回所选的颜色
与前两种对话框不同 ColorDialog 组件很容易实现其主要功能(挑选颜色) 选取的颜色将成为 Color 属性的设定值 因此 使用颜色就和设定属性值一样简单 在下面的例子中 按钮控制的 Click 事件将会开启一个 ColorDialog 组件 一旦用户选中某种颜色 并且单击了 OK 按钮的背景将被设成所选的颜色 本例假设存在名为 Button 的 Button 组件和名为 ColorDialog 的 ColorDialog 组件
Visual Basic Private Sub Button _Click(ByVal sender As System Object _ ByVal e As System EventArgs) Handles Button Click If ColorDialog ShowDialog() = DialogResult OK Then Button BackColor = ColorDialog Color End If End Sub
// C# private void button _Click(object sender System EventArgs e) { if(colorDialog ShowDialog() == DialogResult OK) { button BackColor = colorDialog Color; } }
ColorDialog 组件具有 AllowFullOpen 属性 当其设为 False 的时候 Define Custom Colors 按钮将会失效 此时用户只能使用预定义的调色板 此外 它还有一个 SolidColorOnly 属性 当其设为 true 时 用户将不能使用抖动颜色
4.FontDialog 组件
此对话框允许用户选择字体 以改变其 weight 和 size 等属性
被选中的字体将成为 Font 属性的设定值 因此 使用字体也和设定属性值一样简单 在本例通过 Button 控件的 Click 事件调用 FileDialog 组件 当用户选中一个字体 并且单击 OK 的时候 TextBox 控件的 Font 属性将被设成所选的字体 本例假设存在名为 Button 的 Button 控件 名为 TextBox 的 TextBox 控件和名为 FontDialog 的 FontDialog 组件
Visual Basic Private Sub Button _Click(ByVal sender As System Object _ ByVal e As System EventArgs) Handles Button Click If FontDialog ShowDialog() = DialogResult OK Then TextBox Font = FontDialog Font End If End Sub
// C# private void button _Click(object sender System EventArgs e) { if(fontDialog ShowDialog() == DialogResult OK) { textBox Font = fontDialog Font; } }
FontDialog 元件还包括 MinSize 和 MaxSize 属性 它们决定了允许用户选择的字体的最小和最大点数 还有一个 ShowColor 属性 当其设为 True 时 用户可以从对话框的下拉列表中选取字体的颜色
5.PrintDocument 类
以下三个会话框 PrintDialog 组件 PageSetupDialog 组件和 PrintPreviewDialog 控件 都与 PrintDocument 类有关 PrintDocument 类用于文档打印前的设置 设定其属性 以改变文档外观和打印方式 再将其实例输出到打印机 通常的步骤是 ( ) 生成 PrintDocument 类的一个实例 ( ) 设置 PageSetupDialog 组件的属性 ( ) 使用 PrintPreviewDialog 控件进行预览 ( ) 通过 PrintDialog 组件打印出来
关于 PrintDocument 类的进一步资料 请参阅 PrintDocument Class
6.PrintDialog 元件
此对话框允许用户指定将要打印的文档 除此之外 它还能用于选择打印机 决定打印页 以及设置打印相关属性 通过它可以让用户文档打印更具灵活性 他们既能打印整个文档 又能打印某个片断 还能打印所选区域
使用 PrintDialog 组件时要注意它是如何与 PrinterSettings 类进行交互的 PrinterSettings 类用于设定纸张来源 分辨率和加倍放大等打印机特征属性 每项设置都是 PrinterSettings 类的一个属性 通过 PrintDialog 类可以改变关联到文档的 PrinterSetting 类实例(由PrintDocument PrinterSettings 指定)的特征属性值
PrintDialog 组件将包含特征属性设置的 PrintDocument 类的实例提交到打印机 应用 PrintDialog 组件进行文档打印的范例 请参见 Creating Standard Windows Forms Print Jobs
7.PageSetupDialog 组件
PageSetupDialog 组件用于显示打印布局 纸张大小和其它页面选项 如同其他对话框一样 可以通过 ShowDialog 方法调用 PageSetupDialog 组件 此外 必须生成一个 PrintDocument 类的实例 也即被打印的文档 而且必须安装了一台本地或者远程打印机 否则 PageSetupDialog 组件将无法获取打印格式以供用户选择
使用 PageSetupDialog 组件时必须注意它是如何与 PageSettings 类进行交互的 PageSettings 类决定页面如何被打印 比如打印方向 页面大小和边距等 每项设置都是 PageSettings 类的一个属性 PageSetupDialog 类可以改变 PageSettings 类实例(由 PrintDocument DefaultPageSettings 指定)的上述选项
在下列代码中 Button 控件的 Click 事件处理程序开启一个 PageSetupDialog 组件 其 Document 属性被设成某个存在的文档 其 Color 属性被设成 false
本例假设存在名为 Button 的 Button 控件 名为 myDocument 的 PrintDocument 控件和名为 PageSetupDialog 的 PageSetupDialog 组件
Visual Basic Private Sub Button _Click(ByVal sender As System Object _ ByVal e As System EventArgs) Handles Button Click The print document myDocument used below is merely for an example You will have to specify your own print document PageSetupDialog Document = myDocument Set the print document s color setting to false so that the page will not be printed in color PageSetupDialog Document DefaultPageSettings Color = False PageSetupDialog ShowDialog() End Sub
// C# private void button _Click(object sender System EventArgs e) { // The print document myDocument used below // is merely for an example // You will have to specify your own print document pageSetupDialog Document = myDocument; // Set the print document s color setting to false // so that the page will not be printed in color pageSetupDialog Document DefaultPageSettings Color = false; pageSetupDialog ShowDialog(); }
8.PrintPreviewDialog 控件
与其他对话框不同 PrintPreviewDialog 控件对整个应用程序或者其它控件没有影响 因为它仅仅在对话框里显示内容 此对话框用于显示文档 主要是打印之前的预览
调用 PrintPreviewDialog 控件 也是使用 ShowDialog 方法 同时 必须生成 PrintDocument 类的一个实例 也即被打印的文档
注意 当使用 PrintPreviewDialog 控件时 也必须已经安装了一台本地或者远程打印机 否则 PrintPreviewDialog 组件将无法获取被打印文档的外观
PrintPreviewDialog 控件通过 PrinterSettings 类和 PageSettings 类进行设置 分别与 PageDialog 组件和 PageSetupDialog 组件相似 此外 PrintPreviewDialog 控件的 Document 属性所指定的被打印文档 同时作用于 PrinterSettings 类和 PageSettings 类 其内容被显示在预览窗口中
在下列代码中 通过 Button 控件的 Click 事件调用 PrintPreviewDialog 控件 被打印文档在 Document 属性中指定 注意 代码中没有指定被打印文档
本例假设存在名为 Button 的 Button 控件 名为 myDocument 的 PrintDocument 组件和名为 PrintPreviewDialog 的 PrintPreviewDialog 控件
Visual Basic Private Sub Button _Click(ByVal sender As System Object _ ByVal e As System EventArgs) Handles Button Click The print document myDocument used below is merely for an example You will have to specify your own print document PrintPreviewDialog Document = myDocument PrintPreviewDialog ShowDialog() End Sub
// C# private void button _Click(object sender System EventArgs e) { // The print document myDocument used below // is merely for an example // You will have to specify your own print document printPreviewDialog Document = myDocument; printPreviewDialog ShowDialog() }
lishixinzhi/Article/program/net/201311/14815
FileStream fs = new FileStream("d:\\atxt", FileModeOpen); StreamReader m_streamReader = new StreamReader(fs); m_streamReaderBaseStreamSeek(0, SeekOriginBegin); string arry = ""; string strLine = m_streamReaderReadLine(); do { string[] split = strLineSplit('='); string a = split[0]; if (aToLower() == "ip") { arry += strLine + "\n"; } strLine = m_streamReaderReadLine(); } while (strLine != null && strLine != ""); m_streamReaderClose(); m_streamReaderDispose(); fsClose(); fsDispose(); ConsoleWrite(arry); ConsoleReadLine(); 如果你要大小写也要匹配的话把ToLower() 去掉就行了
因为要在uitableviewcell里面的uiview模块里面,调用selfnavigationcontroller pushviewcontroller推入一个新的viewcontroller,需要获取其上层的uiviewcontroller,找到如下的代码
id object = [self nextResponder];
while (![object isKindOfClass:[UIViewController class]] &&
object != nil) {
object = [object nextResponder];
}
UIViewController uc=(UIViewController)object;
FileUpload控件
FileUpload 控件显示一个文本框控件和一个浏览按钮,使用户可以选择客户端上的文件并将它上载到 Web 服务器。用户通过在控件的文本框中输入本地计算机上文件的完整路径(例如,C:\MyFiles\TestFiletxt)来指定要上载的文件。用户也可以通过单击“浏览”按钮,然后在“选择文件”对话框中定位文件来选择文件。
用户选择要上载的文件后,FileUpload 控件不会自动将该文件保存到服务器。您必须显式提供一个控件或机制,使用户能提交指定的文件。例如,可以提供一个按钮,用户单击它即可上载文件。为保存指定文件所写的代码应调用 SaveAs 方法,该方法将文件内容保存到服务器上的指定路径。通常,在引发回发到服务器的事件的事件处理方法中调用 SaveAs 方法。
在文件上传的过程中,文件数据作为页面请求的一部分,上传并缓存到服务器的内存中,然后再写入服务器的物理硬盘中。
有三个方面需要注意:
1确认是否包含文件
在调用 SaveAs 方法将文件保存到服务器之前,使用 HasFile 属性来验证 FileUpload 控件确实包含文件。若 HasFile 返回 true,则调用 SaveAs 方法。如果它返回 false,则向用户显示消息,指示控件不包含文件。不要通过检查PostedFile 属性来确定要上载的文件是否存在,因为默认情况下该属性包含 0 字节。因此,即使 FileUpload 控件为空,PostedFile 属性仍返回一个非空值。
2文件上传大小限制
默认情况下,上传文件大小限制为 4096 KB (4 MB)。可以通过设置 >
切换优先级是不行的,优先级高了只是说明读取进程会比更多的线程优先级高,但是还是会有比他更高的线程的,因为信号频率很低,所以用多线程是做不出来的。读取信号频率低的只能用一个单一的程序去读取。你可以用一个程序去读取信号。然后通过自己设计的格式写到文件中。然后另一个程序去不断读取文件中的数据做处理
Sonic官网
用户交流社区
目前已支持POCO-SDK的所有游戏引擎(Unity3d、Cocos2dx系列、白鹭、UE4),使用前需游戏已接入SDK。v140-beta更新后就可以使用啦~ (预计五一后更新)
Poco 是一个基于 UI 控件搜索的跨引擎自动化测试框架。支持主流游戏引擎:Cocos2d-x、Unity3d、安卓原生应用
>
以上就是关于ASP.NET窗体对话框的实现全部的内容,包括:ASP.NET窗体对话框的实现、lua的io,读取文件,匹配关键字,获取内容下面内容.并返回、io 如何取得uiview最上层子视图等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)