/// <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; }
/// <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 { } }
public void SetParaFormat(bool fSelection, PARAFORMAT2 format) { format.cbSize = PARAFORMAT2.SIZE; SendMessage(new HandleRef(this, Handle), EM_SETPARAFORMAT, (fSelection ? 1 : 0), ref format); }
public PARAFORMAT2 GetParaFormat(bool fSelection) { var format = new PARAFORMAT2(); format.cbSize = PARAFORMAT2.SIZE; SendMessage(new HandleRef(this, Handle), EM_GETPARAFORMAT, (fSelection ? 1 : 0), ref format); return format; }
private static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, ref PARAFORMAT2 lParam);
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); }
//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; }
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref PARAFORMAT2 lParam);
/// <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); }