Thursday, 28 April 2011

FolderBrowserDialog in Win Forms


FolderBrowserDialog in Win Forms



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace opendialog1
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Form4 f4 = new Form4();
            f4.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            richTextBox1.Text = "";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderDlg = new FolderBrowserDialog();
            folderDlg.ShowNewFolderButton = true;
           
            if (folderDlg.ShowDialog() == DialogResult.OK)
            {
               // richTextBox1.LoadFile(folderDlg.SelectedPath,RichTextBoxStreamType.PlainText);
                this.Text = folderDlg.SelectedPath;
                MessageBox.Show(folderDlg.RootFolder.ToString());
            }

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Form3_Load(object sender, EventArgs e)
        {

        }
    }
}

� E � � �/h g n>}

        private void button3_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfdlg = new SaveFileDialog();

            sfdlg.InitialDirectory = @"C:\";
            sfdlg.RestoreDirectory = true;
            sfdlg.Title = "Save Text Files";
            sfdlg.DefaultExt = "txt";
            sfdlg.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            sfdlg.FilterIndex = 2;
            sfdlg.CheckFileExists = true;
            sfdlg.CheckPathExists = true;


            if (sfdlg.ShowDialog() == DialogResult.OK)
            {
                this.Text = sfdlg.FileName;
                if (richTextBox1.TextLength > 0)
                {
                    richTextBox1.SaveFile(sfdlg.FileName, RichTextBoxStreamType.PlainText);
                }
                else
                {
                    MessageBox.Show("Cant save null data");
                }
               
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Form3 f3 = new Form3();
            f3.Show();
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }
    }
}

No comments:

Post a Comment