locked
Unable to change fontstyle in VS2005 using C# RRS feed

  • Question


    • Edited by xyz007 Tuesday, August 2, 2011 5:51 PM
    • Changed type xyz007 Tuesday, August 2, 2011 5:52 PM Hi,
    • Changed type xyz007 Tuesday, August 2, 2011 5:52 PM
    • Moved by CoolDadTx Monday, August 8, 2011 1:16 PM Not IDE related (From:Visual C# IDE)
    Monday, August 1, 2011 9:22 PM

All replies

  • Can you place the code here which is giving the problem ?
    Tuesday, August 2, 2011 3:03 PM
  • Hi

    Do you mean the fontstyle of code or some displayed text? If you are talking about the text, please post the code which doesn't work.


    Cookie Luo[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, August 3, 2011 1:53 AM
  • The following code is working

    this.Font = new Font(this.Font, FontStyle.Underline);

    Show me your code.
    Wednesday, August 3, 2011 1:30 PM
  • ·         Hi,

    I am trying to change font style of label text using user's choice(windows form (VS 2005)) using C#. I have list box having font names like "Arial" etc.. Radio buttons for font size and check box for font style . Everything works fine except font styles. When I check bold check box font style gets bold, and when italic it gets italic. But the problem is when I uncheck its not getting Unbold and etc. Please let me know the logical query for it.

    My query is as below

    private System.Drawing.Font myfont;

    privateint fontsize = 16;

    privatestring fontname ="arial";

    private System.Drawing.FontStyle mystyle = System.Drawing.FontStyle.Regular;

    publicvoid assignfont()

    {

    //uses variables to assign font

    fontname = listBox1.Text;

    //assigning fontstyle through check box

    if (checkBox1.Checked)

    mystyle = mystyle | System.Drawing.

    FontStyle.Bold;

    if (checkBox2.Checked)

    mystyle = mystyle | System.Drawing.

    FontStyle.Italic;

    if (checkBox3.Checked)

    mystyle = mystyle | System.Drawing.

    FontStyle.Underline;

    myfont =

    new System.Drawing.Font(fontname, fontsize, mystyle);

    label1.Font = myfont;

    }

    In form the query is

    privatevoid listBox1_SelectedIndexChanged(object sender,EventArgs e)

    {

    assignfont();

    }

    privatevoid radioButton1_CheckedChanged(object sender,EventArgs e)

    {

    fontsize = 8;

    assignfont(); }

    privatevoid radioButton2_CheckedChanged(object sender,EventArgs e)

    {

    fontsize = 10;

    assignfont();

    }

    privatevoid radioButton3_CheckedChanged(object sender,EventArgs e)

    {

    fontsize = 12;

    assignfont();

    }

    privatevoid checkBox1_CheckedChanged(object sender,EventArgs e)

    {

    assignfont();

    }

    privatevoid checkBox3_CheckedChanged
    Wednesday, August 3, 2011 2:18 PM
  • Hi

    Please post the code about your CheckedChanged events. There must be some logic problems.


    Cookie Luo[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, August 4, 2011 2:34 AM
  • Have you set the "AutoPostback" property of the checkboxes and radiobuttons to "true"?

    If you have please check whether there is any Updatepanel.


    Regards, digital
    Success is 3-D coz it demands Desire, Determination and Dedication.
    Thursday, August 4, 2011 10:00 AM