nim_duilib(9)之RichEdit
introduction
- 更多控件用法,请参考 here 和 源码。
- 本文的代码基于这里
- RichEdit的更多用法,请参考源码中RichEdit.h提供的函数,RichEdit控件,可以定制为多种多样的形式,其公开的函数很多,本文仅演示密码和只读。
xml文件添加代码
基于上一篇, 继续向basic.xml中添加下面关于RichEdit的代码。 xml完整源码在文末。
<!--第二行控件开始-->
<!--第二行控件开始-->
<HBox height="85">
<VBox>
<HBox>
<RichEdit class="simple input" name="rich_edit_1" text="输入演示" height="30" margin="0,3" padding="6,6,6" promptmode="true" prompttext="Single line text control" promptcolor="lightcolor"/>
<CheckBox class="checkbox_font12" name="rich_edit_readonly" text="read only" margin="0,5,0,10"/>
</HBox>
</VBox>
</HBox>
这里,创建了一个RichEdit控件和一个CheckBox按钮。
代码中关联
BasicForm.h
- 打开BasicForm.h,类中添加下面的代码用于关联界面控件。
// rich edit
ui::RichEdit* prichedit_;
ui::CheckBox* prichedit_cb_;
监听选择子项事件
类中继续添加下面的代码,用于监听checkbox选择状态变化
// 监听将richedit设置为只读
bool OnRichEditSetReadOnly(ui::EventArgs* msg);
BasicForm.cpp
InitWindow函数
- 转到BasicForm.cpp,找到 InitWindow 函数,向其增加下面的代码
void BasicForm::InitWindow()
{
......
// 8.关联richedit控件
//----------------------------------------------------------------------------------------
prichedit_ = dynamic_cast<ui::RichEdit*>(FindControl(L"rich_edit_1"));
prichedit_cb_ = dynamic_cast<ui::CheckBox*>(FindControl(L"rich_edit_readonly"));
if (prichedit_cb_)
{
// 监听选中和没有选中事件
prichedit_cb_->AttachSelect(nbase::Bind(&BasicForm::OnRichEditSetReadOnly, this, std::placeholders::_1));
prichedit_cb_->AttachUnSelect(nbase::Bind(&BasicForm::OnRichEditSetReadOnly, this, std::placeholders::_1));
}
}
OnRichEditSetReadOnly
OnRichEditSetReadOnly函数源码如下:
bool BasicForm::OnRichEditSetReadOnly(ui::EventArgs* msg)
{
if (prichedit_cb_ && prichedit_)
{
// 获取当前选中状态
bool is_checked = prichedit_cb_->IsSelected();
// 设置只读
prichedit_->SetReadOnly(is_checked);
// 设置是否为密码属性
prichedit_->SetPassword(is_checked);
}
return false;
}
运行结果

xml完整源码
<?xml version="1.0" encoding="UTF-8"?>
<Window size="900,600" caption="0,0,0,35">
<VBox bkcolor="bk_wnd_darkcolor">
<HBox width="stretch" height="35" bkcolor="bk_wnd_lightcolor">
<Control />
<Button class="btn_wnd_min" name="minbtn" margin="4,6,0,0" />
<Box width="21" margin="4,6,0,0">
<Button class="btn_wnd_max" name="maxbtn"/>
<Button class="btn_wnd_restore" name="restorebtn" visible="false"/>
</Box>
<Button class="btn_wnd_close" name="closebtn" margin="4,6,8,0"/>
</HBox>
<!--下面是中间的控件-->
<VBox padding="30, 30, 30, 30" >
<HBox height="120">
<VBox>
<!-- Buttons -->
<Button class="btn_global_blue_80x30" name="btn_blue" text="blue" />
<Button class="btn_global_white_80x30" name="btn_white" text="white"/>
<Button class="btn_global_red_80x30" name="btn_red" text="red"/>
</VBox>
<!--checkbox-->
<VBox>
<CheckBox class="checkbox_font12" name="checkbox1" text="checkbox1" margin="0,5,0,10" selected="true"/>
<CheckBox class="checkbox_font12" name="checkbox2" text="checkbox2" margin="0,5,0,10"/>
<CheckBox class="checkbox_font12" name="checkbox3" text="checkbox3" margin="0,5,0,10"/>
</VBox>
<!-- option-->
<VBox>
<Option class="circle_option_2" name="option1" group="option_group" text="option1" margin="0,3,0,10" selected="true"/>
<Option class="circle_option_2" name="option2" group="option_group" text="option2" margin="0,3,0,10"/>
<Option class="circle_option_2" name="option3" group="option_group" text="option3" margin="0,3,0,10"/>
</VBox>
<HBox>
<!-- List -->
<VListBox class="list" name="list" padding="5,3,5,3">
</VListBox>
<VBox>
<!-- Buttons -->
<CheckBox class="checkbox_font12" name="list_checkbox_add_to_top" text="add to top" margin="0,5,0,10"/>
<Button class="btn_global_blue_80x30" name="list_btn_add" text="add" />
<CheckBox class="checkbox_font12" name="list_checkbox_remove_all" text="del all?" margin="0,5,0,10"/>
<Button class="btn_global_white_80x30" name="list_btn_remove" text="remove"/>
</VBox>
</HBox>
<!-- TreeView -->
<TreeView class="list" name="tree" padding="5,3,5,3" margin="20">
</TreeView>
</HBox>
<!--第二行控件开始-->
<HBox height="85">
<VBox>
<!--combobox-->
<Combo class="list" name="combo" height="30" margin="0,12,0,0" padding="6" bkimage="file='../public/combo/normal.png' corner='5,5,30,5'"/>
<HBox>
<RichEdit class="simple input" name="rich_edit_1" text="输入演示" height="30" margin="0,3" padding="6,6,6" promptmode="true" prompttext="Single line text control" promptcolor="lightcolor"/>
<CheckBox class="checkbox_font12" name="rich_edit_readonly" text="read only" margin="0,5,0,10"/>
</HBox>
</VBox>
</HBox>
</VBox> <!--下面是中间的控件 结束-->
</VBox>
</Window>
nim_duilib(9)之RichEdit的更多相关文章
- nim_duilib(20)之即刻(1)
note 一个基于nim_duilib仿wechat的IM. 主界面 样式 美工差了. 布局 整体为水平布局,左边的深灰色区域(frame_left),右侧的light white区域(frame_r ...
- nim_duilib(13)之添加fmt库
introduction 习惯使用fmt库做字符串的格式化操作.尽管nim_duilib提供了类似的函数. 故项目demo_xml引入了外部库fmt framework.h中添加下面的以便使用fmt库 ...
- 不注册COM在Richedit中使OLE支持复制粘贴
正常情况下在Richedit中使用OLE,如果需要OLE支持复制粘贴,那么这个OLE对象必须是已经注册的COM对象. 注册COM很简单,关键问题在于注册时需要管理员权限,这样一来,如果希望APP做成绿 ...
- RichEdit 追加 RTF
下面实现追加RTF 到 RichEdit 的功能其本质是:EM_STREAMIN 消息,详细查看 MSDN//--------------------------------------------- ...
- windows sdk编程 richedit创建,像十六进制编辑器一样显示文件
编译环境 :windows 7 64位 vs2010,工程创建选择"win32项目" 注意添加几个头文件 #include <WinBase.h> #include & ...
- 一种快速刷新richedit中内嵌动画的方法的实现
在IM中使用动画表情是一种非常有趣的方式,然而选择一种合适的方式来实现却并不容易. 一般来说,除了自己去实现一个富文本控件,目前主要的解决方案有3种: 1.使用浏览器做容器. 2.使用QT提供的Ric ...
- 实现一种快速查找Richedit中可见区域内OLE对象的方法
Richedit是一个OLE容器,使用Richedit来显示IM聊天内容时,通常使用OLE对象来实现在Richedit中播放表情动画. 触发表情的绘制有两种途径: 1.来自Richedit的刷新消息. ...
- RichEdit
RichEdit 设置字符颜色 ; ; this->RichEdit1->SelAttributes->Color=clRed; 行间距字符间距 void __fastcall TF ...
- BCB中获得RichEdit 默认行间距
首先,这些功能支持RichEdit2.0 以上功能: 其次,用常规的方法是无法获得LineSpace 的: 你使用 EM_GETPARAFORMAT也得不到,你会发现dyLineSpacing 的值永 ...
随机推荐
- Docker-原理解析
容器! Linux容器是与系统其他部分隔离开的一系列进程,从另一个镜像运行,并由该镜像提供支持进程所需的全部文件.容器提供的镜像包含了应用的所有依赖项,因而在从开发到测试再到生产的整个过程中,它都具有 ...
- pyquery解析库的介绍和使用
### pyquery的介绍和使用 ## 测试文本 text = ''' <html><head><title>there is money</title&g ...
- EXCEL-对筛选出(单独手动隐藏行还是在统计范围内)的表格数据进行统计
=SUBTOTAL(3,A1:A5) #计算筛选出的表格中A1:A5中有几个值. =SUBTOTAL(3,I71:I21447) ,在I71:I21447之间计数,会自动略去没有筛选上的隐藏单元格 ...
- Selenium-IDE在火狐上的扩展
昨天突然想学学 Selenium,就上网查了一些介绍,发现一些教程基本都是比较老版本的了,使用起来略有不便,所以今天试着写一些最新版本的.请参考Selenium官网.文章以下内容都是在 Mac 机器上 ...
- SpringBoot整合Shiro 二:Shiro配置类
环境搭建见上篇:SpringBoot整合Shiro 一:搭建环境 Shiro配置类配置 shiro的配置主要集中在 ShiroFilterFactoryBean 中 关于权限: anon:无需认证就可 ...
- 第三个基础框架 — springMVC — 更新完毕
1.什么是springMVC? 还是老规矩,百度百科一下 这里面说了一堆废话,去官网瞄一下 官网网址:https://docs.spring.io/spring-framework/docs/curr ...
- HDFS02 HDFS的Shell操作
HDFS的Shell操作(开发重点) 目录 HDFS的Shell操作(开发重点) 基本语法 常用命令 准备工作 上传 -moveFromLocal 剪切 -copyFromLocal 拷贝 -put ...
- Git提交规范
Commit message 的格式 每次提交,Commit message 都包括三个部分:Header,Body 和 Footer. <type>(<scope>): &l ...
- IntentFilter,PendingIntent
1.当Intent在组件间传递时,组件如果想告知Android系统自己能够响应那些Intent,那么就需要用到IntentFilter对象. IntentFilter对象负责过滤掉组件无法响应和处理的 ...
- SpringBoot让测试类飞起来的方法
单元测试是项目开发中必不可少的一环,在 SpringBoot 的项目中,我们用 @SpringBootTest 注解来标注一个测试类,在测试类中注入这个接口的实现类之后对每个方法进行单独测试. 比如下 ...