Archive Browser
Download KeyboardSupportDemo.zip version 1.0.0.0, last updated 04/06/2016 (10.17 KB)
Download- md5: 90e557815ee49f581745ed334ea2d9ed
- sha1: 3fbc13752142394a4c4dcab84de6ffce94de3b4f
- sha256: eb014fe61a006edcbe89107bc437dd99b3910badf471f20dc30d79fd7edbc743
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
namespace Cyotek.Windows.Forms.Demo
{
// Cyotek ImageBox
// Copyright (c) 2010-2015 Cyotek Ltd.
// http://cyotek.com
// http://cyotek.com/blog/tag/imagebox
// Licensed under the MIT License. See license.txt for the full text.
// If you use this control in your applications, attribution, donations or contributions are welcome.
internal class EventsListBox : ListBox
{
#region Constructors
public EventsListBox()
{
base.IntegralHeight = false;
base.HorizontalScrollbar = true;
}
#endregion
#region Properties
[DefaultValue(true)]
public new bool HorizontalScrollbar
{
get { return base.HorizontalScrollbar; }
set { base.HorizontalScrollbar = value; }
}
[DefaultValue(false)]
public new bool IntegralHeight
{
get { return base.IntegralHeight; }
set { base.IntegralHeight = value; }
}
#endregion
#region Methods
public void AddEvent(string eventName)
{
this.AddEvent(eventName, null);
}
public void AddEvent(string eventName, IDictionary<string, object> values)
{
this.AddEvent(null, eventName, values);
}
public void AddEvent(Control sender, string eventName)
{
this.AddEvent(sender, eventName, EventArgs.Empty);
}
public void AddEvent(Control sender, string eventName, EventArgs args)
{
IDictionary<string, object> values;
values = new Dictionary<string, object>();
foreach (PropertyInfo pi in args.GetType().GetProperties())
{
object value;
if (pi.GetIndexParameters().Length == 0)
{
try
{
value = pi.GetValue(args, null);
}
catch
{
// ignore errors
value = null;
}
}
else
{
// Not going to try and handler indexers
value = null;
}
values.Add(pi.Name, value);
}
this.AddEvent(sender, eventName, values);
}
public void AddEvent(Control sender, string eventName, IDictionary<string, object> values)
{
StringBuilder eventData;
eventData = new StringBuilder();
eventData.Append(DateTime.Now.ToLongTimeString());
eventData.Append('\t');
if (sender != null)
{
eventData.Append(sender.Name);
eventData.Append('.');
}
eventData.Append(eventName);
eventData.Append('(');
if (values != null)
{
int index;
index = 0;
foreach (KeyValuePair<string, object> value in values)
{
eventData.Append(value.Key);
eventData.Append(" = ");
eventData.Append(value.Value);
if (index < values.Count - 1)
{
eventData.Append(", ");
}
index++;
}
}
eventData.Append(')');
this.Items.Add(eventData.ToString());
this.TopIndex = this.Items.Count - this.ClientSize.Height / this.ItemHeight;
}
public void Attach(object obj)
{
// TODO: Isn't workig with events that use custom delegates
//foreach (EventInfo eventInfo in obj.GetType().
// GetEvents())
//{
// EventHandler handler;
// handler = (sender, args) => this.HandleEvent(eventInfo.Name, sender, args);
// eventInfo.AddEventHandler(obj, handler);
//}
}
private void HandleEvent(string eventName, object sender, EventArgs e)
{
this.AddEvent((Control)sender, eventName, e);
}
#endregion
}
}
Donate
This software may be used free of charge, but as with all free software there are costs involved to develop and maintain.
If this site or its services have saved you time, please consider a donation to help with running costs and timely updates.
Donate