C# make winform readonly radioButton look like standard

依然范特西╮ 提交于 2019-12-20 01:41:06

问题


Simple question. If I set a radiobutton in a winform project read only it's appearance (font color) changes to light grey. Same when I set it's enabled property to false,

How can I manage to create a read only radiobutton looking like a normal one ? Cause like that you can barely see it.

Thanks


回答1:


As an option you can add a ReadOnly property and override OnClick and call base.OnClick(e) only if !ReadOnly:

using System;
using System.Windows.Forms;
public class MyRadioButton : RadioButton
{
    public bool ReadOnly { get; set; }
    protected override void OnClick(EventArgs e)
    {
        if (!ReadOnly)
            base.OnClick(e);
    }
}



回答2:


Managed it by removing the text of the radiobutton and added a label next to it.

Not the greatest solution but working...




回答3:


Set the AutoCheck property to false.



来源:https://stackoverflow.com/questions/39203813/c-sharp-make-winform-readonly-radiobutton-look-like-standard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!