Click here to Skip to main content
16,019,764 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All

I want to find TextBox control in among all the forms of current project and change their fonts.
I want solution coding with c# windows application.

If possible please give me solution step by step because i m fresher in programming.
Thanks to all

Ruchik.
Posted
Updated 31-Mar-11 2:59am
v3

I don't understand exactly what you want. If you want to change the font in all of the TextBox controls in a solution/project, I'm afraid you're going to have to do that one control at a time in the designer. I'm not saying this because it's impossible to write another app that parses the source files for you, but because you have to SEE what the change is going to do in the form with ragards to the relative position of the other controls that are also on the same form (not to mention the form itself).

Now, if you want to programatically change the font on all of the tTextBox controls on a form, you can easily do that, but that doesn't preclude you from having to consider the same positioning and soize ramifications already described.

Lastly, a demand for code typically doesn't go over very well here, no matter how much of a code virgin you are. If you want to programatically change the font in a control, this is something like the way I'd do it:

C#
private void ChangeFontInTextBoxes(Control container)
{
    foreach (Control ctrl in container.Controls)
    {
        if (ctrl is TextBox)
        {
            // set the font or other desired properties
        }
        else
        {
            if (ctrl.HasChildren)
            {
                ChangeFontInTextBoxes(ctrl);
            }
        }
    }
}


and I'd call it from the form like this:

C#
ChangeFontInTextBoxes(this);


The code above uses recursion (google it).
 
Share this answer
 
Instead of searhing the controls, I suggest to create your own TextBox class, to set its Font property in the construtor, and use this custom control in all your forms:

class MyTextBox : TextBox
{
    public MyTextBox()
    {
        Font = ...;
    }
}
 
Share this answer
 
If you haven't explicitly set the Font on a control (including a TextBox), it will inherit it from its parent container. Thus, to change the font for a whole form (including all the subcontrols with default font attributes), you just need to set Font on the form. The same thing works with other container controls (like Panels and GroupBoxes) too, I believe.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900