From 2feb5816e190946d31a4a3ecae2e242b7b11fac8 Mon Sep 17 00:00:00 2001 From: Aehrraid Date: Wed, 23 Dec 2020 15:03:30 +0100 Subject: [PATCH] Code cleanup - Interpolated strings - Typo in "ModDirectoryCondition" - Using Visual Studio "Run Code Cleanup" --- DigglesModManager.csproj | 4 +- FormMain.cs | 55 ++++++++++--------- FormModSettings.cs | 12 ++-- Helpers.cs | 4 +- Log.cs | 10 ++-- Mod.cs | 10 ++-- Model/AppSettings.cs | 4 +- Model/ModDirectory.cs | 2 +- ...yCondition.cs => ModDirectoryCondition.cs} | 24 ++++---- ...onType.cs => ModDirectoryConditionType.cs} | 2 +- Model/ModSettingsVariable.cs | 4 +- Paths.cs | 2 +- Program.cs | 2 +- ProgressBarManipulator.cs | 7 +-- Service/ModdingService.cs | 46 ++++++++-------- ToolTipListBox.cs | 13 ++--- 16 files changed, 98 insertions(+), 103 deletions(-) rename Model/{ModDirectroyCondition.cs => ModDirectoryCondition.cs} (66%) rename Model/{ModDirectroyConditionType.cs => ModDirectoryConditionType.cs} (64%) diff --git a/DigglesModManager.csproj b/DigglesModManager.csproj index 0376bf2..4fc230d 100644 --- a/DigglesModManager.csproj +++ b/DigglesModManager.csproj @@ -88,8 +88,8 @@ - - + + diff --git a/FormMain.cs b/FormMain.cs index 35353f1..be93ac9 100644 --- a/FormMain.cs +++ b/FormMain.cs @@ -1,15 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Windows.Forms; -using System.IO; +using DigglesModManager.Model; using DigglesModManager.Properties; using DigglesModManager.Service; using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; using System.Text; -using DigglesModManager.Model; using System.Threading.Tasks; +using System.Windows.Forms; namespace DigglesModManager { @@ -72,7 +72,7 @@ public FormMain() if (correctDirectory) { ResetStatusNote(); - ReadMods(); + ReadMods(); } else { @@ -108,7 +108,7 @@ private void setCheckOfLanguageInMenu(bool check) menuItem.Checked = check; if (check) menuItem.CheckState = CheckState.Checked; - else + else menuItem.CheckState = CheckState.Unchecked; } @@ -125,7 +125,7 @@ private void ReadMods() _moddingService.ReadModsFromFiles(_activeMods, _progressBarManipulator); //read mods - var modDirectories = (new DirectoryInfo(Paths.ModPath + "\\" + Paths.ModDirectoryName)).GetDirectories(); + var modDirectories = (new DirectoryInfo($"{Paths.ModPath}\\{Paths.ModDirectoryName}")).GetDirectories(); foreach (var modInfo in modDirectories) { if (!_activeMods.Exists(mod => mod.ModDirectoryName.Equals(modInfo.Name))) @@ -163,7 +163,7 @@ private void listBox1_SelectedIndexChanged(object sender, EventArgs e) private void listBox2_SelectedIndexChanged(object sender, EventArgs e) { - if (!this.moddingServiceRunning) + if (!moddingServiceRunning) { //find settings file int selectedIndex = installedModsListBox.SelectedIndex; @@ -255,34 +255,35 @@ private void setUIToModdingState(bool moddingState) var buttonsEnabled = !moddingState; // Refresh Button - this.refreshButton.Enabled = buttonsEnabled; + refreshButton.Enabled = buttonsEnabled; // Arrow Buttons - this.installModButton.Enabled = buttonsEnabled; - this.uninstallModButton.Enabled = buttonsEnabled; - this.moveUpButton.Enabled = buttonsEnabled; - this.moveDownButton.Enabled = buttonsEnabled; + installModButton.Enabled = buttonsEnabled; + uninstallModButton.Enabled = buttonsEnabled; + moveUpButton.Enabled = buttonsEnabled; + moveDownButton.Enabled = buttonsEnabled; // Mod Settings Buttons - this.moddingServiceRunning = moddingState; + moddingServiceRunning = moddingState; if (buttonsEnabled) { - this.listBox2_SelectedIndexChanged(null, null); + listBox2_SelectedIndexChanged(null, null); } else { - this.modSettingsButton.Enabled = false; - this.modSettingsMenuButton.Enabled = false; + modSettingsButton.Enabled = false; + modSettingsMenuButton.Enabled = false; } // Lets Mod Buttons - this.letsModButton.Enabled = buttonsEnabled; - this.letsModMenuButton.Enabled = buttonsEnabled; + letsModButton.Enabled = buttonsEnabled; + letsModMenuButton.Enabled = buttonsEnabled; } private void button_mod_Click(object sender, EventArgs e) { // set user interface into the modding state (disable buttons etc) - this.setUIToModdingState(true); + setUIToModdingState(true); // Modding in second task to avoid UI freeze - Task.Factory.StartNew(() => { + Task.Factory.StartNew(() => + { SetMessage(Resources.PleaseWait, Color.Black); //get file count of all active mods var fileCount = 0; @@ -318,7 +319,7 @@ private void button_mod_Click(object sender, EventArgs e) { SetMessage(Resources.Error, Color.Red); Helpers.ShowMessage(Resources.ModdingService_ErrorMessage, Resources.Error); - } + } else if (warning) { SetMessage(Resources.Warning, Color.Orange); @@ -329,7 +330,7 @@ private void button_mod_Click(object sender, EventArgs e) SetMessage(Resources.ModdingSuccessful, Color.Green); } // set user interface into normal state (enable buttons etc) - this.setUIToModdingState(false); + setUIToModdingState(false); }); } @@ -353,7 +354,7 @@ private void modSettingsMenuButton_Click(object sender, EventArgs e) { button_mod_settings_Click(sender, e); } - + private void changeLanguage(string language) { setCheckOfLanguageInMenu(false); diff --git a/FormModSettings.cs b/FormModSettings.cs index 9e5563d..72ad2d0 100644 --- a/FormModSettings.cs +++ b/FormModSettings.cs @@ -1,8 +1,8 @@ -using System; +using DigglesModManager.Model; +using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; -using DigglesModManager.Model; namespace DigglesModManager { @@ -20,9 +20,9 @@ public FormModSettings(Mod mod, string language) InitializeComponent(Math.Max(173, mod.Config.SettingsVariables.Count * 23 + 12)); FormBorderStyle = FormBorderStyle.FixedSingle; - Name = _mod.ToString() + " - Settings"; + Name = $"{_mod} - Settings"; Text = Name; - + var i = 0; if (_mod.Config != null) { @@ -43,9 +43,9 @@ private void BuildVariableRow(int i, ModSettingsVariable variable, string langua { AutoSize = true, Location = new Point(12, height), - Name = variable.ID + "_label", + Name = $"{variable.ID}_label", TabIndex = i + 3, - Text = variable.Name(language) + @":" + Text = $"{variable.Name(language)}:" }; Controls.Add(label); diff --git a/Helpers.cs b/Helpers.cs index ba5ae09..c7570b9 100644 --- a/Helpers.cs +++ b/Helpers.cs @@ -1,6 +1,6 @@ -using System.Diagnostics; +using DigglesModManager.Properties; +using System.Diagnostics; using System.Windows.Forms; -using DigglesModManager.Properties; namespace DigglesModManager { diff --git a/Log.cs b/Log.cs index e88fe88..ee4c28b 100644 --- a/Log.cs +++ b/Log.cs @@ -11,20 +11,20 @@ class Log private static void LogToErrorFile(string text) { - var writer = new StreamWriter(Paths.ExePath + "\\" + Paths.ErrorLogFileName, true, Encoding.Default); - writer.WriteLine(DateTime.Now + " - " + text); + var writer = new StreamWriter($"{Paths.ExePath}\\{Paths.ErrorLogFileName}", true, Encoding.Default); + writer.WriteLine($"{DateTime.Now} - {text}"); writer.Flush(); writer.Close(); } private static void LogToErrorFile(string type, string message, FileInfo fileInfo, int line) { - LogToErrorFile(type + " in \"" + fileInfo.FullName + "\" at line " + line + ": " + message); + LogToErrorFile($"{type} in \"{fileInfo.FullName}\" at line {line}: {message}"); } public static void Error(string message) { - LogToErrorFile(ERROR + " " + message); + LogToErrorFile($"{ERROR} {message}"); } public static void Error(string message, FileInfo fileInfo, int line) @@ -34,7 +34,7 @@ public static void Error(string message, FileInfo fileInfo, int line) public static void Warning(string message) { - LogToErrorFile(WARNING + " " + message); + LogToErrorFile($"{WARNING} {message}"); } public static void Warning(string message, FileInfo fileInfo, int line) diff --git a/Mod.cs b/Mod.cs index 101e61b..5b57c57 100644 --- a/Mod.cs +++ b/Mod.cs @@ -1,11 +1,11 @@ using DigglesModManager.Model; +using DigglesModManager.Properties; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Windows.Forms; -using DigglesModManager.Properties; namespace DigglesModManager { @@ -16,7 +16,7 @@ public class Mod : IToolTipDisplayer, IComparable public DirectoryInfo ModDirectoryInfo { get; private set; } public ModConfig Config { get; private set; } - + public string ToolTipText { get; private set; } public string Author { get; private set; } @@ -31,7 +31,7 @@ public Mod(string modDirectory, Dictionary oldSettings) { ModDirectoryName = modDirectory; // the last backslash is important for path cutting! - ModDirectoryInfo = new DirectoryInfo(Paths.ModPath + "\\" + Paths.ModDirectoryName + "\\" + ModDirectoryName + "\\"); + ModDirectoryInfo = new DirectoryInfo($"{Paths.ModPath}\\{Paths.ModDirectoryName}\\{ModDirectoryName}\\"); FileCount = ModDirectoryInfo.GetFiles("*", SearchOption.AllDirectories).Length; //get description @@ -122,11 +122,11 @@ public string GetToolTipText() } if (!Author.Equals("")) { - toolTip += " Author: " + Author; + toolTip += $" Author: {Author}"; } else if (!string.IsNullOrEmpty(Config.Author)) { - toolTip += " Author: " + Config.Author; + toolTip += $" Author: {Config.Author}"; } return toolTip; diff --git a/Model/AppSettings.cs b/Model/AppSettings.cs index d7372f2..a755c72 100644 --- a/Model/AppSettings.cs +++ b/Model/AppSettings.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; +using System.Collections.Generic; namespace DigglesModManager.Model { diff --git a/Model/ModDirectory.cs b/Model/ModDirectory.cs index bac4631..8251d2f 100644 --- a/Model/ModDirectory.cs +++ b/Model/ModDirectory.cs @@ -35,7 +35,7 @@ public string Path /// [DefaultValue(null)] [JsonProperty(PropertyName = "condition", Required = Required.Default, DefaultValueHandling = DefaultValueHandling.Populate)] - public ModDirectroyCondition Condition { get; set; } + public ModDirectoryCondition Condition { get; set; } } } diff --git a/Model/ModDirectroyCondition.cs b/Model/ModDirectoryCondition.cs similarity index 66% rename from Model/ModDirectroyCondition.cs rename to Model/ModDirectoryCondition.cs index f54a79f..635a669 100644 --- a/Model/ModDirectroyCondition.cs +++ b/Model/ModDirectoryCondition.cs @@ -4,13 +4,13 @@ namespace DigglesModManager.Model { - public class ModDirectroyCondition + public class ModDirectoryCondition { /// /// The type of the directory condition. [REQUIRED] /// [JsonProperty(PropertyName = "type", Required = Required.Always)] - public ModDirectroyConditionType Type { get; set; } + public ModDirectoryConditionType Type { get; set; } /// /// ID of the variable or mod that has to be checked. [REQUIRED] @@ -27,37 +27,37 @@ public class ModDirectroyCondition [JsonProperty(PropertyName = "value", Required = Required.Default, DefaultValueHandling = DefaultValueHandling.Populate)] public object Value { get; set; } - public bool isTrue(Mod mod, List activeMods) + public bool IsTrue(Mod mod, List activeMods) { switch (Type) { - case ModDirectroyConditionType.Mod: + case ModDirectoryConditionType.Mod: foreach (var activeMod in activeMods) { - if (activeMod.ModDirectoryName.Equals(this.Id)) + if (activeMod.ModDirectoryName.Equals(Id)) { return true; } } //no warning, because the existence of a mod is checked. break; - case ModDirectroyConditionType.Variable: - if (this.Value == null) + case ModDirectoryConditionType.Variable: + if (Value == null) { - Log.Warning(mod.ModDirectoryName + ": Variable with ID \"" + this.Id + "\" needs a value."); + Log.Warning($"{mod.ModDirectoryName}: Variable with ID \"{Id}\" needs a value."); break; } foreach (var modVariable in mod.Config.SettingsVariables) { - if (modVariable.ID.Equals(this.Id)) + if (modVariable.ID.Equals(Id)) { - return modVariable.Value.Equals(this.Value); + return modVariable.Value.Equals(Value); } } - Log.Warning(mod.ModDirectoryName + ": Variable with ID \"" + this.Id + "\" not found"); + Log.Warning($"{mod.ModDirectoryName}: Variable with ID \"{Id}\" not found"); break; default: - Log.Warning(mod.ModDirectoryName + ": Unhandled ModDirectroyConditionType \"" + Type + "\""); + Log.Warning($"{mod.ModDirectoryName}: Unhandled ModDirectroyConditionType \"{Type}\""); break; } return false; diff --git a/Model/ModDirectroyConditionType.cs b/Model/ModDirectoryConditionType.cs similarity index 64% rename from Model/ModDirectroyConditionType.cs rename to Model/ModDirectoryConditionType.cs index d808c60..5e90795 100644 --- a/Model/ModDirectroyConditionType.cs +++ b/Model/ModDirectoryConditionType.cs @@ -1,6 +1,6 @@ namespace DigglesModManager.Model { - public enum ModDirectroyConditionType + public enum ModDirectoryConditionType { Mod, Variable } diff --git a/Model/ModSettingsVariable.cs b/Model/ModSettingsVariable.cs index 1b905e2..bfffc03 100644 --- a/Model/ModSettingsVariable.cs +++ b/Model/ModSettingsVariable.cs @@ -19,7 +19,7 @@ public class ModSettingsVariable /// /// The human readanle name of the variable. [REQUIRED] /// - [JsonProperty(PropertyName="name", Required = Required.Always)] + [JsonProperty(PropertyName = "name", Required = Required.Always)] private ModTranslationString NameTranslation { get; set; } public string Name(string language) @@ -41,7 +41,7 @@ public string Description(string language) /// /// The data-type of the variable. Can be bool, int.. [REQUIRED] /// - [JsonConverter(typeof(StringEnumConverter)), JsonProperty(PropertyName="type", Required = Required.Always)] + [JsonConverter(typeof(StringEnumConverter)), JsonProperty(PropertyName = "type", Required = Required.Always)] public ModVariableType Type { get; set; } /// diff --git a/Paths.cs b/Paths.cs index d3d1a92..11667d8 100644 --- a/Paths.cs +++ b/Paths.cs @@ -9,7 +9,7 @@ public class Paths public static string ModPath = ExePath; //dyn: ExePath | local: @"D:\Projekte\DigglesMods\DigglesModManager" public static string ModDirectoryName = "Mods"; public static string[] DigglesExecutableNames = { "Diggles.exe", "Wiggles.exe" }; - public static string DataPath = ExePath + "\\Data"; + public static string DataPath = $"{ExePath}\\Data"; //.dm public static string RestoreFileName = "restore.dm"; diff --git a/Program.cs b/Program.cs index ae0b647..9cc4adf 100644 --- a/Program.cs +++ b/Program.cs @@ -22,7 +22,7 @@ public static void Main() { Helpers.ShowErrorMessage(Resources.FormMain_CouldNotFindFile.Replace("FILENAME", e.FileName)); } - + } } } diff --git a/ProgressBarManipulator.cs b/ProgressBarManipulator.cs index 1d1c06c..a9756b8 100644 --- a/ProgressBarManipulator.cs +++ b/ProgressBarManipulator.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +using System.Windows.Forms; namespace DigglesModManager { diff --git a/Service/ModdingService.cs b/Service/ModdingService.cs index d53b548..2344c63 100644 --- a/Service/ModdingService.cs +++ b/Service/ModdingService.cs @@ -1,10 +1,10 @@ -using System; +using DigglesModManager.Model; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; -using DigglesModManager.Model; -using Newtonsoft.Json; namespace DigglesModManager.Service { @@ -21,12 +21,12 @@ public class ModdingService public static string ChangeFilePrefix = "change_"; public static string CopyFileSuffix = "_copy"; - + public void ReadModsFromFiles(List activeMods, ProgressBarManipulator progressBarManipulator) { progressBarManipulator.Increment(); //check if mod directory exists - var modDirectoryPath = Paths.ModPath + "\\" + Paths.ModDirectoryName; + var modDirectoryPath = $"{Paths.ModPath}\\{Paths.ModDirectoryName}"; if (!Directory.Exists(modDirectoryPath)) { Directory.CreateDirectory(modDirectoryPath); @@ -51,8 +51,8 @@ public void ReadModsFromFiles(List activeMods, ProgressBarManipulator progr public void RememberForRestore(FileInfo file, string type) { //remember - var writer = new StreamWriter(Paths.ExePath + "\\" + Paths.RestoreFileName, true, Encoding.Default); - writer.WriteLine(type + "||" + file.FullName); + var writer = new StreamWriter($"{Paths.ExePath}\\{Paths.RestoreFileName}", true, Encoding.Default); + writer.WriteLine($"{type}||{file.FullName}"); writer.Flush(); writer.Close(); } @@ -73,7 +73,7 @@ public void SaveActiveMods(string language, List activeMods) } appSettings.ActiveMods.Add(mod.ModDirectoryName, variables); } - + var json = JsonConvert.SerializeObject(appSettings, Formatting.Indented); File.WriteAllText(appSettingsFilePath, json, Encoding.UTF8); //overwrites any existing files, if present } @@ -96,7 +96,7 @@ public int LetsMod(Mod mod, DirectoryInfo modDirectory, DirectoryInfo gameDirect { if (gameFile.Name.ToLower() == "texmaps.bin") { - this.RememberForRestore(gameFile, "res"); + RememberForRestore(gameFile, "res"); gameFile.MoveTo(gameFile.FullName + CopyFileSuffix); break; } @@ -162,13 +162,13 @@ public int LetsMod(Mod mod, DirectoryInfo modDirectory, DirectoryInfo gameDirect { //copy file to game folder Console.WriteLine($"Copy file: {modFile.FullName} --> {gameDirectory.FullName}\\{filename}"); - newModFile = modFile.CopyTo(gameDirectory.FullName + "\\" + filename, true); + newModFile = modFile.CopyTo($"{gameDirectory.FullName}\\{filename}", true); //replace variables var fileContent = File.ReadAllText(newModFile.FullName, Encoding.Default); foreach (var modVar in mod.Config.SettingsVariables) { - fileContent = fileContent.Replace("$print:" + modVar.ID, modVar.Value.ToString()); + fileContent = fileContent.Replace($"$print:{modVar.ID}", modVar.Value.ToString()); } Console.WriteLine($"Replace content for {newModFile.FullName}"); File.WriteAllText(newModFile.FullName, fileContent, Encoding.Default); @@ -247,7 +247,7 @@ public int LetsMod(Mod mod, DirectoryInfo modDirectory, DirectoryInfo gameDirect } if (!modVarFound) { - Log.Error("Boolean mod variable '" + ifStatement + "' not found for '$if' statement", modFile, lineNumber); + Log.Error($"Boolean mod variable '{ifStatement}' not found for '$if' statement", modFile, lineNumber); returnValue = ERROR_CODE; break; } @@ -406,9 +406,9 @@ public int LetsMod(Mod mod, DirectoryInfo modDirectory, DirectoryInfo gameDirect var commandsAsString = command[0]; for (int i = 1; i < commandCount; i++) { - commandsAsString += ", " + command[i]; + commandsAsString += $", {command[i]}"; } - Log.Error("Found commands that do not match: " + commandsAsString, modFile, lineNumber); + Log.Error($"Found commands that do not match: {commandsAsString}", modFile, lineNumber); } else { @@ -424,7 +424,7 @@ public int LetsMod(Mod mod, DirectoryInfo modDirectory, DirectoryInfo gameDirect //before: replace variables foreach (var modVar in mod.Config.SettingsVariables) { - newValue = newValue.Replace("$print:" + modVar.ID, modVar.Value.ToString()); + newValue = newValue.Replace($"$print:{modVar.ID}", modVar.Value.ToString()); } //replace old value with new value @@ -453,7 +453,7 @@ public int LetsMod(Mod mod, DirectoryInfo modDirectory, DirectoryInfo gameDirect } else if (!string.IsNullOrEmpty(line) && !line.StartsWith("$if:")) { - Log.Warning("Unnecessary content found: '" + line + "'", modFile, lineNumber); + Log.Warning($"Unnecessary content found: '{line}'", modFile, lineNumber); returnValue = WARNING_CODE; } } @@ -468,7 +468,7 @@ public int LetsMod(Mod mod, DirectoryInfo modDirectory, DirectoryInfo gameDirect //remember if (newModFile != null && !copyExists) { - this.RememberForRestore(newModFile, type); + RememberForRestore(newModFile, type); } progressBarManipulator.Increment(); @@ -506,7 +506,7 @@ public int LetsMod(Mod mod, DirectoryInfo modDirectory, DirectoryInfo gameDirect if (directory.Path.Equals(relativePath)) { // if this is a special directory, check the condition - if (directory.Condition != null && !directory.Condition.isTrue(mod, activeMods)) + if (directory.Condition != null && !directory.Condition.IsTrue(mod, activeMods)) { //if a condition exists and is false, skip this directory skipDirectory = true; @@ -522,13 +522,13 @@ public int LetsMod(Mod mod, DirectoryInfo modDirectory, DirectoryInfo gameDirect case ModDirectoryType.Optional: if (directory.Condition == null) { - Log.Warning(mod.ModDirectoryName + ": The optional directory " + directory.Path + " should have a condition"); + Log.Warning($"{mod.ModDirectoryName}: The optional directory {directory.Path} should have a condition"); returnValue = WARNING_CODE; } //do nothing, because it is now a normal directory break; default: - Log.Warning(mod.ModDirectoryName + ": Unhandled ModDirectoryType \"" + directory.Type + "\""); + Log.Warning($"{mod.ModDirectoryName}: Unhandled ModDirectoryType \"{directory.Type}\""); returnValue = WARNING_CODE; break; } @@ -579,9 +579,9 @@ public int LetsMod(Mod mod, DirectoryInfo modDirectory, DirectoryInfo gameDirect public void Restore() { - if (File.Exists(Paths.ExePath + "\\" + Paths.RestoreFileName)) + if (File.Exists($"{Paths.ExePath}\\{Paths.RestoreFileName}")) { - var reader = new StreamReader(Paths.ExePath + "\\" + Paths.RestoreFileName, Encoding.Default); + var reader = new StreamReader($"{Paths.ExePath}\\{Paths.RestoreFileName}", Encoding.Default); string line; while ((line = reader.ReadLine()) != null) { @@ -633,7 +633,7 @@ public void Restore() } reader.Close(); //delete restore file - File.Delete(Paths.ExePath + "\\" + Paths.RestoreFileName); + File.Delete($"{Paths.ExePath}\\{Paths.RestoreFileName}"); } } } diff --git a/ToolTipListBox.cs b/ToolTipListBox.cs index af20e0b..54b3561 100644 --- a/ToolTipListBox.cs +++ b/ToolTipListBox.cs @@ -1,5 +1,4 @@ using System; -using System.Drawing; using System.Windows.Forms; namespace DigglesModManager @@ -36,8 +35,8 @@ public ToolTipListBox() { InitializeComponent(); - this.MouseMove += listBox_MouseMove; - this.MouseLeave += listBox_MouseLeave; + MouseMove += listBox_MouseMove; + MouseLeave += listBox_MouseLeave; _currentItemSet = false; _toolTipDisplayed = false; @@ -53,8 +52,8 @@ private void listBox_MouseMove(object sender, MouseEventArgs e) { // Get the item that the mouse is currently over var cursorPoint = Cursor.Position; - cursorPoint = this.PointToClient(cursorPoint); - var itemIndex = this.IndexFromPoint(cursorPoint); + cursorPoint = PointToClient(cursorPoint); + var itemIndex = IndexFromPoint(cursorPoint); if (itemIndex == ListBox.NoMatches) { @@ -93,10 +92,10 @@ private void listBox_MouseLeave(object sender, EventArgs e) void _toolTipDisplayTimer_Tick(object sender, EventArgs e) { // Display tooltip text since the mouse has hovered over an item - if (_toolTipDisplayed || _currentItem == ListBox.NoMatches || _currentItem >= this.Items.Count) + if (_toolTipDisplayed || _currentItem == ListBox.NoMatches || _currentItem >= Items.Count) return; - var toolTipDisplayer = this.Items[_currentItem] as IToolTipDisplayer; + var toolTipDisplayer = Items[_currentItem] as IToolTipDisplayer; if (toolTipDisplayer == null) return;