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

  • Home
  • SEARCH
  • 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 8211435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:25:34+00:00 2026-06-07T10:25:34+00:00

I have been working on this project for a few days, it’s a C#

  • 0

I have been working on this project for a few days, it’s a C# Windows Visual Studio 2010 form and I have been posting different questions that relate to the same project; as I was told to post different questions instead on having them all in the same post. So this is the project: create a form with two ListBoxes—one contains at least four font names and the other contains at least four font sizes. Let the first item in each list be the default selection if the user fails to make a selection. Allow only one selection per ListBox. After the user clicks a button, display “Hello” in the selected font and size.
This time I’m having a problem getting the message in the textbox to display according to the font type and size that the user selected. Here is where I’m at in the coding:

    public Form1()
    {
        InitializeComponent();

        //populate listbox1
        listBox1.Items.Add("Arial");
        listBox1.Items.Add("Calibri");
        listBox1.Items.Add("Times New Roman");
        listBox1.Items.Add("Verdana");

        //populate listbox2
        listBox2.Items.Add("8");
        listBox2.Items.Add("10");
        listBox2.Items.Add("12");
        listBox2.Items.Add("14");

        this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
        listBox1.SelectedIndex = 0; // <--- set default selection for listBox1 

        this.listBox2.SelectedIndexChanged += new System.EventHandler(this.listBox2_SelectedIndexChanged);
        listBox2.SelectedIndex = 0; // <--- set default selection for listBox2

    }

    private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
    {

        textBox1.Text = listBox1.SelectedItem.ToString();
    }

    private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
    {
        textBox1.Text = listBox2.SelectedItem.ToString();
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        textBox1.Text = "Hello!"; 
    }

    private void button1_Click(object sender, EventArgs e)
    {

    }
}

}

Now I’m trying to elicit a call from a button clicked that will display the message “Hello” in the user’s choice of font and font size. Any suggestions would be greatly appreciated.

  • 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-07T10:25:36+00:00Added an answer on June 7, 2026 at 10:25 am

    remove this method:

     private void textBox1_TextChanged(object sender, EventArgs e)
    {
        textBox1.Text = "Hello!"; 
    }
    

    in the button_click event of your button, add this :

      private void button1_Click(object sender, EventArgs e)
        {
        textBox1.Text = "hello";       
        textBox1.Font = new Font(listBox1.SelectedItem.ToString(), Convert.ToInt32(listBox2.SelectedItem.ToString()));  
        }
    

    you might want to remove the selectedindexchanged methods in your code if you are going to use a button tho. depends on what you want.

    edit:

     public Form2()
        {
            InitializeComponent();
            listBox1.Items.Add("Arial");
            listBox1.Items.Add("Calibri");
            listBox1.Items.Add("Times New Roman");
            listBox1.Items.Add("Verdana");
    
            listBox2.Items.Add("8");
            listBox2.Items.Add("10");
            listBox2.Items.Add("12");
            listBox2.Items.Add("14");
            listBox1.SelectedIndex = 0;
            listBox2.SelectedIndex = 0;
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
        textBox1.Text = "hello";       
        textBox1.Font = new Font(listBox1.SelectedItem.ToString(), Convert.ToInt32(listBox2.SelectedItem.ToString()));  
        }
    

    if you just use the above code everything should work as you want it to. I tried it out myself and it’s working fine for me

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

Sidebar

Related Questions

I have been working on a project for a few days now and have
I've been working on this project for a few days and I really haven't
Morning, I have been working on this problem for a few days and cannot
So I have been working on this project for a short while now. I
I have been working on this for few hours and got stuck, so how
I have been working on this problem for 2 days now and it's an
I have been working on this for days but I don't get it so
Afternoon, I have been working with CKEditor and CKFinder for the last few days
I have been working at a few different companies now and every one has
I have been working on a side project for the last few weeks, and

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.