Ok now I understand ya!
And yes, I agree. It is bad programming practice. A GUI is just to present information to the user. You should never use it to store things you actually use in your working code.
My suggestion: Make a small Hotkey class that holds your information. And store that in a List<Hotkey>.
Example:
Code:
public class Hotkey
{
public static List<Hotkey> Hotkeys = new List<Hotkey>();
public string ModifierPressed { get; set; }
public int KeyCode { get; set; }
public string Key { get; set; }
public string ModifierToSend { get; set; }
public string SendTo { get; set; }
public string WhoTo { get; set; }
public string SpecialCommands { get; set; }
public static void LoadHotkeys(string inputFilePath)
{
if (File.Exists(inputFilePath))
{
using (TextReader tr = new StreamReader(inputFilePath))
{
string line = tr.ReadLine();
while (!string.IsNullOrEmpty(line))
{
string[] hotkeyInfo = line.Split(new[] {':'}, StringSplitOptions.RemoveEmptyEntries);
//NONE:179:touchplay:NONE:179:touchplay:HOTKEYS
Hotkey h = new Hotkey
{
ModifierPressed = hotkeyInfo[0],
KeyCode = Convert.ToInt32(hotkeyInfo[1]),
Key = hotkeyInfo[2],
ModifierToSend = hotkeyInfo[3]
};
if (hotkeyInfo.Length > 5)
{
h.SendTo = hotkeyInfo[5];
}
if (hotkeyInfo.Length > 6)
{
h.WhoTo = hotkeyInfo[6];
}
if (hotkeyInfo.Length > 7)
{
h.SpecialCommands = hotkeyInfo[7];
}
Hotkeys.Add(h);
line = tr.ReadLine();
}
}
}
}
public static Hotkey GetKey(int keyCode)
{
//LINQ:
//var ret = from hotkey in Hotkeys
// where hotkey.KeyCode == keyCode
// select hotkey;
//return ret.FirstOrDefault();
// Regular old foreach
foreach (Hotkey hotkey in Hotkeys)
{
if (hotkey.KeyCode == keyCode)
{
return hotkey;
}
}
return null;
}
/// <summary>
/// Gets the GUI item. Nifty for using lstViewHotkeys.Items.Add(hotkey.GuiItem);
/// </summary>
/// <value>The GUI item.</value>
public ListViewItem GuiItem
{
get
{
// Obviously need to change this to match your list view.
string[] texts = new[]
{
ModifierPressed, KeyCode.ToString(), Key, ModifierToSend, SendTo, WhoTo,
SpecialCommands
};
return new ListViewItem(texts);
}
}
}
Probably not exactly what you're looking for, but it gets the point across.