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
{
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);
}
}
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);
}
}
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)
{
}
}
}
SAVE ALONEI want to create a save button not a save as
Page 1 of 1
1 Replies - 742 Views - Last Post: 11 August 2010 - 12:48 AM
#1
SAVE ALONE
Posted 10 August 2010 - 11:37 PM
Hi! I would like to create a save button using Microsoft visual c#. I already know how to create a save as button. But i don't know how to create a save button. I also know how to create an open file. Please kindly help me. I am really a newbie in C#. THANKS A LOT!
Replies To: SAVE ALONE
#2
Re: SAVE ALONE
Posted 11 August 2010 - 12:48 AM
Peggy, on 10 August 2010 - 09:37 PM, said:
Hi! I would like to create a save button using Microsoft visual c#. I already know how to create a save as button. But i don't know how to create a save button. I also know how to create an open file. Please kindly help me. I am really a newbie in C#. THANKS A LOT!
You will need a class variable to store the path for the 'save' method. Initially this would be set to the empty string (or null). If the user loads a file (Open button?) you'd set this variable to the path the user selects in the OpenFile dialog. When the users presses the Save button, you'd check to see if the variable is null/empty and if it is use the Save As method you already have.
Also, in the Save As method, you would set this variable so the user can use the Save button from then on.
Make sense?
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|