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 9142953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:54:15+00:00 2026-06-17T09:54:15+00:00

this question is a further development of a previous question. I’m working with C#

  • 0

this question is a further development of a previous question.
I’m working with C# .NET framework 2.0, Visual Studios 10.
I have a text editor upon which I would like to have a dirty marker in the form title, in this case a simple ““. If the textbox has been changed, then the “” should appear in the title. When the textbox has been saved, then the “*” should disappear. I’ve tried the following things, but perhaps incorrectly:
1 form, editor, has the save button and textbox

—- Editor.cs

—- Functions.cs

a Different FILE, NOT A FORM, Functions.cs, gets called upon save which performs the save
(to keep things neat, only buttons etc on form code, and a different file does the dirty work).

–Changing Editor._isDirty value from within the second functional file
–Changing _isDirty value from within the editor file itself
–Changing IsDirty from within the editor (i can’t figure out how to do that from the functional file)

and here is the relevant code:

    public static bool _isDirty = false;

    public plainTextEditor() 
    {
        InitializeComponent();
        functionsProxy = new Functions();
        IsDirty = false;
    }

    /* Property added to flag Changed _isDirty event */
    public bool IsDirty
    {
        get { return _isDirty; }
        set
        {
            if (_isDirty != value)
            {
                _isDirty = value;
                OnIsDirtyChanged(IsDirty);
            }
        }
    }
    protected void OnIsDirtyChanged(bool _isDirty)
    {
        if (_isDirty == true)
        {
            //textBox1.BackColor = Color.LightCoral;
            this.Text += "*";
        }
        else
        {
            this.Text = "Text Editor";
            //textBox1.BackColor = SystemColors.Window;
        }
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        string newtext = textBox1.Text;
        if (currentText != newtext)
        {
            // This solves the problem of initial text being tagged as changed text
            if (currentText == "")
            {
                //textBox1.BackColor = SystemColors.Window;
                IsDirty = false;
            }
            else
            {
                IsDirty = true;
            }
            currentText = newtext;
        }
    }

    private void btnSave_Click(object sender, EventArgs e)
    {
        functionsProxy.doSave(textBox1.Text);
        //_isDirty = false;
        IsDirty = false;
    }

Now, from what I understood about the events and properties.. if I even change the value of _isDirty, the OnIsDirty should be called and changed right?? No matter where I change the value of _isDirty, say it be from a different form. That’s what I want anyways.. that the event of * either appears or disappears depending on whether the _isDirty changes! Somehow it’s only working to mark the dirty and not to clear it.

Please help if you can, or suggest another method (sample code would be ace!) 😉

  • 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-17T09:54:16+00:00Added an answer on June 17, 2026 at 9:54 am

    There are several issues in your code. One of them is the mix-up of a static member and a parameter in the method. I tried to correct the code. Here is my suggestion for you:

    private bool _isDirty = false;
    
    public plainTextEditor() 
    {
        InitializeComponent();
        functionsProxy = new Functions();
        IsDirty = false;
    }
    
    /* Property added to flag Changed _isDirty event */
    public bool IsDirty
    {
        get { return _isDirty; }
        set
        {
            if (_isDirty != value)
            {
                _isDirty = value;
                OnIsDirtyChanged();
            }
        }
    }
    
    private void OnIsDirtyChanged()
    {
        if (_isDirty == true)
        {
            //textBox1.BackColor = Color.LightCoral;
            this.Text += "*";
        }
        else
        {
            this.Text = "Text Editor";
            //textBox1.BackColor = SystemColors.Window;
        }
    }
    
    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        string newtext = textBox1.Text;
        if (currentText != newtext)
        {
            // This solves the problem of initial text being tagged as changed text
            if (currentText == "")
            {
                //textBox1.BackColor = SystemColors.Window;
                IsDirty = false;
            }
            else
            {
                IsDirty = true;
            }
            currentText = newtext;
        }
    }
    
    private void btnSave_Click(object sender, EventArgs e)
    {
        functionsProxy.doSave(textBox1.Text);
        IsDirty = false;
    }
    

    Keep “_isDirty” private to your form. You already expose the Dirty state with your property IsDirty. If you don’t want any code from outside your form to change IsDirty, then make the setter (“set”) private.
    Now your code should run.

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

Sidebar

Related Questions

This question follows on from a previous question, that has raised a further issue.
Following up this question , I have a further problem - I have two
This question is a further development of this question: jQuery simple checkbox to hide
Background (question further down) I've been Googling this back and forth reading RFCs and
N.B THIS QUESTION HAS BEEN UPDATED, READ FURTHER DOWN Hi, I want to create
since I couldn't find an answer to this question I researched a bit further
This is a further question based on this answer: How can I implement a
My development team is working to the Scrum methodolody, pretty much. We have a
Updated Question After some further debugging I've updated this question to be more accurate
I am taking a prior question one step further (see this question ), I

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.