locked
how to get previous values of the textbox? RRS feed

  • Question

  • Hi,

    I want to write a code in which if the calculated values present in the text box is changed then the text box should turn green if the value is increases and should turn red if the value is decreased. i am not able to figure out how to compare the current values with the previous one.

    Sunday, January 19, 2014 8:41 AM

Answers

  • how to get previous values of the textbox? 

    you can use List<string> to save your text

    when  the text box is changed add new string to List<string>

    The following C # code and the same concept :

    List<string> history_list;
    private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
    {
        history_list.Add(((TextBox)sender).Text);
    }

    • Edited by SUKI Huang Sunday, January 19, 2014 10:48 AM
    • Marked as answer by Anna Cc Saturday, January 25, 2014 4:55 PM
    Sunday, January 19, 2014 10:48 AM
  • Hi prog_begner,

    According to your description, you want to compare two value and change the color of the box according to the result.

    In general, we use edit control instead of textbox in MFC application. Textbox is a toolbox of winform appllication. 

    "i am not able to figure out how to compare the current values with the previous one."

    Here, I use edit control as an example. I suggest you create a varible m_save_edit. And the value of m_save_edit is the same as the edit control. The code snippet is below:

    void CMFCcolorDlg::OnBnClickedOk()
    {
    	UpdateData(true);
              if(m_save_edit > m_edit)
              {
               //change the color of control to red
              }
              if(m_save_edit < m_edit)
              {
               //change the color of control to green
              }
              
    	m_save_edit = m_edit;
    
    }

    To change the background color of an MFC edit control, please refer to this kb:

    http://support.microsoft.com/kb/117778/en-us

    Best regards,

    Sunny


    • Edited by Anna Cc Thursday, January 23, 2014 4:01 AM
    • Proposed as answer by Renjith V Ramachandran Thursday, January 23, 2014 6:20 AM
    • Marked as answer by Anna Cc Saturday, January 25, 2014 4:55 PM
    Thursday, January 23, 2014 4:00 AM
  • You can use GetWindowText() also. Refer sample in SetWindowText()

    Thanks, Renjith V R

    • Marked as answer by Anna Cc Saturday, January 25, 2014 4:55 PM
    Thursday, January 23, 2014 6:22 AM

All replies

  • Hi,

    I want to write a code in which if the calculated values present in the text box is changed then the text box should turn green if the value is increases and should turn red if the value is decreased. i am not able to figure out how to compare the current values with the previous one.

    I'm not sure what this has to do with parallel computing.

    What kind of application is this?

    But basically, process the change notification for the control, and each time you do so put the new value in a member variable. Compare this member variable with the new value before updating it.


    David Wilkinson | Visual C++ MVP

    Sunday, January 19, 2014 10:38 AM
  • how to get previous values of the textbox? 

    you can use List<string> to save your text

    when  the text box is changed add new string to List<string>

    The following C # code and the same concept :

    List<string> history_list;
    private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
    {
        history_list.Add(((TextBox)sender).Text);
    }

    • Edited by SUKI Huang Sunday, January 19, 2014 10:48 AM
    • Marked as answer by Anna Cc Saturday, January 25, 2014 4:55 PM
    Sunday, January 19, 2014 10:48 AM
  • Hi prog_begner,

    According to your description, you want to compare two value and change the color of the box according to the result.

    In general, we use edit control instead of textbox in MFC application. Textbox is a toolbox of winform appllication. 

    "i am not able to figure out how to compare the current values with the previous one."

    Here, I use edit control as an example. I suggest you create a varible m_save_edit. And the value of m_save_edit is the same as the edit control. The code snippet is below:

    void CMFCcolorDlg::OnBnClickedOk()
    {
    	UpdateData(true);
              if(m_save_edit > m_edit)
              {
               //change the color of control to red
              }
              if(m_save_edit < m_edit)
              {
               //change the color of control to green
              }
              
    	m_save_edit = m_edit;
    
    }

    To change the background color of an MFC edit control, please refer to this kb:

    http://support.microsoft.com/kb/117778/en-us

    Best regards,

    Sunny


    • Edited by Anna Cc Thursday, January 23, 2014 4:01 AM
    • Proposed as answer by Renjith V Ramachandran Thursday, January 23, 2014 6:20 AM
    • Marked as answer by Anna Cc Saturday, January 25, 2014 4:55 PM
    Thursday, January 23, 2014 4:00 AM
  • You can use GetWindowText() also. Refer sample in SetWindowText()

    Thanks, Renjith V R

    • Marked as answer by Anna Cc Saturday, January 25, 2014 4:55 PM
    Thursday, January 23, 2014 6:22 AM