rich text increase space between lines?

The only way I can think of is to handle KeyDown and add an extra space when e.KeyCode==(int)Keys.SpaceBar.
 
Richedit.h from the platform SDK offers these possibilities:

C#:
// 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:

C#:
[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:

C#:
[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:

C#:
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:

C#:
const int SCF_SELECTION = 1;
const int EM_SETPARAFORMAT = 1095;

Hope this helps, it's completely untested.

-- Pete
 
Back
Top