Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Richedit.h from the platform SDK offers these possibilities:

 

// PARAFORMAT 2.0 masks and effects 
#define PFM_SPACEBEFORE			0x00000040
#define PFM_SPACEAFTER			0x00000080
#define PFM_LINESPACING			0x00000100

 

To use them you will need a PARAFORMAT2 struct:

 

[structLayout( LayoutKind.Sequential )]
private struct PARAFORMAT
{
   public int cbSize;
   public uint dwMask;
   public short wNumbering;
   public short wReserved;
   public int dxStartIndent;
   public int dxRightIndent;
   public int dxOffset;
   public short wAlignment;
   public short cTabCount;
   [MarshalAs( UnmanagedType.ByValArray, SizeConst = 32 )]
   public int[] rgxTabs;

   // PARAFORMAT2 from here onwards
   public int dySpaceBefore;
   public int dySpaceAfter;
   public int dyLineSpacing;
   public short sStyle;
   public byte bLineSpacingRule;
   public byte bOutlineLevel;
   public short wShadingWeight;
   public short wShadingStyle;
   public short wNumberingStart;
   public short wNumberingStyle;
   public short wNumberingTab;
   public short wBorderSpace;
   public short wBorderWidth;
   public short wBorders;
}

 

You will then need SendMessage:

 

[DllImport( "user32", CharSet = CharSet.Auto )]
private static extern IntPtr SendMessage( HandleRef hWnd, int msg, 
                                         int wParam, ref PARAFORMAT lParam );

 

Now make sure the text you want to change line spacing for is selected and do this:

 

PARAFORMAT fmt = new PARAFORMAT();
fmt.cbSize = Marshal.SizeOf( fmt );
fmt.dwMask = PFM_LINESPACING; // Or whatever
fmt.dyLineSpacing = 2; // Or whatever

// This assumes you will be calling from a class derived from RichTextBox
SendMessage( new HandleRef( this, Handle ), EM_SETPARAFORMAT,
            SCF_SELECTION, ref fmt );

 

Where the two constants used are:

 

const int SCF_SELECTION = 1;
const int EM_SETPARAFORMAT = 1095;

 

Hope this helps, it's completely untested.

 

-- Pete

  • 1 year later...
Posted

Hey all,

 

You've got to add:

 

fmt.bLineSpacingRule = somelinespacingrule;

 

right before the SendMessage call. This tells it what type of spacing to perform. Valid options are 0-5.

 

For more information on the different options, check out:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditstructures/paraformat2.asp

 

This site is the msdn article on the PARAFORMAT2 structure. I found it really helpful!

 

~~Paul

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...