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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:49:16+00:00 2026-05-26T14:49:16+00:00

My question comes from a problem which I have right now. I have MainWindow,

  • 0

My question comes from a problem which I have right now. I have MainWindow, AuthenticateWindow, and AddEntryWindow which all are WinForms. In main window I have possibility to Authenticate and Add Entry into my main windows textbox. They can not add an entry until they authenticate (no problem with this). I need to add an entry to the text box which will update my main windows textbox. The problem if, how can I check if entry was added to my textbox?

I am trying to have a Save option from menu strip. I am getting an error whenever I am trying to save an empty file. How could I authenticate the saving process by Save button by having it first disabled, and enabled after entry was added?

I could always verify if if textbox had an entry but I want to have button disabled first, and enabled after entry was added. I do not have a privilege to do so as of right now.

Please ask questions if I am not clear enough.

private void tsmiSave_Click(object sender, EventArgs e)
{
    // Open sfdSaveToLocation which let us choose the
    // location where we want to save the file.
    if (txtDisplay.Text != string.Empty)
    {
        sfdSaveToLocation.ShowDialog();
    }
}

MainWindow.cs

using System;
using System.IO;
using System.Windows.Forms;

namespace Store_Passwords_and_Serial_Codes
{
    public partial class MainWindow : Form
    {
        private AuthenticateUser storedAuth;

        public MainWindow()
        {
            InitializeComponent();
        }

        private void MainWindow_Load(object sender, EventArgs e)
        {
            // Prohibit editing.
            txtDisplay.Enabled = false;
        }

        public string ChangeTextBox
        {
            get
            {
                return this.txtDisplay.Text;
            }
            set
            {
                this.txtDisplay.Text = value;
            }
        }

        private void tsmiAuthenticate_Click(object sender, EventArgs e)
        {
            AuthenticationWindow authWindow = new AuthenticationWindow();
            authWindow.ShowDialog();
            storedAuth = authWindow.Result;
        }

        private void tsmiAddEntry_Click(object sender, EventArgs e)
        {
            if (storedAuth == null)
            {
                DialogResult result = MessageBox.Show
                    ("You must log in before you add an entry." 
                    + Environment.NewLine + "You want to authenticate?",
                    "Information", MessageBoxButtons.YesNo, 
                    MessageBoxIcon.Information);

                if (result == DialogResult.Yes)
                {
                    AuthenticationWindow authWindow = 
                        new AuthenticationWindow();
                    authWindow.ShowDialog();
                    storedAuth = authWindow.Result;

                    AddEntryWindow addWindow = new AddEntryWindow
                        (this, storedAuth.UserName, storedAuth.Password);
                    addWindow.ShowDialog();
                }
            }
            else
            {
                AddEntryWindow addWindow = new AddEntryWindow
                    (this, storedAuth.UserName, storedAuth.Password);
                addWindow.ShowDialog();
            }
        }

        private void tsmiClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tsmiSave_Click(object sender, EventArgs e)
        {
            // Open sfdSaveToLocation which let us choose the
            // location where we want to save the file.
            sfdSaveToLocation.ShowDialog();
        }

        private void sfdSaveToLocation_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
        {
            string theFileName = sfdSaveToLocation.FileName;

            EncryptDecrypt en = new EncryptDecrypt();

            string encrypted = en.Encrypt(txtDisplay.Text,
                storedAuth.UserName, storedAuth.Password);

            MessageBox.Show(encrypted);

            File.WriteAllText(theFileName, encrypted);
        }
    }
}

AddEntryWindow.cs

using System;
using System.Windows.Forms;
// Needed to be used with StringBuilder
using System.Text;
// Needed to be used with ArrayList.
using System.Collections;

namespace Store_Passwords_and_Serial_Codes
{
    public partial class AddEntryWindow : Form
    {
        string user, pass;

        // Initializind ArrayList to store all data needed to be added or retrived.
        private ArrayList addedEntry = new ArrayList();

        // Initializing MainWindow form.
        MainWindow mainWindow;

        // Default constructor to initialize the form.
        public AddEntryWindow()
        {
            InitializeComponent();
        }

        public AddEntryWindow(MainWindow viaParameter, string user, string pass)
            : this()
        {
            mainWindow = viaParameter;
            this.user = user;
            this.pass = pass;
        }

        private void AddEntryWindow_Load(object sender, EventArgs e)
        { }

        private void btnAddEntry_Click(object sender, EventArgs e)
        {
            // Making sure that type is selected.
            if (cmbType.SelectedIndex == -1)
            {
                MessageBox.Show("Please select entry type!", "Error!", 
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            // Each field must be filled for specified type.
            // Here we are checking if all fields were filled.
            else if ((cmbType.SelectedIndex == 0 && (txtUserName.Text == string.Empty || txtPassword.Text == string.Empty)) ||
                (cmbType.SelectedIndex == 1 && (txtURL.Text == string.Empty || txtPassword.Text == string.Empty)) ||
                (cmbType.SelectedIndex == 2 && (txtSoftwareName.Text == string.Empty || txtSerialCode.Text == string.Empty)))
            {
                MessageBox.Show("Please fill all the fields!", "Error!", 
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                int totalEntries = 0;

                if(cmbType.SelectedIndex == 0)
                    addedEntry.Add(new AddPC(cmbType.Text, 
                        txtUserName.Text, txtPassword.Text));

                else if(cmbType.SelectedIndex == 1)
                    addedEntry.Add(new AddWebSite(cmbType.Text, 
                        txtUserName.Text, txtPassword.Text, txtURL.Text));

                else if(cmbType.SelectedIndex == 2)
                    addedEntry.Add(new AddSerialCode(cmbType.Text, 
                        txtSoftwareName.Text, txtSerialCode.Text));

                StringBuilder stringBuilder = new StringBuilder();

                foreach (var list in addedEntry)
                {
                    if (list is AddPC)
                    {
                        totalEntries++;
                        AddPC tmp = (AddPC)list;
                        stringBuilder.Append(tmp.ToString());
                    }
                    else if (list is AddWebSite)
                    {
                        totalEntries++;
                        AddWebSite tmp = (AddWebSite)list;
                        stringBuilder.Append(tmp.ToString());
                    }
                    else if (list is AddSerialCode)
                    {
                        totalEntries++;
                        AddSerialCode tmp = (AddSerialCode)list;
                        stringBuilder.Append(tmp.ToString());
                    }
                }

                mainWindow.ChangeTextBox = stringBuilder.ToString();

                mainWindow.tsslStatus.Text = "A total of " + totalEntries + " entries added.";

                // Clearing all fields.
                ClearFields();
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            ClearFields();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            // Closing the Add Entry Window form.
            this.Close();
        }

        private void cmbType_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Deciding which data must be entered depending on
            // what type is selected from combo box.

            // PC
            if (cmbType.SelectedIndex == 0)
            {}
            // Web Site
            else if (cmbType.SelectedIndex == 1)
            {}
            // Serial Code
            else if (cmbType.SelectedIndex == 2)
            {}
        }

        private void ClearFields()
        {
            // Clearing all fields to the default state.
        }
    }
}

Regards.

  • 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-05-26T14:49:17+00:00Added an answer on May 26, 2026 at 2:49 pm

    It sounds like you probably just want to subscribe to the TextChanged event, which will be fired whenever the text in the textbox changes.

    I can’t say I really followed everything that you’re doing, but I think you should be fine to just enable or disable your Save button within that event handler.

    EDIT: It’s not really clear where all your different components live, but you want something like:

    // Put this after the InitializeComponent() call in the constructor.
    txtDisplay.TextChanged += HandleTextBoxTextChanged;
    
    ...
    
    private void HandleTextBoxTextChanged(object sender, EventArgs e)
    {
        bool gotText = txtDisplay.Text.Length > 0;
        menuSaveButton.Enabled = gotText;
    }
    

    I’d also strongly advise you not to use ArrayList but to use the generic List<T> type. The non-generic collections should almost never be used in new code.

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

Sidebar

Related Questions

I have a language-agnostic question about an algorithm. This comes from a (probably simple)
This question comes from a range of other questions that all deal with essentially
I am following up from this question here The problem I have is that
This question comes from my experience with the following question: https://stackoverflow.com/questions/492748/new-responses-icon-on-so-crashes-ie7-closed In that question,
A common question that comes up from time to time in the world of
This question has been puzzling me for a long time now. I come from
i have a question on a problem i am working on. I have to
I am working on a project right now that involves receiving a message from
I asked a question a while ago about which local DB was right for
I have a problem really phrasing this question so i try to give an

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.