Click here to Skip to main content
Rate this: bad
good
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 2:18am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use This code..
 
In form2,at save button click..
 
Session["listoffonts"]=combobox1.SelectedValue.ToString();
Session["listoffontsize"]=combobox2.SelectedValue.ToString();
 

In Form1 Page_load
 
label1.Text=Session["listoffonts"].ToString();
label2.Text=Session["listoffontsize"].ToString();
  Permalink  
v2
Comments
Sharath2790 at 5-Nov-12 3:49am
   
I can't use it because My VS doesn't support system.web.Http......
Rate this: bad
good
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;
objForm1.Show();
  Permalink  
Comments
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
good
Please Sign up or sign in to vote.

Solution 3

I am vb.net 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 | :)
  Permalink  
v3

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

  Print Answers RSS
0 OriginalGriff 359
1 Maciej Los 290
2 Sergey Alexandrovich Kryukov 230
3 Shweta N Mishra 185
4 PIEBALDconsult 149
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 2 Nov 2012
Copyright © CodeProject, 1999-2014
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