Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to change font size according to drop down list selection in c# ?

I want the user to make selection according the drop down list and it will appear on my text box.

What I have tried:

PrimaryStyle.Font.Size = FontUnit.Parse(FontSizeList.SelectedItem.Text);
            lblMessage.ApplyStyle(PrimaryStyle);
            txtMessage.ApplyStyle(PrimaryStyle);
Posted
Updated 18-Dec-17 7:13am
Comments

1 solution

html code bellow

<br /><br /><br />
      <asp:Label ID="lblMessage" runat="server" Text="this is the text for testing"></asp:Label>
       <br /><br />
       <div>
            <asp:DropDownList ID="ddlfont" runat="server"  AutoPostBack="true" OnSelectedIndexChanged="ddlfont_SelectedIndexChanged">
               <asp:ListItem Text="10" Value="10"></asp:ListItem>
               <asp:ListItem Text="12" Value="12"></asp:ListItem>
               <asp:ListItem Text="14" Value="14"></asp:ListItem>
           </asp:DropDownList>

       </div>


Code behind is bellow


private Style primaryStyle = new Style();
      protected void Page_Load(object sender, EventArgs e)
      {

      }

      protected void ddlfont_SelectedIndexChanged(object sender, EventArgs e)
      {
          primaryStyle.Font.Size = FontUnit.Parse(ddlfont.SelectedItem.Text);
          lblMessage.ApplyStyle(primaryStyle);

      }
 
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