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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:08:42+00:00 2026-06-10T18:08:42+00:00

I am creating a simple program to track notes into a text file. I

  • 0

I am creating a simple program to track notes into a text file. I have everything working correctly except for the checkboxes. I need it where you can select which checkboxes you want and it writes to the file on the same line. If no checkboxes are selected or only some of them it will go to next line as well. Below is the code i currently have and it works fine so far except if i use Writeline on each checkbox statement obviously it puts each checkbox text on a new line. If i use only Write it works except the “tshooting_text.Text ends up on the same line as the checkboxes text. I am a bit new to C# and programming in general so please forgive me if i am missing something simple. Anyway here is the code i have so far.

private void copy_clipboard_button_Click(object sender, EventArgs e)
{

    //Starts the file writer
    using (StreamWriter sw = new StreamWriter("C:\\INET Portal Notes.txt"))
    {
        string CBRSame = cust_btn_text.Text;
        if (cbr_same.Checked)
        {
            cust_callback_text.Text = CBRSame;
        }

        //Writes textboxes to the file
        sw.WriteLine("**Name: " + cust_name_text.Text);
        sw.WriteLine("**BTN: " + cust_btn_text.Text);  
        sw.WriteLine("**CBR: " + cust_callback_text.Text);
        sw.WriteLine("**Modem: " + cust_modem_text.Text);
        //Statements to write checkboxes to file
        if (checkbox_pwr.Checked)
            sw.Write("**Lights: PWR, ");
        if (checkbox_e1.Checked)
            sw.Write("E1, ");
        if (checkbox_e2.Checked)
            sw.Write("E2, ");
        if (checkbox_e3.Checked)
            sw.Write("E3, ");
        if (checkbox_e4.Checked)
            sw.Write("E4, ");
        if (checkbox_wlan.Checked)
            sw.Write("WLAN, ");
        if (checkbox_dsl.Checked)
            sw.Write("DSL, ");
        if (checkbox_dslblink.Checked)
            sw.Write("DSL Blinking, ");
        if (checkbox_inet.Checked)
            sw.Write("INET, ");
        if (checkbox_inetred.Checked)
            sw.Write("INET RED, ");

        //Continues textboxes to file
        sw.WriteLine("**Troubleshooting: " + tshooting_text.Text);
        sw.WriteLine("**Services Offered: " + services_offered_text.Text);
        sw.WriteLine("**Other Notes: " + other_notes_text.Text);
        sw.Flush();
    }
}
  • 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-10T18:08:43+00:00Added an answer on June 10, 2026 at 6:08 pm

    My suggestion is the following:

    1. Put all your CheckBox controls inside a Panel control, let’s call it pnlCheckBoxes.
    2. Input desired indicator to CheckBox‘s Tag property (at design time).
    3. Order check boxes if needed.
    4. Enumerate all the checkboxes and write the output text for each one.

    This way, you will be able to easily add/remove check boxes and not need to modify your code to reflect these changes.

    Here’s how you can order your check boxes inside Panel control (be sure not to modify the rest of the code if you not sure about it). Modify the code in your Form1.designer.cs file:

    // 
    // pnlCheckBoxes
    //
    // Rearrange the lines below to match the order you desire
    this.pnlCheckBoxes.Controls.Add(this.checkBoxWlan);
    this.pnlCheckBoxes.Controls.Add(this.checkBoxDsl);
    // Leave the lines below intact.
    this.pnlCheckBoxes.Location = new System.Drawing.Point(21, 110);
    this.pnlCheckBoxes.Name = "pnlCheckBoxes";
    this.pnlCheckBoxes.Size = new System.Drawing.Size(200, 100);
    this.pnlCheckBoxes.TabIndex = 6;
    

    Here’s the code of your writer function (after placing check boxes in panel, assigning Tag properties to them and arranging them):

    private void copy_clipboard_button_Click(object sender, EventArgs e)
    {
        //Starts the file writer
        using (StreamWriter sw = new StreamWriter("C:\\INET Portal Notes.txt"))
        {
            /* ... */
    
            //Statements to write checkboxes to file
    
            // This variable will store your whole line for check boxes.
            string checkBoxesLine = "**";
    
            // Enumerate all controls in panel.
            foreach (Control control in pnlCheckBoxes.Controls)
            {
                // Make sure the control is CheckBox, ignore others.
                if (control is CheckBox)
                {
                    // Cast it to CheckBox variable, to make it easier to work with.
                    CheckBox checkBox = (CheckBox)control;
    
                    // Make sure it is checked, and if it is, make sure that the Tag property
                    // has been set to string, so that we can get it's ID (WLAN, DSL, etc.).
                    if (checkBox.Checked && checkBox.Tag is string)
                    {
                        // Cast tag to string.
                        string checkBoxId = (string)checkBox.Tag;
                        // Append tag and comma to the end of the line.
                        checkBoxesLine += string.Format("{0}, ", checkBoxId);
                    }
                }
            }
    
            // That's it, we have the whole line, write it as a new line.
            sw.WriteLine(checkBoxesLine);
    
            //Continues textboxes to file
            /* ... */ 
        }
    }
    

    The code above can be shortened, but since you’re new to C#, I’ve tried to explain as much as I could.

    Although the answer is a bit out of the scope of the question, I have demonstrated several functionalities here – enumerating controls, casting objects, formatting strings – and I hope you will find these useful in your future C# projects.

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

Sidebar

Related Questions

I'm creating a simple file walker to list some files and need to omit
We have a fairly simple program that's used for creating backups. I'm attempting to
I have made a program in Flex for creating simple schedules, similar to MS
Hi i have made a simple program that plays a video file, i used
I'm working on a simple lex program for class, and in it I'm creating
I have eth0 and eth1. I am creating a simple tcp program with gsoap.
So I'm working on creating a very simple C program that just preforms shell
I'm creating an virtual stamp card program for the iphone and have run into
I'm having big problems while creating a simple program in C. I have the
I'm creating a simple program with the possibility to change the language and 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.