Click here to Skip to main content
15,563,763 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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...???

Use This code..

In form2,at save button click..


In Form1 Page_load

Share this answer
Sharath2790 5-Nov-12 3:49am    
I can't use it because My VS doesn't support system.web.Http......
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;
Share this answer
Sharath2790 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 ..
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!
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