Reputation: 141
I want to set the focus in the button when a button is disabled in the windows form application.
Is there any way to achieve this goal?
Background:
I am making an application that can be used by a blind person so when the button is enabled then on focus screen reader will read of button content but when a button is disabled then not possible to read by screen reader because of the button can not be focused on disabled mode
Upvotes: 1
Views: 425
Reputation: 145
You can create a custom control and create one propriety into a custom control. using that property to check OnClick need to fire or not.
For Example:
public class buttonReadonly: Button
{
private bool _isReadOnly = false;
public bool isReadOnly
{
get
{
return _isReadOnly;
}
set
{
_isReadOnly = value;
}
}
protected override void OnClick(EventArgs e)
{
if (!isReadOnly)
{
base.OnClick(e);
}
}
}
Upvotes: 1
Reputation: 258
You can try to add and remove the event of click by below code rather than enable and disable the button in C#.
For remove click event
button.Click -= button_Click;
For add click event
button.Click += button_Click;
For reference, you can refer to the below link.
How to subscribe to and unsubscribe from events (C# Programming Guide)
Upvotes: 2