Skip to content

Commit

Permalink
+ codedoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Hawkynt committed Aug 4, 2024
1 parent 32794d6 commit af2557d
Show file tree
Hide file tree
Showing 12 changed files with 730 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,30 @@
namespace System.Windows.Forms;

public static partial class ControlCollectionExtensions {

/// <summary>
/// Converts the <see cref="Control.ControlCollection"/> to an array of controls.
/// </summary>
/// <param name="this">This <see cref="Control.ControlCollection"/> instance.</param>
/// <returns>An array of <see cref="Control"/> elements.</returns>
/// <exception cref="System.NullReferenceException">Thrown if <paramref name="this"/> is <see langword="null"/>.</exception>
/// <example>
/// <code>
/// Form form = new Form();
/// form.Controls.Add(new Button());
/// form.Controls.Add(new TextBox());
/// Control[] controls = form.Controls.ToArray();
/// Console.WriteLine($"Number of controls: {controls.Length}");
/// // Output: Number of controls: 2
/// </code>
/// </example>
public static Control[] ToArray(this Control.ControlCollection @this) {
Against.ThisIsNull(@this);

var result = new Control[@this.Count];
for (var i = 0; i < result.Length; ++i)
result[i] = @this[i];

@this.CopyTo(result, 0);

return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace System.Windows.Controls;

public static partial class TextBoxExtensions {

/// <summary>
/// Saves the caret position and restores it upon object disposal.
/// </summary>
Expand All @@ -45,9 +46,18 @@ public static partial class TextBoxExtensions {
public static Point GetCaretPosition() => NativeMethods.GetCaretPos();

/// <summary>
/// Moves the cursor to end of the text.
/// Moves the cursor to the end of the text in the <see cref="TextBox"/>.
/// </summary>
/// <param name="this">This TextBox.</param>
/// <param name="this">This <see cref="TextBox"/> instance.</param>
/// <exception cref="System.NullReferenceException">Thrown if <paramref name="this"/> is <see langword="null"/>.</exception>
/// <example>
/// <code>
/// TextBox textBox = new TextBox();
/// textBox.Text = "Hello, World!";
/// textBox.MoveCursorToEnd();
/// // The cursor is now at the end of the text.
/// </code>
/// </example>
public static void MoveCursorToEnd(this TextBox @this) {
Against.ThisIsNull(@this);

Expand All @@ -56,11 +66,22 @@ public static void MoveCursorToEnd(this TextBox @this) {
}

/// <summary>
/// Tries to parse the content into an int.
/// Tries to parse the text of the <see cref="TextBox"/> as an integer.
/// </summary>
/// <param name="this">This TextBox.</param>
/// <param name="value">The value.</param>
/// <returns><c>true</c> on success; otherwise, <c>false</c>.</returns>
/// <param name="this">This <see cref="TextBox"/> instance.</param>
/// <param name="value">The parsed integer value if the parsing is successful; otherwise, the original value.</param>
/// <returns><see langword="true"/> if the parsing is successful; otherwise, <see langword="false"/>.</returns>
/// <exception cref="System.NullReferenceException">Thrown if <paramref name="this"/> is <see langword="null"/>.</exception>
/// <example>
/// <code>
/// TextBox textBox = new TextBox();
/// textBox.Text = "123";
/// int result = 0;
/// bool success = textBox.TryParseInt(ref result);
/// Console.WriteLine($"Success: {success}, Result: {result}");
/// // Output: Success: True, Result: 123
/// </code>
/// </example>
public static bool TryParseInt(this TextBox @this, ref int value) {
Against.ThisIsNull(@this);

Expand All @@ -76,15 +97,24 @@ public static bool TryParseInt(this TextBox @this, ref int value) {
}

/// <summary>
/// Tries to parse the content into an int.
/// Tries to parse the text of the <see cref="TextBox"/> as an integer using the specified style and format provider.
/// </summary>
/// <param name="this">This TextBox.</param>
/// <param name="style">The style.</param>
/// <param name="provider">The format provider.</param>
/// <param name="value">The value.</param>
/// <returns>
/// <c>true</c> on success; otherwise, <c>false</c>.
/// </returns>
/// <param name="this">This <see cref="TextBox"/> instance.</param>
/// <param name="style">A bitwise combination of enumeration values that indicates the permitted format of the input string.</param>
/// <param name="provider">An object that supplies culture-specific formatting information.</param>
/// <param name="value">The parsed integer value if the parsing is successful; otherwise, the original value.</param>
/// <returns><see langword="true"/> if the parsing is successful; otherwise, <see langword="false"/>.</returns>
/// <exception cref="System.NullReferenceException">Thrown if <paramref name="this"/> is <see langword="null"/>.</exception>
/// <example>
/// <code>
/// TextBox textBox = new TextBox();
/// textBox.Text = "123";
/// int result = 0;
/// bool success = textBox.TryParseInt(NumberStyles.Integer, CultureInfo.InvariantCulture, ref result);
/// Console.WriteLine($"Success: {success}, Result: {result}");
/// // Output: Success: True, Result: 123
/// </code>
/// </example>
public static bool TryParseInt(this TextBox @this, NumberStyles style, IFormatProvider provider, ref int value) {
Against.ThisIsNull(@this);

Expand All @@ -98,4 +128,5 @@ public static bool TryParseInt(this TextBox @this, NumberStyles style, IFormatPr
value = temp;
return true;
}

}
91 changes: 64 additions & 27 deletions System.Windows.Forms.Extensions/System/Windows/Forms/ProgressBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,88 @@
namespace System.Windows.Forms;

public static partial class ProgressBarExtensions {

/// <summary>
/// Sets the progress bar percentage.
/// Sets the value of the <see cref="ProgressBar"/> to the specified percentage.
/// </summary>
/// <param name="This">This ProgressBar.</param>
/// <param name="percentage">The percentage to set.</param>
public static void SetPercent(this ProgressBar This, double percentage) {
Against.ThisIsNull(This);
/// <param name="this">This <see cref="ProgressBar"/> instance.</param>
/// <param name="percentage">The percentage to set the progress bar value to, where 0.0 represents 0% and 100.0 represents 100%.</param>
/// <exception cref="System.NullReferenceException">Thrown if <paramref name="this"/> is <see langword="null"/>.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">Thrown if <paramref name="percentage"/> is less than 0.0 or greater than 100.0.</exception>
/// <example>
/// <code>
/// ProgressBar progressBar = new ProgressBar();
/// progressBar.SetPercent(75.0);
/// // The progress bar is now set to 75%.
/// </code>
/// </example>
public static void SetPercent(this ProgressBar @this, double percentage) {
Against.ThisIsNull(@this);

This.Value = (int)(This.Minimum + (This.Maximum - This.Minimum) * Math.Min(Math.Max(percentage, 0), 100) * 0.01d);
@this.Value = (int)(@this.Minimum + (@this.Maximum - @this.Minimum) * Math.Min(Math.Max(percentage, 0), 100) * 0.01d);
}

/// <summary>
/// Sets the progress bar value.
/// Sets the value of the <see cref="ProgressBar"/> to the specified normalized value.
/// </summary>
/// <param name="This">This ProgressBar.</param>
/// <param name="value">The normalized value to set (0&lt;x&lt;1).</param>
public static void SetNormalizedValue(this ProgressBar This, double value) {
Against.ThisIsNull(This);
/// <param name="this">This <see cref="ProgressBar"/> instance.</param>
/// <param name="value">The normalized value to set, where 0.0 represents the minimum value and 1.0 represents the maximum value.</param>
/// <exception cref="System.NullReferenceException">Thrown if <paramref name="this"/> is <see langword="null"/>.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">Thrown if <paramref name="value"/> is less than 0.0 or greater than 1.0.</exception>
/// <example>
/// <code>
/// ProgressBar progressBar = new ProgressBar();
/// progressBar.SetNormalizedValue(0.75);
/// // The progress bar is now set to 75% of its range.
/// </code>
/// </example>
public static void SetNormalizedValue(this ProgressBar @this, double value) {
Against.ThisIsNull(@this);

This.Value = (int)(This.Minimum + (This.Maximum - This.Minimum) * Math.Min(Math.Max(value, 0), 1));
@this.Value = (int)(@this.Minimum + (@this.Maximum - @this.Minimum) * Math.Min(Math.Max(value, 0), 1));
}

/// <summary>
/// Sets the progress bar according to current and max, without changing it's minimum and maximum values.
/// Sets the value of the <see cref="ProgressBar"/> based on the specified current and maximum values.
/// </summary>
/// <param name="This">This ProgressBar.</param>
/// <param name="current">The current value.</param>
/// <param name="max">The maximum value to assume.</param>
public static void SetValue(this ProgressBar This, double current, double max) {
Against.ThisIsNull(This);
/// <param name="this">This <see cref="ProgressBar"/> instance.</param>
/// <param name="current">The current value to set.</param>
/// <param name="max">The maximum value to set.</param>
/// <exception cref="System.NullReferenceException">Thrown if <paramref name="this"/> is <see langword="null"/>.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">Thrown if <paramref name="current"/> is less than 0.0 or greater than <paramref name="max"/>.</exception>
/// <example>
/// <code>
/// ProgressBar progressBar = new ProgressBar();
/// progressBar.SetValue(30.0, 100.0);
/// // The progress bar is now set to 30% of its range.
/// </code>
/// </example>
public static void SetValue(this ProgressBar @this, double current, double max) {
Against.ThisIsNull(@this);

This.SetPercent(max == 0 ? 0 : current / max * 100);
@this.SetPercent(max == 0 ? 0 : current / max * 100);
}

/// <summary>
/// Sets the progress bar according to current, min and max, without changing it's minimum and maximum values.
/// Sets the value of the <see cref="ProgressBar"/> based on the specified current, minimum, and maximum values.
/// </summary>
/// <param name="This">This ProgressBar.</param>
/// <param name="current">The current value.</param>
/// <param name="min">The minimum value to assume.</param>
/// <param name="max">The maximum value to assume.</param>
public static void SetValue(this ProgressBar This, double current, double min, double max) {
Against.ThisIsNull(This);
/// <param name="this">This <see cref="ProgressBar"/> instance.</param>
/// <param name="current">The current value to set.</param>
/// <param name="min">The minimum value of the range.</param>
/// <param name="max">The maximum value of the range.</param>
/// <exception cref="System.NullReferenceException">Thrown if <paramref name="this"/> is <see langword="null"/>.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">Thrown if <paramref name="current"/> is less than <paramref name="min"/> or greater than <paramref name="max"/>.</exception>
/// <example>
/// <code>
/// ProgressBar progressBar = new ProgressBar();
/// progressBar.SetValue(30.0, 0.0, 100.0);
/// // The progress bar is now set to 30% of its range.
/// </code>
/// </example>
public static void SetValue(this ProgressBar @this, double current, double min, double max) {
Against.ThisIsNull(@this);

var newMax = max - min;
This.SetPercent(newMax == 0 ? 0 : (current - min) / newMax * 100);
@this.SetPercent(newMax == 0 ? 0 : (current - min) / newMax * 100);
}
}
Loading

0 comments on commit af2557d

Please sign in to comment.