New File button

I would like to create a new file button in C# windows

Page 1 of 1

2 Replies - 1071 Views - Last Post: 12 August 2010 - 04:38 AM Rate Topic: -----

#1 Peggy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 25-September 09

New File button

Posted 12 August 2010 - 02:56 AM

Hi there again...
I'm still working with my C# program...
Now I need to create a button that would create a new file...
Just like the one you see in a Word document creator...
How am I suppose to do that...
And could you please suggest a tutorial suitable for this kind of problems...
I'm kind of find it difficult in finding one...
THANKS A LOT!!!

 
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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        string path = "";
        public Form1()
        {
            InitializeComponent();
        }

        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog save1 = new SaveFileDialog();
            save1.DefaultExt = "*rtf";
            save1.Filter = "RTF FIles|*.rtf";
            if (save1.ShowDialog() == DialogResult.OK && save1.FileName.Length > 0) {
                richTextBox1.SaveFile(save1.FileName, RichTextBoxStreamType.RichText);
                path = save1.FileName;
            }
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog open1 = new OpenFileDialog();
            open1.Filter = "Rich Text Format(*rtf)|*.rtf|Allfiles(*.*)|*.*";
            if (open1.ShowDialog() == DialogResult.OK) {
                richTextBox1.LoadFile(open1.FileName, RichTextBoxStreamType.RichText);
                path = open1.FileName;
            } 
            
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void fontToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FontDialog fontDialog1 = new FontDialog();
            fontDialog1.ShowColor = true;          
            if (fontDialog1.ShowDialog() != DialogResult.Cancel)
            {
                richTextBox1.SelectionFont = fontDialog1.Font;
                richTextBox1.SelectionColor = fontDialog1.Color; 

            }
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (path.Length > 0)
            {
                richTextBox1.SaveFile(path, RichTextBoxStreamType.RichText);
            }
            else {
                SaveFileDialog save2 = new SaveFileDialog();
                save2.DefaultExt = "*rtf";
                save2.Filter = "RTF FIles|*.rtf";
                if (save2.ShowDialog() == DialogResult.OK && save2.FileName.Length > 0)
                {
                    richTextBox1.SaveFile(save2.FileName, RichTextBoxStreamType.RichText);
                    path = save2.FileName; 
                }            
            }
        }

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RichTextBox form1 = new RichTextBox();
            form1.Text = "";
        }
    }
}




Is This A Good Question/Topic? 0
  • +

Replies To: New File button

#2 plejer_adam   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 90
  • Joined: 17-May 10

Re: New File button

Posted 12 August 2010 - 03:08 AM

maybe u could just clear the whole richtextbox , and make it that way New.
Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1536
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: New File button

Posted 12 August 2010 - 04:38 AM

I agree with plejer_adam...why don't you just clear the RichTextBox?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1