Click here to Skip to main content
13,050,617 members (93,739 online)
Rate this:
Please Sign up or sign in to vote.
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 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 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!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 2 Nov 2012
Copyright © CodeProject, 1999-2017
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