Radio之谈---vc++

本文介绍如何在MFC对话框中初始化选择某个Radio按钮并获取用户的选择值。通过在OnInitDialog()函数中设置Radio按钮的状态以及定义全局变量来记录用户的选择。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

1)程序一运行就Radio按钮就被选择中,只需在OnInitDialog()添加如下代码

 CButton* tb=(CButton*)GetDlgItem(IDC_RADIO1);
  tb->SetCheck(1);

代表IDC_RADIO1被选中。

 

2)获取Radio选中的值:

先定义一个全局变量 int m_Radio;或者在class CRadioDlg : public CDialog
{

int m_Radio

}(这里的类在头文件那里的)

也是可以的;然后在Radio选择事件里面:

void CRadioDlg::OnRadio1()
{
 // TODO: Add your control notification handler code here
 m_Radio=1;
}

void CRadioDlg::OnRadio2()
{
 // TODO: Add your control notification handler code here
 m_Radio=2;
}

void CRadioDlg::OnRadio3()
{
 // TODO: Add your control notification handler code here
 m_Radio=3;
}

void CRadioDlg::OnRadio4()
{
 // TODO: Add your control notification handler code here
 m_Radio=4;
}

最后在一个获取Radio控件选择中的值,如按钮单击事件里面:

void CRadioDlg::OnButton1()
{
 // TODO: Add your control notification handler code here
 CString str1;
    CButton* tb=(CButton*)GetDlgItem(IDC_RADIO1+m_Radio-1);
 tb->GetWindowText(str1);
 m_Static.SetWindowText(str1);
 
}

最终运行的效果图:

 

 

 

### 设置 Element UI `el-radio-button` 组件的圆角半径 为了自定义 `el-radio-button` 的外观,特别是调整其圆角半径,可以通过覆盖默认样式来实现这一目标。Element UI 提供了一套完整的 CSS 类名体系,允许开发者通过自定义样式表轻松修改组件的视觉效果。 #### 方法一:全局样式覆盖 可以在项目的全局样式文件(如 `style.css` 或 `<style>` 标签内)中添加特定的选择器,用于重写 `el-radio-button` 的边框半径: ```css .el-radio-button__inner { border-radius: 10px; /* 自定义圆角大小 */ } ``` 这种方法适用于整个项目中的所有 `el-radio-button` 实例[^1]。 #### 方法二:局部作用域内的样式定制 如果只需要针对某个页面或组件内部使用的 `el-radio-button` 进行样式调整,则可以采用更精确的方式,在相应 Vue 单文件组件 (SFC) 中应用 scoped 属性,并编写如下代码: ```html <template> <div class="custom-radiobutton"> <!-- 放置 el-radio-button --> </div> </template> <style scoped> .custom-radiobutton .el-radio-button__inner { border-radius: 10px; } </style> ``` 这种方式能够有效防止样式的意外传播,确保只影响预期范围内的元素。 #### 方法三:使用 inline-style 动态绑定样式 对于更加灵活的需求场景,还可以利用 Vue.js 的特性——动态绑定 style 来实时改变单个按钮实例的样式属性: ```vue <template> <el-radio-button :style="{ borderRadius: customRadius }">选项A</el-radio-button> </template> <script setup> import { ref } from 'vue'; const customRadius = ref('10px'); </script> ``` 此方法提供了最大的灵活性,可以根据不同的条件即时更新界面表现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值