delphi queryCommandState

如何
获取当前光标所在的字符属性

关键点

function queryCommandState(const cmdID: WideString): WordBool;
safecall;

  1. 粗体

  2. 斜体
  3. 下划线
  4. 删除线
  5. 对齐方式 左 中 右
  6. 数字排序
  7. 圆的排序
  8. 上标
  9. 下标

function queryCommandValue(const cmdID: WideString): OleVariant;
safecall;

  1. 字体名称

  2. 字符大小

实现过程

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;

备注

这个主要应用在工具栏按钮感应上

相关链接

来自为知笔记(Wiz)

delphi queryCommandState

时间: 2024-08-08 09:27:48

delphi queryCommandState的相关文章

delphi 01设置 字体属性

设置/获取 字体属性 名称 大小 粗体 斜体 下划线 删除线 颜色1 颜色2 uses MSHTML; //设置 //------------------------------------------------------------------------------procedure WB_SetFontName();begin  (Form1.webbrowser1.Document as IHTMLDocument2).execCommand('FontName', False, F

Delphi WebBrowser控件的使用(大全 good)

Delphi WebBrowser控件的使用 WebBrowser控件属性:1.Application      如果该对象有效,则返回掌管WebBrowser控件的应用程序实现的自动化对象(IDispatch).如果在宿主对象中自动化对象无效,程序将返回WebBrowser控件的自动化对象2.Parent       返回WebBrowser控件的父自动化对象,通常是一个容器,例如是宿主或IE窗口3.Containe       返回WebBrowser控件容器的自动化对象.通常该值与Pare

Delphi中Twebbrowser的document 对象的属性、方法、事件一览(转)

Delphi中Twebbrowser的document 对象的属性.方法.事件一览(转) 2012-12-07 10:19:39|  分类: Delphi 零碎 |  标签:webbrowser  属性  方法  事件  delphi   |举报 |字号大中小 订阅 {ihtmldocument2 方法:}write //写入writeln //写入并换行open //打开一个流,以收集 document.write 或 document.writeln 的输出close //关闭并输出用 do

delphi execCommand

WebBrowser1.Document as IHTMLDocument2 关键点 function execCommand(const cmdID: WideString; showUI: WordBool; value: OleVariant): WordBool; safecall; 实现过程 uses OleCtrls,ComObj,Mshtml,ActiveX; ///网页查看模式 (WebBrowser1.Document as IHTMLDocument2).designMode

Delphi常用系统函数总结

字符串处理函数 Unit System 函数原型 function Concat(s1 [, s2,..., sn]: string): string; 说明 与 S := S1 + S2 + S3 ...; 相同. 将字符串相加. 函数原型 function Copy(S: string; Index, Count: Integer): string;说明 S : 字符串. Indexd : 从第几位开始拷贝. Count : 总共要拷贝几位. 从母字符串拷贝至另一个字符串. 函数原型 pro

最新的Delphi版本号对照

The CompilerVersion constant identifies the internal version number of the Delphi compiler. It is defined in the System unit and may be referenced either in code just as any other constant: if CompilerVersion = 20 then sCompilerName := 'Delphi 2009';

Delphi XE10 dxLayoutControl 控件应用指南

http://www.cnblogs.com/Bonny.Wong/p/7440288.html DevExpress VCL套件是一套非常强大的界面控件,可惜关于Delphi开发方面的说明太少,有些控件使用起来一头雾水,不知从何下手.本节详细介绍在Delphi Xe10 Seattle中如何利用dxLayoutControl 控件来做界面布局. 1.  首先从工具箱面板中将dxLayoutControl放在Form上,设置2个关键属性如下: 属性 属性值 说明 Align alClient 一

delphi 移动开发博客地址收集

这个是各位博主学习整理的笔记,很值得大家学习. XE2011的博客: http://www.cnblogs.com/xe2011/ 万一的博客:http://www.cnblogs.com/del/ 武稀松的博客:http://www.raysoftware.cn/ delphiteacher的博客:http://blog.csdn.net/DelphiTeacher 我一路走来的博客:http://blog.csdn.net/tingsking18/article/details/477210

Delphi使用android的NDK是通过JNI接口,封装好了,不用自己写本地代码,直接调用

一.Android平台编程方式:      1.基于Android SDK进行开发的第三方应用都必须使用Java语言(Android的SDK基于Java实现)      2.自从ndk r5发布以后,已经允许完全用C/C++ 来开发应用或者游戏,而不再需要编写任何Java 的代码   Android程序运行在Dalvik虚拟机中,NDK允许用户使用类似C / C++之类的原生代码语言执行部分程序. 二.跨平台移动开发   Delphi使用android的NDK是通过JNI接口,封装好了,不用自己