Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8703503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:53:02+00:00 2026-06-13T02:53:02+00:00

I made a small text editor that saves text from a RichTextBox into an

  • 0

I made a small text editor that saves text from a RichTextBox into an .rtf file, but whenever I click the open menu option it opens the savefile dialog box. I cannot figure out why can anyone help me out?

Here are the names for the menu dialog items.

MenuStrip: menuStrip1
Save: saveMenu
Open: openMenu
RichTextBox: richTextBox1

here is the code that I am working on below…

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();
        }

        //save the file

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

            // Text from the rich textbox rtfMain
            string str = richTextBox1.Text;
            // Create a new SaveFileDialog object
            using (SaveFileDialog dlgSave = new SaveFileDialog())
                try
                {
                    // Available file extensions
                    dlgSave.Filter = "Rich Text Format (.rtf)|*.rtf";
                    // SaveFileDialog title
                    dlgSave.Title = "Save";
                    // Show SaveFileDialog
                    if (dlgSave.ShowDialog() == DialogResult.OK && dlgSave.FileName.Length > 0)
                    {
                        richTextBox1.SaveFile(dlgSave.FileName);

                    }
                }
                catch (Exception errorMsg)
                {
                    MessageBox.Show(errorMsg.Message);
                } 


        }

        private void openMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)

        {
            using (var of = new OpenFileDialog())
            {
                of.DefaultExt = "*.rtf";
                of.Filter = "RTF Files|*.rtf";

                if (of.ShowDialog() == DialogResult.OK)
                    richTextBox1.Rtf = System.IO.File.ReadAllText(of.FileName);
            }



        }

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:53:03+00:00Added an answer on June 13, 2026 at 2:53 am

    I’m assuming your openMenu is a child item on the menuStrip1; thus when you click it, the the menuStrip1_ItemClicked event is raised, and that’s exactly where you have your code to open a Save dialog.

    You should probably get rid of the openMenu_ItemClicked method, and instead have a single menuStrip1_ItemClicked method wired up the menuStrip1’s ItemClicked event, and in that method you can determine what item was clicked and what to do accordingly.

    So in your menuStrip1_ItemClicked method, you could do something like…

    if(e.ClickedItem == this.openMenu)
    {
        //Code to bring up Open File Dialog here
    }
    else if (e.ClickedItem == this.saveMenu)
    {
        //Code to bring up Save Dialog here
    }
    

    P.S. you can debug to see the flow of execution, and you’ll probably see that the menuStrip1 ItemClicked event is being raised first, and that code being executed first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've made a small tool that parses a chunk of text, does some simple
I have made some small macro that I am using to display text line
I made a small magento (1.7) template file that displays a all products in
I'm creating a small program that will read a text file, which contains a
I made a small project where i try to change the name from edit
I've made a small game that uses level, and level is just a int
I have made a small log service that i want to publish to a
i made a small menu with <ul> <li> : js: $('#ulAcoesCliente li').click(function(ev) { $(.ulNone).each(function(){
I've made a small gist of it but basically what I'd like to do
I have a small ruby application that I made on my local machine. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.