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...???
Posted

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();
 
Share this answer
 
v2
Comments
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.
C#
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();
 
Share this answer
 
Comments
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 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.
C#
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
C#
LookNFeel.SetFont(ComboFontNm.Text, convert.ToInt32(ComboFontsize.Text));


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


Happy Coding!
:)
 
Share this answer
 
v3

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