Click here to Skip to main content
11,715,043 members (62,690 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# VS2010 font
My application has two forms(form1,form2).. Form1 has 3 labels. form2 has 2 comboboxes(combobox1,combobox2) and save button. combobox1 is for list of fonts and combobox2 for list of fontsizes. After selecting required font.. How do i assign it to the labels in the form1...???
Posted 2-Nov-12 1:18am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use This code..

In form2,at save button click..


In Form1 Page_load

Sharath2790 at 5-Nov-12 3:49am
I can't use it because My VS doesn't support system.web.Http......
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

first in Form1.Designer.cs, make all three labels declarations as "public".

in Form2 if from Combbox font selected is "Calibri", then on Save click, write below code. Jst replace "Calibri" with whichever font selected.
Font objFont = new Font("Calibri", 9, FontStyle.Bold);
Form1 objForm1 = new Form1();
objForm1.label1.Font = objFont;
objForm1.label2.Font = objFont;
objForm1.label3.Font = objFont;
Sharath2790 at 5-Nov-12 3:48am
Using objForm1.Show() makes Form1 to appear twice... My Form1 has a Audio element But When I try to hide it Audio keeps playing And even the new form (ie, Form1) appears ..
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

I am developer not so fluent in C#
sorry if any mistake in code-blocks,

but process should like below...,

create a class LookNFeel
create static 'NewFont' variable so, that in your application it can work as global variable... and you can retrieve it in other forms easily.
public class LookNFeel
   Public static Font NewFont = New Font("Arial", 12);
   Public static SetFont(string FontName,int as fontsize)
       NewFont = New Font(FontName, fontsize); //Make sure passing correct font name

Now, from Form1 when click button call function to set font in global NewFont variable
LookNFeel.SetFont(ComboFontNm.Text, convert.ToInt32(ComboFontsize.Text));

in Form2's Load event set font like this
foreach (Control c in this.Controls)
    c.font = LookNFeel.NewFont;

Happy Coding!
Smile | :)

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 530
1 Richard MacCutchan 275
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 115
0 Sergey Alexandrovich Kryukov 775
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320

Advertise | Privacy | Mobile
Web02 | 2.8.150901.1 | Last Updated 2 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100