• 【小技巧】C#的saveFileDialog和openFileDialog的用法总结


     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.Linq;
     7 using System.Text;
     8 using System.Windows.Forms;
     9 
    10 using System.IO;
    11 
    12 namespace WindowsFormsApplication1
    13 {
    14     public partial class Form1 : Form
    15     {
    16         public Form1()
    17         {
    18             InitializeComponent();
    19         }
    20 
    21         private void button1_Click(object sender, EventArgs e)
    22         {
    23             StreamWriter myStream;
    24             saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
    25             saveFileDialog1.RestoreDirectory = true;
    26             if (saveFileDialog1.ShowDialog() == DialogResult.OK)
    27             {
    28                 string str;
    29                 str = saveFileDialog1.FileName;
    30                 myStream = new StreamWriter(saveFileDialog1.FileName);
    31                 myStream.Write(textBox1.Text); 
    32                 myStream.Flush();
    33                 myStream.Close();
    34             }
    35         }
    36 
    37         private void button2_Click(object sender, EventArgs e)
    38         {
    39             string resultFile;
    40             OpenFileDialog openFileDialog1 = new OpenFileDialog();
    41             openFileDialog1.InitialDirectory = "D:\";
    42             openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
    43             openFileDialog1.RestoreDirectory = true;
    44             if (openFileDialog1.ShowDialog() == DialogResult.OK)
    45             {
    46                 resultFile = openFileDialog1.FileName;
    47                 MessageBox.Show(resultFile);
    48             }
    49         }
    50 
    51         private void Form1_Load(object sender, EventArgs e)
    52         {
    53         
    54         }
    55     }
    56 }
  • 相关阅读:
    zookeeper
    redis客户端高低版本简单实战、雪崩、击穿、穿透、布隆过滤器(三)
    redis集群理论与实战(二)
    redis集群理论与实战
    oracle单表循环修改表字段
    redis的集群、主从复制、CAP、paxos
    CF1328D Carousel
    AT4842 [ABC136E] Max GCD
    [ABC135D] Digits Parade
    AT4752 [ABC131E] Friendships
  • 原文地址:https://www.cnblogs.com/achao123456/p/5920353.html
Copyright © 2020-2023  润新知