delphi queryCommandState
如何
获取当前光标所在的字符属性
关键点
function queryCommandState(const cmdID: WideString): WordBool;
safecall;
- 粗体
- 斜体
- 下划线
- 删除线
- 对齐方式 左 中 右
- 数字排序
- 圆的排序
- 上标
- 下标
function queryCommandValue(const cmdID: WideString): OleVariant;
safecall;
- 字体名称
- 字符大小
实现过程
|
function GetFontName():string;
begin
Result:=(Form1.webbrowser1.Document as
IHTMLDocument2).queryCommandValue('FontName'); end;
function GetFontSize():string;
begin
Result:=(Form1.webbrowser1.Document as
IHTMLDocument2).queryCommandValue('FontSize'); end;
function IsBold():Boolean;
Var bRtn:Boolean;
begin
bRtn:= (Form1.webbrowser1.Document as
IHTMLDocument2).queryCommandState('Bold'); if bRtn then
Result:=True
else
Result:=False;
end;
function IsItalic():Boolean;
Var bRtn:Boolean;
begin
bRtn:= (Form1.webbrowser1.Document as
IHTMLDocument2).queryCommandState('Italic'); if bRtn then
Result:=True
else
Result:=False;
end;
function IsUnderline():Boolean;
Var bRtn:Boolean;
begin
bRtn:= (Form1.webbrowser1.Document as
IHTMLDocument2).queryCommandState('Underline'); if bRtn then
Result:=True
else
Result:=False;
end;
function IsStrikeThrough():Boolean;
Var bRtn:Boolean;
begin
bRtn:= (Form1.webbrowser1.Document as
IHTMLDocument2).queryCommandState('StrikeThrough'); if bRtn then
Result:=True
else
Result:=False;
end;
function IsSubScript():Boolean;
Var bRtn:Boolean;
begin
bRtn:= (Form1.webbrowser1.Document as
IHTMLDocument2).queryCommandState('SubScript'); if bRtn then
Result:=True
else
Result:=False;
end;
function IsSuperScript():Boolean;
Var bRtn:Boolean;
begin
bRtn:= (Form1.webbrowser1.Document as
IHTMLDocument2).queryCommandState('SuperScript'); if bRtn then
Result:=True
else
Result:=False;
end;
function IsJustifyLeft():Boolean;
Var bRtn:Boolean;
begin
bRtn:= (Form1.webbrowser1.Document as
IHTMLDocument2).queryCommandState('JustifyLeft'); if bRtn then
Result:=True
else
Result:=False;
end;
function IsJustifyCenter():Boolean;
Var bRtn:Boolean;
begin
bRtn:= (Form1.webbrowser1.Document as
IHTMLDocument2).queryCommandState('JustifyCenter'); if bRtn then
Result:=True
else
Result:=False;
end;
function IsJustifyRight():Boolean;
Var bRtn:Boolean;
begin
bRtn:= (Form1.webbrowser1.Document as
IHTMLDocument2).queryCommandState('JustifyRight'); if bRtn then
Result:=True
else
Result:=False;
end;
function IsJustifyFull():Boolean;
Var bRtn:Boolean;
begin
bRtn:= (Form1.webbrowser1.Document as
IHTMLDocument2).queryCommandState('JustifyFull'); if bRtn then
Result:=True
else
Result:=False;
end;
function IsInsertOrderedList():Boolean;
Var bRtn:Boolean;
begin
bRtn:= (Form1.webbrowser1.Document as
IHTMLDocument2).queryCommandState('InsertOrderedList'); if bRtn then
Result:=True
else
Result:=False;
end;
function IsInsertUnorderedList():Boolean;
Var bRtn:Boolean;
begin
bRtn:= (Form1.webbrowser1.Document as
IHTMLDocument2).queryCommandState('InsertUnorderedList'); if bRtn then
Result:=True
else
Result:=False;
end;
///使用
procedure TForm1.WebBrowser1CommandStateChange(ASender:
TObject; Command: Integer; Enable: WordBool);
Var bRtn:Boolean;
begin
try
cbb_FontNameList.Text:=GetFontName();
cbb_FontSize.Text:=GetFontSize();
btn_Bold.Down:=IsBold();
btn_Italic.Down:=IsItalic();
btn_Underline.Down:=IsUnderline();
btn_strikethrough.Down:=IsStrikeThrough();
btn_SubScript.Down:=IsSubScript();
btn_SuperScript.Down:=IsSuperScript();
ToolButton_AlignTwo.Down:=IsJustifyFull();
ToolButton_AlignLeft.Down:=IsJustifyLeft();
ToolButton_AlignCenter.Down:=IsJustifyCenter();
ToolButton_AlignRight.Down:=IsJustifyRight();
ToolButton_UnoredredList.Down:=IsInsertUnorderedList();
ToolButton_OrderedList.Down:=IsInsertOrderedList();
//格式化
except
Exit;
end;
end;
|
图
备注
这个主要应用在工具栏按钮感应上
相关链接
delphi queryCommandState的更多相关文章
- Delphi WebBrowser控件的使用(大全 good)
Delphi WebBrowser控件的使用 WebBrowser控件属性:1.Application 如果该对象有效,则返回掌管WebBrowser控件的应用程序实现的自动化对象(IDis ...
- Delphi TWebBrowser
Delphi WebBrowser控件的使用 WebBrowser控件属性:1.Application 如果该对象有效,则返回掌管WebBrowser控件的应用程序实现的自动化对象(IDis ...
- 学习笔记:7z在delphi的应用
最近做个发邮件的功能,需要将日志文件通过邮件发送回来用于分析,但是日志文件可能会超级大,测算下来一天可能会有800M的大小.所以压缩是不可避免了,delphi中的默认压缩算法整了半天不太好使,就看了看 ...
- delphi连接sql存储过程
针对返回结果为参数的 一. 先建立自己的存储过程 ALTER PROCEDURE [dbo].[REName] ) AS BEGIN select ROW_NUMBER() over(order by ...
- delphi 2010与delphi XE破解版的冲突
在系统中同时安装了Dephi 2010LITE版与Delphi XE lite后,总是会有一个有问题 是因为两者都是读取C:\ProgramData\Embarcadero目录下的license文件, ...
- [Delphi] Delphi版本号对照
VER300 Delphi Seattle / C++Builder Seattle 23 230 (Delphi:Win32/Win64/OSX/iOS32/iOS64/An ...
- delphi tidhttp 超时设置无效的解决方法
现在delphi都发布到xe8了,tidhttp还有缺陷,那就是超时设置在没有网络或者连不上服务器的时候是无效的,不管你设置为多少都要10-20秒.connectTimeout和readTimeout ...
- Delphi Code Editor 之 编辑器选项
Delphi Code Editor 之 编辑器选项 可从Code Editor的右键菜单中选择“Properties”菜单项来查看编辑器选项.也可以从主菜单[Tools | Editor Optio ...
- Delphi使用ADO进行数据库编程
Delphi是一个可视化的编程工具,ADO编程也是这样,所以话不多言,直接通过代码.截图和语言来说明. 我的数据库是Oracle,为了测试,先建一个表:create table practice(un ...
随机推荐
- 在英文 sql2005中 比较nvarchar 与 varchar的速度
declare @str1 varchar(max); declare @count int; ; print 'begin' begin set @str1 = @str1 + '*'; ; end ...
- Hibernate优化
前言 在一般情况下,Hibernate需要将执行转换为SQL语句从而性能低于JDBC.但是在经过比较好的性能优化之后,性能还是让人相当满意的,特别是应用二级缓存之后,甚至可以获得比较不使用缓存的JDB ...
- web.config配置详细说明
(一).Web.Config是以XML文件规范存储,配置文件分为以下格式 1.配置节处理程序声明 特点:位于配置文件的顶部,包含在<configSections>标志中. 2.特定应 ...
- Android开源项目SlidingMenu深切解析
demo:http://download.csdn.net/detail/javadxz/6954819 SlidingMenu的是一种斗劲新的设置界面或设备界面结果,在主界面左滑或者右滑呈现设置界面 ...
- android 触摸事件、点击事件的区别
针对屏幕上的一个View控件,Android如何区分应当触发onTouchEvent,还是onClick,亦或是onLongClick事件? 在Android中,一次用户操作可以被不同的View按次序 ...
- Cake slicing
题意: n*m的方格中有k个点,现在要把方格分开使得每个点在一个部分,每分一次花费边长的费用,求完成花的最小费用 分析: dp[sx][sy][ex][ey]表示分割起点(sx,sy)终点(ex,ey ...
- VC++6.0连接Access数据库
建立一个连接数据库的类: 1.头文件:ADOConn.h #import "C:\Program Files\Common Files\System\ado\msado15.dll" ...
- webpack入门级教程
Webpack是什么 首先可以看下官方文档,文档是最好的老师. 这里也有国外的一个朋友写的入门介绍. Webpack是由Tobias Koppers开发的一个开源前端模块构建工具.它的基本功能是将以模 ...
- Blogilo:Ubuntu下“wlw”
原文首发:http://www.ido321.com/1274.html 这一篇博客是在Ubuntu的博客客户端blogilo下发布的,感觉有点高大上,特此发布一篇博文记录一下. 博客发布在 ...
- BootStrap入门教程 (四) :JQuery类库插件(模态窗口,滚动监控,标签效果,提示效果,“泡芙”效果,警告区域,折叠效果,旋转木马,输入提示)
上讲回顾:Bootstrap组件丰富同时具有良好可扩展性,能够很好地应用在生产环境.这些组件包括按钮(Button),导航(Navigation),缩略图( thumbnails),提醒(Alert) ...