Member Avatar for Falcon25

Hi guys happy new year, hope you all have a great year ahead of you

Anyway I'm a little bit stuck on a question and thought I'll ask for a bit of help:

So I'm using a Windows Forms Application and the user types in some text within a textbox, then you can click on a radio button that says 'to Upper Case' or another one which says 'to Lower Case' and it simply changes that text within a label. It seems quiet simple so apologies for asking I just can't seem to get it.

So far I have this:

private void upperCaseButton_CheckedChanged(object sender, EventArgs e)
        {
            string userText;

            userText = inputTextBox.Text;

            if (userText == "")
                MessageBox.Show("Please enter some text");
            else
                userText.Font = new Font(userText.Font, userText, Font.Style ^ FontStyle.Uppercase); 
        }

But this does not work obviously because Uppercase is not apart of Font Style, its the only thing I know to do for this question. Any help is much appreciated :)

You can use the CharacterCasing property of the text box control.

private void upperCaseButton_CheckedChanged(object sender, EventArgs e)
        {
            string userText;

            if (userText == "")
                MessageBox.Show("Please enter some text");
            else
                inputTextBox.CharacterCasing = CharacterCasing.Upper;

            userText = inputTextBox.Text;
        }

It's an enum with 3 elements:

Upper
Lower
Normal

public enum CharacterCasing
{
Normal,
Upper,
Lower
}

Your welcome. :)

Member Avatar for Falcon25

Hey man thanks for your quick response unfortunately I was getting an error in this line of code

inputTextBox.CharacterCasing = CharacterCasing.Upper;

so I started just messing around with the problem and eventually got it too work. I'll post it on here below encase anyone needs to know and then mark it as solved

private void upperCaseButton_CheckedChanged(object sender, EventArgs e)
        {
            string userText;

            userText = inputTextBox.Text;

            if (userText == "")
                MessageBox.Show("Please enter some text");
            else
                outputLabel.Text = userText.ToUpper();            
        }

Okay well here's the code that I tested it with to make 100% sure. It's set up on a timer to change the text back and forth to Upper and Lower.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            this.timer1.Interval = 700;
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
            this.Load += new System.EventHandler(this.Form1_Load);
        }

        private System.Windows.Forms.Timer timer1;

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (textBox1.CharacterCasing == CharacterCasing.Upper)
                textBox1.CharacterCasing = CharacterCasing.Lower;

            else if (textBox1.CharacterCasing == CharacterCasing.Lower)
                textBox1.CharacterCasing = CharacterCasing.Upper;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.CharacterCasing = CharacterCasing.Upper;
            timer1.Start();
        }
    }
}
commented: Very helpful, works great thanks man! +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.