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的更多相关文章

  1. nim_duilib(20)之即刻(1)

    note 一个基于nim_duilib仿wechat的IM. 主界面 样式 美工差了. 布局 整体为水平布局,左边的深灰色区域(frame_left),右侧的light white区域(frame_r ...

  2. nim_duilib(13)之添加fmt库

    introduction 习惯使用fmt库做字符串的格式化操作.尽管nim_duilib提供了类似的函数. 故项目demo_xml引入了外部库fmt framework.h中添加下面的以便使用fmt库 ...

  3. 不注册COM在Richedit中使OLE支持复制粘贴

    正常情况下在Richedit中使用OLE,如果需要OLE支持复制粘贴,那么这个OLE对象必须是已经注册的COM对象. 注册COM很简单,关键问题在于注册时需要管理员权限,这样一来,如果希望APP做成绿 ...

  4. RichEdit 追加 RTF

    下面实现追加RTF 到 RichEdit 的功能其本质是:EM_STREAMIN 消息,详细查看 MSDN//--------------------------------------------- ...

  5. windows sdk编程 richedit创建,像十六进制编辑器一样显示文件

    编译环境 :windows 7 64位 vs2010,工程创建选择"win32项目" 注意添加几个头文件 #include <WinBase.h> #include & ...

  6. 一种快速刷新richedit中内嵌动画的方法的实现

    在IM中使用动画表情是一种非常有趣的方式,然而选择一种合适的方式来实现却并不容易. 一般来说,除了自己去实现一个富文本控件,目前主要的解决方案有3种: 1.使用浏览器做容器. 2.使用QT提供的Ric ...

  7. 实现一种快速查找Richedit中可见区域内OLE对象的方法

    Richedit是一个OLE容器,使用Richedit来显示IM聊天内容时,通常使用OLE对象来实现在Richedit中播放表情动画. 触发表情的绘制有两种途径: 1.来自Richedit的刷新消息. ...

  8. RichEdit

    RichEdit 设置字符颜色 ; ; this->RichEdit1->SelAttributes->Color=clRed; 行间距字符间距 void __fastcall TF ...

  9. BCB中获得RichEdit 默认行间距

    首先,这些功能支持RichEdit2.0 以上功能: 其次,用常规的方法是无法获得LineSpace 的: 你使用 EM_GETPARAFORMAT也得不到,你会发现dyLineSpacing 的值永 ...

随机推荐

  1. Perl去重fasta序列

    常规方法 #! usr/bin/perl -w use strict; my $input=shift; my %hash; open IN,"<$input"; $/=&q ...

  2. php导出pdf,dompdf中文字体乱码解决办法(特别是代码迁移引起的乱码)

    dompdf\lib\fonts\dompdf_font_family_cache.php记住这个文件里面存放的是字体生成的缓存,迁移时如果覆盖了这个文件会导致乱码而且很难找到出错的地方,相信我... ...

  3. Mybatis批量添加、更新小结

    虽然是很基础的东西,不过难免会忘记,所以写个笔记巩固一下,顺便分享. 实体类: @Data public class EventOrder { ​ private Long id; ​ private ...

  4. c/c++在线编译Output Limit Exceeded(OLE)错误

    提示输出错误,有如下两个可能情况: 1. 不符合题目给出的输出格式,自己输出了多余的内容或者格式不正确 2. 输入数据的时候,未考虑到输入错误的情况 针对2,有如下的例子: 错误的情况: 1 int ...

  5. A Child's History of England.27

    Then, the Red King went over to Normandy, where the people suffered greatly under the loose rule of ...

  6. Docker学习(一)——安装docker

    Suse12上安装docker   对于suse13.2之后的版本,因为docker已经被添加到了suse仓库中,直接使用sudo zypper install docker即可.   suse12不 ...

  7. lucene的索引查询

    package com.hope.lucene;import org.apache.lucene.document.Document;import org.apache.lucene.document ...

  8. postman 中get传参数

    mybatis中: @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET, produces = & ...

  9. Istio在Rainbond Service Mesh体系下的落地实践

    两年前Service Mesh(服务网格)一出来就受到追捧,很多人认为它是微服务架构的最终形态,因为它可以让业务代码和微服务架构解耦,也就是说业务代码不需要修改就能实现微服务架构,但解耦还不够彻底,使 ...

  10. HyperSnips:VSCode上的自动补全神器

    发现一个小众但是巨好用的VSCode自动补全插件:HyperSnips. 作者显然受到了 这位小哥 的启发,将 Vim Ultisnips 的大部分功能搬到了VSCode上.并用 JavaScript ...