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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:24:45+00:00 2026-06-02T20:24:45+00:00

I have written a WPF Application in C# to create checkboxes during runtime as

  • 0

I have written a WPF Application in C# to create checkboxes during runtime as the contents must be obtained from a file. The user selects the items from the checkbox. On the click of a button, all the checked items must be written to a text file. How can it be done?
Is the following code correct way to create checkboxes dynamically?

CheckBox chb;
private void radioButton2_Checked(object sender, RoutedEventArgs e)
{
    //Create file
    string fp5 = @"D:\List.txt";       

    FileStream fs = new FileStream(fp5, FileMode.Open, FileAccess.Read);
    StreamReader reader = new StreamReader(fs);

    float cby = 135.0F;
    int ControlIndex=1;

    while (!reader.EndOfStream)
    {
        string line = reader.ReadLine();
        chb = new CheckBox();
        chb.Name = "Chk" + ControlIndex;
        Canvas.SetLeft(chb, 28);
        Canvas.SetTop(chb, cby);
        chb.Content = line;
        chb.IsChecked = false;
        chb.Foreground = new SolidColorBrush(Colors.Blue);
        myCanvas.Children.Add(chb);
        cby = cby + 25.0F;
        ControlIndex++;
    }
    fs.Close();
}

private void button5_Click(object sender, RoutedEventArgs e)
{
    //Create files
    string fp6 = @"D:\List2.txt";

    if (!File.Exists(fp6))
    File.Create(fp6).Close();

    /*I want to write the checked items of the checkbox chb to the text file List2.txt.
    I wanted to know how to do this */
}
  • 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-02T20:24:46+00:00Added an answer on June 2, 2026 at 8:24 pm

    You can do this

    private void button5_Click(object sender, RoutedEventArgs e)
    {
     string str="";
     foreach (UIElement child in canvas.Children)
     {
       if(child  is CheckBox)
         if(((CheckBox)child).IsChecked)
           str+=((CheckBox)child).Content;
    
     }
     string fp6 = @"D:\List2.txt";
     File.WriteAllText(fp6,str);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have a rich client application written in WPF/WCF and are intending to create
I have a wpf application written in framework 4. The application is downloaded via
I have to modify a WPF application written in C# that displays a complex
I have a C# application of which some parts are written using WPF (which
I have written a simple WPF application in which I wanted to test the
I have an application written in wpf, which downloads some webpages, parses html code
I have a WPF application written in C#. This application has dialog windows in
I have an application written in WPF with a ScrollViewer controlling a Canvas. This
I have a WPF application that is written using MVVM Prism. It has a
I have written an application (wpf - will Mono translate this for a Mac?)

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.