zoukankan      html  css  js  c++  java
  • 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;

     

     

       


     

    备注

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

     

    相关链接

                               

     

     




  • 相关阅读:
    layout_alignStar 与 android:layout_alignEnd
    Java学习过程中的一些知识点
    L1-054 福到了->团体程序设计天梯赛-练习集
    JS冒号的作用
    JS中(function(){xxx})(); 这种写法是什么意思?
    去除vue上方的60px空白
    vue-cli · Failed to download repo vuejs-templates/webpaack: Response code 404
    Windows 7 MBR的修复与Linux产品正确卸载
    折腾一天安装Centos7,以及后面恢复Win7引导的曲折历程
    Windows 7硬盘安装CentOS 6.4 双系统 (WIN7下硬盘安装Linux(Fedora 16,CentOS 6.2,Ubuntu 12.04))
  • 原文地址:https://www.cnblogs.com/xe2011/p/3885591.html
Copyright © 2011-2022 走看看