|
| 1 | +using System; |
| 2 | +using System.IO; |
| 3 | +using System.Reflection; |
| 4 | +using System.Windows.Forms; |
| 5 | + |
| 6 | +namespace DisksizeWatcher |
| 7 | +{ |
| 8 | + partial class AboutBoxForm : Form |
| 9 | + { |
| 10 | + /// <summary> |
| 11 | + /// Set a specific text to the status bar |
| 12 | + /// </summary> |
| 13 | + /// <param name="text">text with some information</param> |
| 14 | + private void SetStatusbarText(string text) |
| 15 | + { |
| 16 | + labelInformation.Enabled = !string.IsNullOrEmpty(value: text); |
| 17 | + labelInformation.Text = text; |
| 18 | + } |
| 19 | + |
| 20 | + public AboutBoxForm() |
| 21 | + { |
| 22 | + InitializeComponent(); |
| 23 | + Text = $"Info about {AssemblyTitle}"; |
| 24 | + labelProductName.Text = AssemblyProduct; |
| 25 | + labelVersion.Text = $"Version {AssemblyVersion}"; |
| 26 | + labelCopyright.Text = AssemblyCopyright; |
| 27 | + labelCompanyName.Text = AssemblyCompany; |
| 28 | + textBoxDescription.Text = AssemblyDescription; |
| 29 | + } |
| 30 | + |
| 31 | + #region Assemblyattributaccessoren |
| 32 | + |
| 33 | + public string AssemblyTitle |
| 34 | + { |
| 35 | + get |
| 36 | + { |
| 37 | + object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false); |
| 38 | + if (attributes.Length > 0) |
| 39 | + { |
| 40 | + AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0]; |
| 41 | + if (titleAttribute.Title != string.Empty) |
| 42 | + { |
| 43 | + return titleAttribute.Title; |
| 44 | + } |
| 45 | + } |
| 46 | + return Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + public string AssemblyVersion |
| 51 | + { |
| 52 | + get |
| 53 | + { |
| 54 | + return Assembly.GetExecutingAssembly().GetName().Version.ToString(); |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + public string AssemblyDescription |
| 59 | + { |
| 60 | + get |
| 61 | + { |
| 62 | + object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); |
| 63 | + if (attributes.Length == 0) |
| 64 | + { |
| 65 | + return string.Empty; |
| 66 | + } |
| 67 | + return ((AssemblyDescriptionAttribute)attributes[0]).Description; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + public string AssemblyProduct |
| 72 | + { |
| 73 | + get |
| 74 | + { |
| 75 | + object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false); |
| 76 | + if (attributes.Length == 0) |
| 77 | + { |
| 78 | + return string.Empty; |
| 79 | + } |
| 80 | + return ((AssemblyProductAttribute)attributes[0]).Product; |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + public string AssemblyCopyright |
| 85 | + { |
| 86 | + get |
| 87 | + { |
| 88 | + object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); |
| 89 | + if (attributes.Length == 0) |
| 90 | + { |
| 91 | + return string.Empty; |
| 92 | + } |
| 93 | + return ((AssemblyCopyrightAttribute)attributes[0]).Copyright; |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + public string AssemblyCompany |
| 98 | + { |
| 99 | + get |
| 100 | + { |
| 101 | + object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false); |
| 102 | + if (attributes.Length == 0) |
| 103 | + { |
| 104 | + return string.Empty; |
| 105 | + } |
| 106 | + return ((AssemblyCompanyAttribute)attributes[0]).Company; |
| 107 | + } |
| 108 | + } |
| 109 | + #endregion |
| 110 | + |
| 111 | + /// <summary> |
| 112 | + /// Load the form |
| 113 | + /// </summary> |
| 114 | + /// <param name="sender">object sender</param> |
| 115 | + /// <param name="e">event arguments</param> |
| 116 | + /// <remarks>The parameters <paramref name="e"/> and <paramref name="sender"/> are not needed, but must be indicated.</remarks> |
| 117 | + private void AboutBoxForm_Load(object sender, System.EventArgs e) => SetStatusbarText(text: string.Empty); |
| 118 | + |
| 119 | + /// <summary> |
| 120 | + /// Detect the accessibility description to set as information text in the status bar |
| 121 | + /// </summary> |
| 122 | + /// <param name="sender">object sender</param> |
| 123 | + /// <param name="e">event arguments</param> |
| 124 | + /// <remarks>The parameter <paramref name="e"/> is not needed, but must be indicated.</remarks> |
| 125 | + private void SetStatusbar_Enter(object sender, EventArgs e) |
| 126 | + { |
| 127 | + string text = string.Empty; |
| 128 | + switch (sender) |
| 129 | + { |
| 130 | + case Control control: |
| 131 | + text = control.AccessibleDescription; |
| 132 | + break; |
| 133 | + case ToolStripSplitButton toolStripSplitButton: |
| 134 | + text = toolStripSplitButton.AccessibleDescription; |
| 135 | + break; |
| 136 | + case ToolStripButton toolStripButton: |
| 137 | + text = toolStripButton.AccessibleDescription; |
| 138 | + break; |
| 139 | + case ToolStripLabel toolStripLabel: |
| 140 | + text = toolStripLabel.AccessibleDescription; |
| 141 | + break; |
| 142 | + case ToolStripMenuItem toolStripMenuItem: |
| 143 | + text = toolStripMenuItem.AccessibleDescription; |
| 144 | + break; |
| 145 | + } |
| 146 | + SetStatusbarText(text: text); |
| 147 | + } |
| 148 | + |
| 149 | + /// <summary> |
| 150 | + /// Clear the information text of the status bar |
| 151 | + /// </summary> |
| 152 | + /// <param name="sender">object sender</param> |
| 153 | + /// <param name="e">event arguments</param> |
| 154 | + /// <remarks>The parameters <paramref name="e"/> and <paramref name="sender"/> are not needed, but must be indicated.</remarks> |
| 155 | + private void ClearStatusbar_Leave(object sender, EventArgs e) => SetStatusbarText(text: string.Empty); |
| 156 | + } |
| 157 | +} |
0 commit comments