C# [Win App] - Regarding changing font of a TextBox Dynamically.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NIKHILUNNIKRISHNAN
    New Member
    • Jun 2008
    • 22

    C# [Win App] - Regarding changing font of a TextBox Dynamically.

    Experts,

    I have a textbox which displays some contents in some font. I am providing the user a dialog which will provide him the options to change the font. The change is getting refelcted only when the user restarts the application.I want to change the font of the text box dynamically; ie; when the user selects the new font,it should be displayed in that font, just like "NotePad". How can I do that ?



    With advance thanks and regards
    Nikhil Unnikrishnan K
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Show us the code you are using currently to change the font.

    Comment

    • NIKHILUNNIKRISHNAN
      New Member
      • Jun 2008
      • 22

      #3
      Hi,

      Code:
      private void SaveUISettings(UIConfig uiConfig)
              {
                  uiConfig.EditorFontString = editorFontTextBox.Text;
                  uiConfig.LogViewerFontString = logViewerFontTextBox.Text;
              }
      .
      .
      .
      public void CallSaveUISettings(UIConfig uiConfig)
              {
                 editorFontTextBox.Font = uiConfig.EditorFont;
                 logFileNameTextBox.Font = uiConfig.LogViewerFont;
                 SaveUISettings(uiConfig);
              }
      These are the two major areas where code changing occurs. But the font change effects only when we restart the application. Why it is not happening instantly ?
      Last edited by Curtis Rutland; Oct 14 '08, 01:57 PM. Reason: use [CODE] [/CODE] tags when posting code

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #4
        Please remember to use [CODE] tags when you post code. This is a requirement on this forum.

        MODERATOR

        Comment

        • mldisibio
          Recognized Expert New Member
          • Sep 2008
          • 191

          #5
          That code does not say very much...you are saving the TextBox string in one function and setting the Font in another...we do not see where you create the Font from the string.

          Nonetheless, at first glance it looks like you are setting the Font with the old settings, and then saving the new Font to uiConfig afterwards, which would explain why the Font change does not happen until you re-start, where it reads the last Font you saved.

          If you are using uiConfig to set the Font, then try saving the new settings to uiConfig first and then setting the Font.

          Comment

          • NIKHILUNNIKRISHNAN
            New Member
            • Jun 2008
            • 22

            #6
            Hi,

            The "SaveUISettings " will be always having the latest provided font from uiConfig. It is saving the latest font only. Then it is using the same font to display in the text box. That is why I am confused !

            Comment

            • NIKHILUNNIKRISHNAN
              New Member
              • Jun 2008
              • 22

              #7
              I am adding the following piece of code to do the same when restart button is clicked. [Restart button restarts the application].

              Code:
              private void menuItemRestart_Click(object sender, System.EventArgs e)
              		{
                          Stop();
                          UIConfig uiConfig = new UIConfig();
                          IapetusConfig iaConfig = new IapetusConfig();
                          InitializeHSMS();
                          logViewerForm.Font = this.config.UIConfig.LogViewerFont;
                          uiConfig.EditorFont = this.config.UIConfig.EditorFont;
                      }
              
              
              .
              .
              .
              .
              .
              .
              
               private void SaveUISettings(UIConfig uiConfig)
                      {
                          uiConfig.EditorFontString = editorFontTextBox.Text;
                          uiConfig.LogViewerFontString = logViewerFontTextBox.Text;
                      }
              
                   
               public void CallSaveUISettings(UIConfig uiConfig)
                      {
                         editorFontTextBox.Font = uiConfig.EditorFont;
                         logFileNameTextBox.Font = uiConfig.LogViewerFont;
                         SaveUISettings(uiConfig);
                      }
              I am getting the desired results only when the application is closed and restarted.

              Comment

              • mldisibio
                Recognized Expert New Member
                • Sep 2008
                • 191

                #8
                I am suggesting you try this:

                Code:
                 public void CallSaveUISettings(UIConfig uiConfig)
                {
                  SaveUISettings(uiConfig);
                  editorFontTextBox.Font = uiConfig.EditorFont;
                  logFileNameTextBox.Font = uiConfig.LogViewerFont;
                }

                Comment

                • NIKHILUNNIKRISHNAN
                  New Member
                  • Jun 2008
                  • 22

                  #9
                  Hi,

                  Can any one give any alternate plans ?

                  Comment

                  Working...