C# 使 winform 只读 radioButton 看起来像标准 [英] C# make winform readonly radioButton look like standard

查看:134
本文介绍了C# 使 winform 只读 radioButton 看起来像标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的问题.如果我在 winform 项目中设置一个单选按钮只读它的外观(字体颜色)更改为浅灰色.当我将其启用属性设置为 false 时相同,

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.

谢谢

推荐答案

作为一个选项,您可以添加 ReadOnly 属性并覆盖 OnClick 并调用 base.OnClick(e) 仅当 !ReadOnly:

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);
    }
}

这篇关于C# 使 winform 只读 radioButton 看起来像标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆