using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace arinc_1553_CSharpGUI
{
    public partial class BuiltInTestForm : Form
    {
        /// Delegate function to use for message update in GUI
        public delegate void MessageUpdateDelegate(string msgString);

        /// The delegated method for updating message
        public MessageUpdateDelegate mMessageDelegate;

        MainForm pFormMain;

        public BuiltInTestForm(MainForm pFormMainHdl)
        {
            InitializeComponent();

            //Create the delegate for the message update.
            mMessageDelegate = new MessageUpdateDelegate(UpdateMessage);

            richTextBox1.Clear();
            pFormMain = pFormMainHdl;
        }

        /*******************************************************************************
         * Name:    UpdateMessage
         *
         * Description:
         *
         *      This is a delegate handler for the message posted by 
         * 
         * The handler processes the received message for user-friendly display 
         * in the GUI 
         *
         ******************************************************************************/
        private void UpdateMessage(string msgString)
        {
            richTextBox1.AppendText(msgString);
        }

        private void buttonClearDisp_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
        }

        private void BuiltInTestForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Hide();
        }

        private void button_MainForm_Click(object sender, EventArgs e)
        {
            this.Hide();
            pFormMain.Show();
        }
    }
}
