Skip to content

Commit

Permalink
Merge pull request #28 from Mijo-Software/mjohne-patch-1
Browse files Browse the repository at this point in the history
Add files via upload
  • Loading branch information
mjohne authored Oct 5, 2023
2 parents df24355 + 4bf2e85 commit f32efb9
Show file tree
Hide file tree
Showing 11 changed files with 291 additions and 141 deletions.
14 changes: 7 additions & 7 deletions DisksizeWatcher/AboutBoxForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

172 changes: 70 additions & 102 deletions DisksizeWatcher/AboutBoxForm.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
using System;
using System.IO;
using System.Reflection;
using MijoSoftware.AssemblyInformation;
using System;
using System.Globalization;
using System.Windows.Forms;

namespace DisksizeWatcher
{
partial class AboutBoxForm : Form
{
/// <summary>
/// Culture info
/// </summary>
private static readonly CultureInfo culture = CultureInfo.CurrentUICulture;

/// <summary>
/// Set a specific text to the status bar
/// </summary>
Expand All @@ -20,101 +25,21 @@ private void SetStatusbarText(string text)
public AboutBoxForm()
{
InitializeComponent();
Text = $"Info about {AssemblyTitle}";
labelProductName.Text = AssemblyProduct;
labelVersion.Text = $"Version {AssemblyVersion}";
labelCopyright.Text = AssemblyCopyright;
labelCompanyName.Text = AssemblyCompany;
textBoxDescription.Text = AssemblyDescription;
}

#region Assemblyattributaccessoren

public string AssemblyTitle
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
if (attributes.Length > 0)
{
AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
if (titleAttribute.Title != string.Empty)
{
return titleAttribute.Title;
}
}
return Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
}
}

public string AssemblyVersion
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}

public string AssemblyDescription
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
if (attributes.Length == 0)
{
return string.Empty;
}
return ((AssemblyDescriptionAttribute)attributes[0]).Description;
}
}

public string AssemblyProduct
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
if (attributes.Length == 0)
{
return string.Empty;
}
return ((AssemblyProductAttribute)attributes[0]).Product;
}
Text = string.Format(provider: culture, format: "Info about {0}", args: AssemblyInfo.AssemblyTitle);
labelProductName.Text = AssemblyInfo.AssemblyProduct;
labelVersion.Text = AssemblyInfo.AssemblyVersion;
labelCompanyName.Text = AssemblyInfo.AssemblyCompany;
labelCopyright.Text = AssemblyInfo.AssemblyCopyright;
textBoxDescription.Text = AssemblyInfo.AssemblyDescription;
}

public string AssemblyCopyright
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
if (attributes.Length == 0)
{
return string.Empty;
}
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
}
}

public string AssemblyCompany
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
if (attributes.Length == 0)
{
return string.Empty;
}
return ((AssemblyCompanyAttribute)attributes[0]).Company;
}
}
#endregion

/// <summary>
/// Load the form
/// </summary>
/// <param name="sender">object sender</param>
/// <param name="e">event arguments</param>
/// <remarks>The parameters <paramref name="e"/> and <paramref name="sender"/> are not needed, but must be indicated.</remarks>
private void AboutBoxForm_Load(object sender, System.EventArgs e) => SetStatusbarText(text: string.Empty);
private void AboutBoxForm_Load(object sender, EventArgs e) => SetStatusbarText(text: string.Empty);

/// <summary>
/// Detect the accessibility description to set as information text in the status bar
Expand All @@ -124,26 +49,69 @@ public string AssemblyCompany
/// <remarks>The parameter <paramref name="e"/> is not needed, but must be indicated.</remarks>
private void SetStatusbar_Enter(object sender, EventArgs e)
{
string text = string.Empty;
switch (sender)
{
case Control control:
text = control.AccessibleDescription;
case TextBox _:
SetStatusbarText(text: ((TextBox)sender).AccessibleDescription);
break;
case Button _:
SetStatusbarText(text: ((Button)sender).AccessibleDescription);
break;
case RadioButton _:
SetStatusbarText(text: ((RadioButton)sender).AccessibleDescription);
break;
case CheckBox _:
SetStatusbarText(text: ((CheckBox)sender).AccessibleDescription);
break;
case DateTimePicker _:
SetStatusbarText(text: ((DateTimePicker)sender).AccessibleDescription);
break;
case Label _:
SetStatusbarText(text: ((Label)sender).AccessibleDescription);
break;
case PictureBox _:
SetStatusbarText(text: ((PictureBox)sender).AccessibleDescription);
break;
case ToolStripButton _:
SetStatusbarText(text: ((ToolStripButton)sender).AccessibleDescription);
break;
case ToolStripMenuItem _:
SetStatusbarText(text: ((ToolStripMenuItem)sender).AccessibleDescription);
break;
case ToolStripLabel _:
SetStatusbarText(text: ((ToolStripLabel)sender).AccessibleDescription);
break;
case ToolStripComboBox _:
SetStatusbarText(text: ((ToolStripComboBox)sender).AccessibleDescription);
break;
case ToolStripDropDown _:
SetStatusbarText(text: ((ToolStripDropDown)sender).AccessibleDescription);
break;
case ToolStripDropDownButton _:
SetStatusbarText(text: ((ToolStripDropDownButton)sender).AccessibleDescription);
break;
case ToolStripSplitButton toolStripSplitButton:
text = toolStripSplitButton.AccessibleDescription;
case ToolStripDropDownItem _:
SetStatusbarText(text: ((ToolStripDropDownItem)sender).AccessibleDescription);
break;
case ToolStripButton toolStripButton:
text = toolStripButton.AccessibleDescription;
/*case ToolStripDropDownMenu _:
SetStatusbarText(text: ((ToolStripDropDownMenu)sender).AccessibleDescription);
break;*/
case ToolStripProgressBar _:
SetStatusbarText(text: ((ToolStripProgressBar)sender).AccessibleDescription);
break;
case ToolStripLabel toolStripLabel:
text = toolStripLabel.AccessibleDescription;
/*case ToolStripSplitButton _:
SetStatusbarText(text: ((ToolStripSplitButton)sender).AccessibleDescription);
break;*/
case ToolStripSeparator _:
SetStatusbarText(text: ((ToolStripSeparator)sender).AccessibleDescription);
break;
case ToolStripMenuItem toolStripMenuItem:
text = toolStripMenuItem.AccessibleDescription;
/*case ToolStripStatusLabel _:
SetStatusbarText(text: ((ToolStripStatusLabel)sender).AccessibleDescription);
break;*/
case ToolStripTextBox _:
SetStatusbarText(text: ((ToolStripTextBox)sender).AccessibleDescription);
break;
}
SetStatusbarText(text: text);
}

/// <summary>
Expand Down
5 changes: 4 additions & 1 deletion DisksizeWatcher/AboutBoxForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@
<value>17, 17</value>
</metadata>
<metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>216, 17</value>
<value>107, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>81</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
Expand Down
92 changes: 92 additions & 0 deletions DisksizeWatcher/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System.IO;
using System.Reflection;

namespace MijoSoftware.AssemblyInformation
{
/// <summary>
/// Provide some assembly information
/// </summary>
public static class AssemblyInfo
{
#region Assembly attribute accessors

/// <summary>
/// Return the title of the assembly
/// </summary>
public static string AssemblyTitle
{
get
{
object[] attributes = Assembly.GetExecutingAssembly()
.GetCustomAttributes(attributeType: typeof(AssemblyTitleAttribute), inherit: false);
if (attributes.Length > 0)
{
AssemblyTitleAttribute titleAttribute = attributes[0] as AssemblyTitleAttribute;
if (!string.IsNullOrEmpty(value: titleAttribute.Title))
{
return titleAttribute.Title;
}
}
return Path.GetFileNameWithoutExtension(path: Assembly.GetExecutingAssembly().CodeBase);
}
}

/// <summary>
/// Return the version of the assembly
/// </summary>
public static string AssemblyVersion => Assembly.GetExecutingAssembly().GetName().Version.ToString();

/// <summary>
/// Return the description of the assembly
/// </summary>
public static string AssemblyDescription
{
get
{
object[] attributes = Assembly.GetExecutingAssembly()
.GetCustomAttributes(attributeType: typeof(AssemblyDescriptionAttribute), inherit: false);
return attributes.Length == 0 ? string.Empty : ((AssemblyDescriptionAttribute)attributes[0]).Description;
}
}

/// <summary>
/// Return the product name of the assembly
/// </summary>
public static string AssemblyProduct
{
get
{
object[] attributes = Assembly.GetExecutingAssembly()
.GetCustomAttributes(attributeType: typeof(AssemblyProductAttribute), inherit: false);
return attributes.Length == 0 ? string.Empty : ((AssemblyProductAttribute)attributes[0]).Product;
}
}

/// <summary>
/// Return the copyright of the assembly
/// </summary>
public static string AssemblyCopyright
{
get
{
object[] attributes = Assembly.GetExecutingAssembly()
.GetCustomAttributes(attributeType: typeof(AssemblyCopyrightAttribute), inherit: false);
return attributes.Length == 0 ? string.Empty : ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
}
}

/// <summary>
/// Return the company name of the assembly
/// </summary>
public static string AssemblyCompany
{
get
{
object[] attributes = Assembly.GetExecutingAssembly()
.GetCustomAttributes(attributeType: typeof(AssemblyCompanyAttribute), inherit: false);
return attributes.Length == 0 ? string.Empty : ((AssemblyCompanyAttribute)attributes[0]).Company;
}
}
#endregion
}
}
1 change: 1 addition & 0 deletions DisksizeWatcher/DisksizeWatcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<Compile Include="AboutBoxForm.Designer.cs">
<DependentUpon>AboutBoxForm.cs</DependentUpon>
</Compile>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
Expand Down
2 changes: 1 addition & 1 deletion DisksizeWatcher/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f32efb9

Please sign in to comment.