Esempio n. 1
0
        //获得wNumberingStyleg的返回值
        public Paraformat2NumberingStyle GetSelectionParaformat2wNumberingStyle()
        {
            PARAFORMAT2 p = new PARAFORMAT2();

            SendMessage(richTextBox.Handle, EM_GETPARAFORMAT, 0, p);
            return((Paraformat2NumberingStyle)p.wNumberingStyle);
        }
        //http://msdn.microsoft.com/en-us/library/bb787942(VS.85).aspx
        /// <summary>
        /// just testing, this is quite complicated
        /// http://msdn2.microsoft.com/en-us/library/aa140277(office.10).aspx
        /// </summary>
        public void LineSpace(LineSpaceTypes types, bool bSelectAll)
        {
            PARAFORMAT2 paraformat1 = new PARAFORMAT2();

            paraformat1.dwMask           = (int)PFM_LINESPACING;
            paraformat1.cbSize           = (int)Marshal.SizeOf(paraformat1);  //(UInt32)Marshal.SizeOf(paraformat1);
            paraformat1.bLineSpacingRule = (byte)(((int)types));
            //paraformat1.wReserved = 0;

            switch (types)
            {
            case LineSpaceTypes.Single: paraformat1.dyLineSpacing = 20; break;

            case LineSpaceTypes.OneAndHalf: paraformat1.dyLineSpacing = 30; break;

            case LineSpaceTypes.Double: paraformat1.dyLineSpacing = 40; break;
            }


            //  paraformat1.dyLineSpacing = ((int)types)40; // the above commented lie. This does need to be set
            if (bSelectAll == true)
            {
                this.SelectAll();
            }

            SendMessage(new System.Runtime.InteropServices.HandleRef(this, this.Handle), 0x447, 0, paraformat1);
            this.SelectionLength = 0;
        }
Esempio n. 3
0
        /// <summary>
        /// Sets the right indent value. Right indent is the
        /// distance to indent to the left, from the right
        /// margin. The larger the number, the further to
        /// the left the text will be indented.
        /// </summary>
        /// <param name="twipsIndentValue"></param>
        private void SetSelectionRightIndent(int twipsIndentValue)
        {
            PARAFORMAT2 pf = new PARAFORMAT2();

            pf.cbSize        = Marshal.SizeOf(pf);
            pf.dwMask        = PFM_RIGHTINDENT;
            pf.dxRightIndent = twipsIndentValue;
            SendMessage(hWnd, EM_SETPARAFORMAT, SCF_SELECTION, ref pf);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the existing vertical line spacing between
        /// lines of text, for the current text selection.
        /// </summary>
        public byte GetSelectionLineSpacing()
        {
            PARAFORMAT2 pf = new PARAFORMAT2();

            pf.cbSize  = Marshal.SizeOf(pf);
            pf.dwMask |= PFM_LINESPACING | PFM_SPACEAFTER;
            SendMessage(hWnd, EM_GETPARAFORMAT, SCF_SELECTION, ref pf);
            return(pf.bLineSpacingRule);
        }
Esempio n. 5
0
        /// <summary>
        /// Returns the rtf formatting right indent value for the
        /// selected text, in twips.
        /// </summary>
        /// <returns>The right indent value in twips.</returns>
        private int GetSelectionRightIndent()
        {
            PARAFORMAT2 pf = new PARAFORMAT2();

            pf.cbSize = Marshal.SizeOf(pf);
            pf.dwMask = PFM_RIGHTINDENT;
            SendMessage(hWnd, EM_GETPARAFORMAT, SCF_SELECTION, ref pf);
            return(pf.dxRightIndent);
        }
        public void SetSelectionLineSpacing(byte bLineSpacingRule, int dyLineSpacing)
        {
            PARAFORMAT2 format = new PARAFORMAT2();

            format.cbSize           = Marshal.SizeOf(format);
            format.dwMask           = PFM_LINESPACING;
            format.dyLineSpacing    = dyLineSpacing;
            format.bLineSpacingRule = bLineSpacingRule;
            SendMessage(this.Handle, EM_SETPARAFORMAT, SCF_SELECTION, ref format);
        }
Esempio n. 7
0
 /// <summary>
 /// Sets vertical line spacing between lines
 /// of text, for the current text selection.
 /// </summary>
 /// <param name="spacing">Set to one of the bLineSpacingRule (BL_) constants,
 /// such as "BL_SINGLE_LINE_SPACING".</param>
 public void SetSelectionLineSpacing(byte spacing)
 {
     // Ignore request if spacing value not valid.
     // Valid values are 0, 1 and 2.
     if (spacing < 3)
     {
         PARAFORMAT2 pf = new PARAFORMAT2();
         pf.cbSize           = Marshal.SizeOf(pf);
         pf.dwMask          |= PFM_LINESPACING | PFM_SPACEAFTER;
         pf.bLineSpacingRule = spacing;
         SendMessage(hWnd, EM_SETPARAFORMAT, SCF_SELECTION, ref pf);
     }
 }
        //调整高度
        public void AdjustLineSpace(RichTextBox rc, double times)
        {
            rc.SelectAll();
            //double RowDist = double.Parse(this.comboBox1.Text);
            //RichTextBox行距为RowDist

            PARAFORMAT2 fmt = new PARAFORMAT2();

            fmt.cbSize           = Marshal.SizeOf(fmt);
            fmt.bLineSpacingRule = 4; //4:固定高度
            fmt.dyLineSpacing    = (int)(((int)rc.Font.Size) * 20 * times);
            fmt.dwMask           = PFM_LINESPACING;
            SendMessage(new HandleRef(rc, rc.Handle), EM_SETPARAFORMAT, 0, ref fmt);
        }
Esempio n. 9
0
        public void SetSelectionParaFormat2(Paraformat2NumberingStyle style, Paraformat2Numbering Number)
        {
            PARAFORMAT2 p = new PARAFORMAT2();

            p.dwMask = (int)(PFM_NUMBERING | PFM_OFFSET | PFM_NUMBERINGSTART | PFM_NUMBERINGSTYLE | PFM_NUMBERINGTAB);

            p.wNumbering = (short)Number;
            //p.dxOffset = BulletIndent;
            p.wNumberingStyle = (short)style;
            p.wNumberingStart = 1;
            p.wNumberingTab   = 500;

            SendMessage(richTextBox.Handle, EM_SETPARAFORMAT, 0, p);
        }
Esempio n. 10
0
            /// <summary>
            /// 获取当前光标所在段落行距
            /// </summary>
            /// <param name="hRichEditHandle">富文本编辑器句柄</param>
            /// <returns>段落行距</returns>
            public static float GetLineSpacing(IntPtr hRichEditHandle)
            {
                PARAFORMAT2 fmt = new PARAFORMAT2();

                fmt.cbSize = Marshal.SizeOf(fmt);
                fmt.dwMask = PFM_LINESPACING;

                IntPtr lParam = Marshal.AllocCoTaskMem(fmt.cbSize);

                Marshal.StructureToPtr(fmt, lParam, true);
                NativeMethods.User32.SendMessage(hRichEditHandle, EM_GETPARAFORMAT, IntPtr.Zero, lParam);
                Marshal.FreeCoTaskMem(lParam);
                return(fmt.dyLineSpacing / 100f);
            }
Esempio n. 11
0
            /// <summary>
            /// 设置指定的富文本编辑器当前光标所在段落行距
            /// </summary>
            /// <param name="hRichEditHandle">富文本编辑器句柄</param>
            /// <param name="lineSpacing">段落行距</param>
            public static void SetLineSpacing(IntPtr hRichEditHandle, float lineSpacing)
            {
                PARAFORMAT2 fmt = new PARAFORMAT2();

                fmt.cbSize           = Marshal.SizeOf(fmt);
                fmt.bLineSpacingRule = 4;
                fmt.dyLineSpacing    = (int)(lineSpacing * 100);
                fmt.dwMask           = PFM_LINESPACING;

                IntPtr lParam = Marshal.AllocCoTaskMem(fmt.cbSize);

                Marshal.StructureToPtr(fmt, lParam, true);
                NativeMethods.User32.SendMessage(hRichEditHandle, EM_SETPARAFORMAT, IntPtr.Zero, lParam);
                Marshal.FreeCoTaskMem(lParam);
            }
Esempio n. 12
0
        /// <summary>
        /// 设置行距
        /// </summary>
        /// <param name="ctl">控件</param>
        /// <param name="dyLineSpacing">间距</param>
        public static void SetLineSpace(Control ctl, int dyLineSpacing)
        {
            PARAFORMAT2 fmt = new PARAFORMAT2();

            fmt.cbSize           = Marshal.SizeOf(fmt);
            fmt.bLineSpacingRule = 4;// bLineSpacingRule;
            fmt.dyLineSpacing    = dyLineSpacing;
            fmt.dwMask           = PFM_LINESPACING;
            try
            {
                SendMessage(new HandleRef(ctl, ctl.Handle), EM_SETPARAFORMAT, 0, ref fmt);
            }
            catch
            {
            }
        }
Esempio n. 13
0
        /// <summary>
        /// 设置行距
        /// </summary>
        /// <param name="ctl">控件</param>
        /// <param name="dyLineSpacing">间距</param>
        public static void SetLineSpace(Control ctl, int dyLineSpacing)
        {
            //1像素=15缇。
            dyLineSpacing = dyLineSpacing * 15;
            //4:dylinespace成员以  缇。的形式指定从一行到下一行的间距。控件使用指定的精确间距,即使dylinespace指定的值小于单个间距。
            //3:dylinespace成员以  缇。的形式指定从一行到下一行的间隔。但是,如果dylinespace指定的值小于单间距,则控件将显示单间距文本。
            byte        bLineSpacingRule = (byte)3;
            PARAFORMAT2 fmt = new PARAFORMAT2();

            fmt.cbSize           = Marshal.SizeOf(fmt);
            fmt.bLineSpacingRule = bLineSpacingRule;
            fmt.dyLineSpacing    = dyLineSpacing;
            fmt.dwMask           = PFM_LINESPACING;
            try
            {
                SendMessage(new HandleRef(ctl, ctl.Handle), EM_SETPARAFORMAT, bLineSpacingRule, ref fmt);
            }
            catch
            { }
        }
Esempio n. 14
0
        public void NumberedBullet(bool TurnOn)
        {
            PARAFORMAT2 paraformat1 = new PARAFORMAT2();

            paraformat1.dwMask = (int)(PFM_NUMBERING | PFM_OFFSET | PFM_NUMBERINGSTART | PFM_NUMBERINGSTYLE | PFM_NUMBERINGTAB);
            if (!TurnOn)
            {
                paraformat1.wNumbering = 0;
                paraformat1.dxOffset   = 0;
            }
            else
            {
                paraformat1.wNumbering      = (short)_BulletType;
                paraformat1.dxOffset        = this.BulletIndent;
                paraformat1.wNumberingStyle = (short)_BulletStyle;
                paraformat1.wNumberingStart = _BulletNumberStart;
                paraformat1.wNumberingTab   = 500;
            }
            SendMessage(new System.Runtime.InteropServices.HandleRef(this, this.Handle), 0x447, 0, paraformat1);
        }
Esempio n. 15
0
        public void NumberedBullet(bool TurnOn)
        {
            PARAFORMAT2 paraformat1 = new PARAFORMAT2();//初始化类PARAFORMAT2的一个新实例

            paraformat1.dwMask = (int)(PFM_NUMBERING | PFM_OFFSET | PFM_NUMBERINGSTART |
                                       PFM_NUMBERINGSTYLE | PFM_NUMBERINGTAB); //设置实例的dwMask属性
            if (!TurnOn)                                                       //当和TurnOn的初始值相反时
            {
                paraformat1.wNumbering = 0;                                    //设置wNumbering属性为0
                paraformat1.dxOffset   = 0;                                    //设置dxOffset属性为0
            }
            else//当和TurnOn的初始值相同时
            {
                paraformat1.wNumbering      = (short)_BulletType;  //设置wNumbering的值
                paraformat1.dxOffset        = this.BulletIndent;   //设置dxOffset的值
                paraformat1.wNumberingStyle = (short)_BulletStyle; //设置项目编号的样式
                paraformat1.wNumberingStart = _BulletNumberStart;  //设置项目编号的起始位置
                paraformat1.wNumberingTab   = 500;                 //设置按Tab键文本移动的距离
            }
            SendMessage(new System.Runtime.InteropServices.HandleRef(this, this.Handle),
                        0x447, 0, paraformat1);//发送指定的消息
        }
        public void NumberedBullet(bool TurnOn)
        {
            PARAFORMAT2 paraformat1 = new PARAFORMAT2();//初始化類PARAFORMAT2的一個新實例

            paraformat1.dwMask = (int)(PFM_NUMBERING | PFM_OFFSET | PFM_NUMBERINGSTART |
                                       PFM_NUMBERINGSTYLE | PFM_NUMBERINGTAB); //設定實例的dwMask屬性
            if (!TurnOn)                                                       //當和TurnOn的預設值相反時
            {
                paraformat1.wNumbering = 0;                                    //設定wNumbering屬性為0
                paraformat1.dxOffset   = 0;                                    //設定dxOffset屬性為0
            }
            else//當和TurnOn的預設值相同時
            {
                paraformat1.wNumbering      = (short)_BulletType;  //設定wNumbering的值
                paraformat1.dxOffset        = this.BulletIndent;   //設定dxOffset的值
                paraformat1.wNumberingStyle = (short)_BulletStyle; //設定項目編號的樣式
                paraformat1.wNumberingStart = _BulletNumberStart;  //設定項目編號的起始位置
                paraformat1.wNumberingTab   = 500;                 //設定按Tab鍵文字移動的距離
            }
            SendMessage(new System.Runtime.InteropServices.HandleRef(this, this.Handle),
                        0x447, 0, paraformat1);//發送指定的消息
        }
Esempio n. 17
0
 private static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, ref PARAFORMAT2 lParam);
Esempio n. 18
0
 public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, ref PARAFORMAT2 pf2);
 public static extern IntPtr SendMessage(System.Runtime.InteropServices.HandleRef hWnd, int msg, int wParam, [In, Out, MarshalAs(UnmanagedType.LPStruct)] PARAFORMAT2 lParam);
Esempio n. 20
0
 private static extern IntPtr SendMessage(IntPtr hWnd, uint msg, uint wParam, [In, Out, MarshalAs(UnmanagedType.LPStruct)] PARAFORMAT2 lParam);
 private static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, UInt32 wParam, ref PARAFORMAT2 lParam);
 private static extern int SendMessage(HandleRef hWnd, int _msg, int wParam, ref PARAFORMAT2 _pf);
 private static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam,
                                          [In, Out, MarshalAs(UnmanagedType.LPStruct)] PARAFORMAT2 lParam); //定義一個向視窗進程發送消息的API函數
Esempio n. 24
0
 public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref PARAFORMAT2 lParam);