using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using Cx.Attributes; using Cx.EventArgs; using Cx.Interfaces; using Cx.WinForm; namespace Cx.Designer.Components { [CxComponentName("CxEventLogger")] public partial class CxEventLogger : UserControl, ICxVisualComponentClass { protected bool floatingWindow; protected Form modelessDlg; protected DataTable dtLog; [CxComponentProperty] public bool FloatingWindow { get { return floatingWindow; } set { floatingWindow = value; } } public CxEventLogger() { InitializeComponent(); dtLog = new DataTable(); dtLog.Columns.Add(new DataColumn("Timestamp")); dtLog.Columns.Add(new DataColumn("Producer")); dtLog.Columns.Add(new DataColumn("Consumer")); dtLog.Columns.Add(new DataColumn("Data")); dgvEventLog.DataSource = dtLog; Dock = DockStyle.Fill; btnClear.Click += new EventHandler(OnClear); } public void Register(object form, ICxVisualComponent component) { if (floatingWindow) { modelessDlg = new Form(); modelessDlg.Text = "Event Logger"; modelessDlg.Controls.Add(this); modelessDlg.Size = new Size(425, 300); modelessDlg.Show(); } else { this.RegisterControl((Form)form, component); } } [CxConsumer] public void LogEvent(object sender, CxEventArgs<string> args) { string msg = args.Data; string[] prodCons = msg.Split(','); DataRow row = dtLog.NewRow(); row[0] = System.DateTime.Now.ToString("hh:mm:ss.fff"); row[1] = prodCons[0].Trim(); row[2] = prodCons[1].Trim(); row[3] = prodCons[2].Trim(); dtLog.Rows.Add(row); } protected void OnClear(object sender, System.EventArgs e) { dtLog.Rows.Clear(); } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)