Skip to content

Commit

Permalink
Add accessibility text to grid stoplight buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
rmcrackan committed May 7, 2024
1 parent d16d0c8 commit d19fe22
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Source/AppScaffolding/AppScaffolding.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Version>11.3.8.1</Version>
<Version>11.3.9.1</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Octokit" Version="10.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,27 @@ public LiberateDataGridViewImageButtonColumn()

internal class LiberateDataGridViewImageButtonCell : DataGridViewImageButtonCell
{
private static readonly Brush DISABLED_GRAY = new SolidBrush(Color.FromArgb(0x60, Color.LightGray));
#region Accessibility
private string accessibilityName => "Liberate Image Button";
private string accessibilityDescription = "undefined";
protected override AccessibleObject CreateAccessibilityInstance() => new MyAccessibilityObject(accessibilityName, accessibilityDescription);
protected class MyAccessibilityObject : DataGridViewCellAccessibleObject
{
public override string Name => _name;
public override string Description => _description;

private string _name { get; }
private string _description { get; }

public MyAccessibilityObject(string name, string description) : base()
{
_name = name;
_description = description;
}
}
#endregion

private static readonly Brush DISABLED_GRAY = new SolidBrush(Color.FromArgb(0x60, Color.LightGray));
private static readonly Color HiddenForeColor = Color.LightGray;
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
Expand All @@ -31,7 +51,8 @@ protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle
base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, null, null, null, cellStyle, advancedBorderStyle, paintParts);

DrawButtonImage(graphics, (Image)status.ButtonImage, cellBounds);
ToolTipText = status.ToolTip;
accessibilityDescription = status.ToolTip;
ToolTipText = status.ToolTip;

if (status.IsUnavailable || status.Opacity < 1)
graphics.FillRectangle(DISABLED_GRAY, cellBounds);
Expand Down

0 comments on commit d19fe22

Please sign in to comment.