locked
How to display the function values in a Rich Text box in c# windows form RRS feed

  • Question

  • I have method called Test() . I want to print its values in a Text Box. I called the mehod Test() on a ButtonClick method. But its not displaying the values.

    public void Test()
            {
                /* Flow board variable declaration */
                UInt64 frpHandle = 0;
                ushort Serial = 0;
                ushort Version = 0;

                /* Flow-rate acquisition variables */
                byte sensor_index = 0; // sensor index coresponds to flow-unit port on the flowboard from 0 to 7
                byte TimeCheck = 0;
                float flow_rate = 0;
                uint loop = 0;

                frpHandle = frp_initialization(0);
                RTBox.Text="\n FRP session initialized";
                RTBox.Refresh();

                frp_get_serial(frpHandle, ref Serial, ref Version);

                RTBox.Text = ("\n FLOWBOARD SN:" + Convert.ToInt32(Serial));
                RTBox.Refresh();

                if (Serial != 0)
                {
                    for (loop = 0; loop < 20; loop++)
                    {
                        frp_read_flow(frpHandle, sensor_index, ref TimeCheck, ref flow_rate);
                        RTBox.Text = ("\n Flow-rate:" + (flow_rate) + "\t ul/min");
                        RTBox.Refresh();

                    }
                    Thread.Sleep(100);
                };

                frp_close(frpHandle);
                RTBox.Text = ("\n FRP session closed");
                RTBox.Refresh();


            }

            private void button1_Click(object sender, EventArgs e)
            {

                Test();

            }

    • Moved by CoolDadTx Monday, November 18, 2019 2:59 PM Winforms related
    Saturday, November 16, 2019 5:47 AM

Answers

  • I have method called Test() . I want to print its values in a Text Box. I called the mehod Test() on a ButtonClick method. But its not displaying the values.



                if (Serial != 0)
                {
                    for (loop = 0; loop < 20; loop++)
                    {
                        frp_read_flow(frpHandle, sensor_index, ref TimeCheck, ref flow_rate);
                        RTBox.Text = ("\n Flow-rate:" + (flow_rate) + "\t ul/min");
                        RTBox.Refresh();

                    }
                    Thread.Sleep(100);
                };

    Try using the += operator instead of the = operator if you want to show 
    multiple lines.

    You may also need to use \r\n instead of just \n.

    RTBox.Text += ("\r\n Flow-rate:" + (flow_rate) + "\t ul/min");
    

    You may also need to set the RTB properties for multiple lines and 
    scrollbars, etc. 

    If you wanted to show the values one at a time as a single line, then you
    probably need to move the Sleep inside the for() loop and keep the = operator.

    - Wayne

    • Marked as answer by varun_bwazz Saturday, November 16, 2019 10:05 AM
    Saturday, November 16, 2019 9:31 AM