Pete's Weblog

The Blog Formerly Known as Fun with WinForms

  Home  |   Contact  |   Syndication    |   Login
  15 Posts | 0 Stories | 50 Comments | 98 Trackbacks

News

Tag Cloud


Archives

Post Categories

.NET Programming

Software

Weblogs

As promised earlier, I've added the ability to change the background colour of the text. I've also made one or two minor changes to the rest of the code, which I'll detail at the end.

Background Colour

Changing the background colour is a simple matter. It works in exactly the same way as changing the underline style, by setting the character format. Since we're dealing with Color here, we need to be using System.Drawing. Then it's just a matter of sending the correct message:

+ Code to set the background colour for a selected region.

And there's one more constant to add:

private const int CFM_BACKCOLOR = 67108864;

That should now enable us to change the background colour of the text. Simple, wasn't it?

Alterations

Notice in the middle of the get method above, we return Color.Empty by default. This is because that return value is used when more than one colour is selected (like in Word when you select across several fonts and the font selection combobox goes blank). A similar approach can be taken in the alignment and underline properties presented previously.

All you have to do is add an entry to the relevant enumeration called "None" (or whatever), probably equal to zero, and return it in the appropriate get method where it says "Default to <whatever>".

Conclusion

That's it for AdvRichTextBox. If anyone is actually reading this and wants me to add more functionality (or post complete source), just leave a comment or send me an email.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted on Wednesday, October 15, 2003 7:33 PM

Feedback

# re: Extending RichTextBox - Part III 10/17/2003 5:16 PM Oscar Perez
Hi,

I'm trying to write a similar code in vb.net (to get the format of a richtextbox selected text) with the message EM_GETCHARFORMAT, but by any reasson it doesn't work. What is wrong?

'CHARFORMAT
<StructLayout(LayoutKind.Sequential)> _
Public Structure STRUCT_CHARFORMAT
Public cbSize As Integer
Public dwMask As UInt32
Public dwEffects As UInt32
Public yHeight As Int32
Public yOffset As Int32
Public crTextColor As Int32
Public bCharSet As Byte
Public bPitchAndFamily As Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=32)> _
Public szFaceName() As Char
End Structure

Function IsBold() As Boolean
Dim cf As New STRUCT_CHARFORMAT()
cf = GetSelectionStyle(CFM_BOLD)

If cf.dwEffects.Equals(CFE_BOLD) Then
Return True
Else
Return False
End If

End Function

Function GetSelectionStyle(ByVal mask As Int32) As STRUCT_CHARFORMAT
Dim cf As New STRUCT_CHARFORMAT()
cf.cbSize = Marshal.SizeOf(cf)
cf.dwMask = Convert.ToUInt32(mask)

Dim lParam As IntPtr
lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(cf))
Marshal.StructureToPtr(cf, lParam, False)

SendMessage(Me.Handle, EM_GETCHARFORMAT, SCF_SELECTION, lParam)
Return cf
End Function


Thanks a lot

# re: Extending RichTextBox - Part III 10/17/2003 5:46 PM Pete Vidler
Hi,

To start with, you don't need to set dwMask if you're using EM_GETCHARFORMAT. You only need that to set the format. Also, I don't think you need to use AllocCoTaskMem (I didn't and it works fine).

Other than that there are a few things I suggest you check:

1) The CHARFORMAT struct must be passed by reference to SendMessage. In c# you would need "ref" before "lParam", but I don't know if it's necessary in VB.

2) I don't see why you need StructureToPtr? Just pass a reference. You can DllImport a separate version of SendMessage that takes a reference of CHARFORMAT rather than always using the IntPtr one.

3) Is your selection correct? If the selection crosses a boundary (where some text in the selection is bold and some isn't) it won't return anything. You will be able to tell when this happens because dwMask will not have the CFM_BOLD bit set (which is why you shouldn't set it yourself).

Hope that helps, if you still have problems please feel free to post another comment.

# re: Extending RichTextBox - Part III 3/10/2004 1:11 AM Eric Bickle
I just wanted to let you know that you're articles on extending the RichTextBox control are great!

You're E-Mail seems to be down, however :( If you want to contact me, feel free to do so at ebickle ---at--- healthspace.ca
I'm currently working on a project creating some input controls that mimic the Lotus Notes behavior; dynamically expanding and resizing edit controls that simulate a document-style layout in a winform. If you're interested in seeing what I've done, let me know!

I made a few changes to your RichEdit code.
* Set the SelectionAlignment/SelectionBackColor/etc properties to disable designer serialization (ie/ those properties shouldn't save into the 'Windows Form Designer Generated Code' section. I also made them so they aren't browsable in the designer (they are runtime properties, not designtime properties)

* Fixed the SelectionBackColor property so that setting a value of "Color.Empty" will reset the background color to default. Getting a default SelectionBackColor returns "Color.Empty" instead of "Color.Black" now.

* Added a few extra enumeration members here and there to allow for unspecified values (as you mentioned in your blog).

I've pasted the code to the bottom of this message; you're welcome to use my changes however you see fit; think of it as public domain.

You'll probably want to change the namespace and class name if you use my code. Also, I've added a "RemoveTheme" call that disables Windows XP theming on the rich edit control. Since I host it by a special parent control with it's own border, I need to make sure all themes are disabled. You'll probably want to remove those calls.

Thanks,
Eric B


/* ========================== */
/* ========================== */
/* ========================== */
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace FlatControls2
{
/// <summary>
/// Represents a custom rich text box control with additional properties for internal use.
/// </summary>
public class CustomRichTextBox : RichTextBox
{
#region Private fields and constructors

private int _Updating = 0;
private int _OldEventMask = 0;

/// <summary>
/// Initializes a new instance of the <see cref="CustomRichTextBox"/> class.
/// </summary>
public CustomRichTextBox()
{
/*
* The following list describes which versions of Rich Edit are included in which releases of Microsoft Windows®.
*
* Windows XP SP1 Includes Rich Edit 4.1, Rich Edit 3.0, and a Rich Edit 1.0 emulator.
* Windows XP Includes Rich Edit 3.0 with a Rich Edit 1.0 emulator.
* Windows Me Includes Rich Edit 1.0 and 3.0.
* Windows 2000 Includes Rich Edit 3.0 with a Rich Edit 1.0 emulator.
* Windows NT 4.0 Includes Rich Edit 1.0 and 2.0.
* Windows 98 Includes Rich Edit 1.0 and 2.0.
* Windows 95 Includes only Rich Edit 1.0. However, Riched20.dll is compatible with Windows 95 and may be installed by an application that requires it.
*/

// Remove any XP style applied to the rich text box.
RemoveTheme();
}

#endregion

#region Windows API

private const int WM_SETREDRAW = 0x0B;
private const int EM_SETEVENTMASK = 0x0431;
private const int EM_SETCHARFORMAT = 0x0444;
private const int EM_GETCHARFORMAT = 0x043A;
private const int EM_GETPARAFORMAT = 0x043D;
private const int EM_SETPARAFORMAT = 0x0447;
private const int EM_SETTYPOGRAPHYOPTIONS = 0x04CA;
private const int CFM_UNDERLINETYPE = 0x800000;
private const int CFM_BACKCOLOR = 0x4000000;
private const int CFE_AUTOBACKCOLOR = 0x4000000;
private const int SCF_SELECTION = 0x01;
private const int PFM_ALIGNMENT = 0x08;
private const int TO_ADVANCEDTYPOGRAPHY = 0x01;

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

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

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

[DllImport("uxtheme.dll", CharSet=CharSet.Unicode)]
private static extern int SetWindowTheme(
HandleRef hWnd,
[MarshalAs(UnmanagedType.LPWStr)]
string pszSubAppName,
[MarshalAs(UnmanagedType.LPWStr)]
string pszSubIdList);

/// <summary>
/// Contains information about character formatting in a rich edit control.
/// </summary>
/// <remarks><see cref="CHARFORMAT"/> works with all Rich Edit versions.</remarks>
[StructLayout(LayoutKind.Sequential)]
private struct CHARFORMAT
{
public int cbSize;
public uint dwMask;
public uint dwEffects;
public int yHeight;
public int yOffset;
public int crTextColor;
public byte bCharSet;
public byte bPitchAndFamily;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=32)]
public char[] szFaceName;
}

/// <summary>
/// Contains information about character formatting in a rich edit control.
/// </summary>
/// <remarks><see cref="CHARFORMAT2"/> requires Rich Edit 2.0.</remarks>
[StructLayout(LayoutKind.Sequential)]
private struct CHARFORMAT2
{
public int cbSize;
public uint dwMask;
public uint dwEffects;
public int yHeight;
public int yOffset;
public int crTextColor;
public byte bCharSet;
public byte bPitchAndFamily;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=32)]
public char[] szFaceName;
public short wWeight;
public short sSpacing;
public int crBackColor;
public int LCID;
public uint dwReserved;
public short sStyle;
public short wKerning;
public byte bUnderlineType;
public byte bAnimation;
public byte bRevAuthor;
}

/// <summary>
/// Contains information about paragraph formatting in a rich edit control.
/// </summary>
/// <remarks><see cref="PARAFORMAT"/> works with all Rich Edit versions.</remarks>
[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;
}

/// <summary>
/// Contains information about paragraph formatting in a rich edit control.
/// </summary>
/// <remarks><see cref="PARAFORMAT2"/> requires Rich Edit 2.0.</remarks>
[StructLayout(LayoutKind.Sequential)]
private struct PARAFORMAT2
{
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;
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;
}

#endregion

#region Property: SelectionUnderlineStyle

/// <summary>
/// Gets or sets the underline style to apply to the current selection or insertion point.
/// </summary>
/// <value>A <see cref="UnderlineStyle"/> that represents the underline style to
/// apply to the current text selection or to text entered after the insertion point.</value>
[Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public UnderlineStyle SelectionUnderlineStyle
{
get
{
CHARFORMAT2 fmt = new CHARFORMAT2();
fmt.cbSize = Marshal.SizeOf(fmt);

// Get the underline style
SendMessage(new HandleRef(this, Handle), EM_GETCHARFORMAT, SCF_SELECTION, ref fmt);
if ((fmt.dwMask & CFM_UNDERLINETYPE) == 0)
{
return UnderlineStyle.None;
}
else
{
byte style = (byte)(fmt.bUnderlineType & 0x0F);
return (UnderlineStyle)style;
}
}
set
{
// Ensure we don't alter the color
UnderlineColor color = SelectionUnderlineColor;

// Ensure we don't show it if it shouldn't be shown
if (value == UnderlineStyle.None)
color = UnderlineColor.Black;

// Set the underline type
CHARFORMAT2 fmt = new CHARFORMAT2();
fmt.cbSize = Marshal.SizeOf(fmt);
fmt.dwMask = CFM_UNDERLINETYPE;
fmt.bUnderlineType = (byte)((byte)value | (byte)color);
SendMessage(new HandleRef(this, Handle), EM_SETCHARFORMAT, SCF_SELECTION, ref fmt);
}
}

#endregion
#region Property: SelectionUnderlineColor

/// <summary>
/// Gets or sets the underline color to apply to the current selection or insertion point.
/// </summary>
/// <value>A <see cref="UnderlineColor"/> that represents the underline color to
/// apply to the current text selection or to text entered after the insertion point.</value>
[Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public UnderlineColor SelectionUnderlineColor
{
get
{
CHARFORMAT2 fmt = new CHARFORMAT2();
fmt.cbSize = Marshal.SizeOf(fmt);

// Get the underline color
SendMessage(new HandleRef(this, Handle), EM_GETCHARFORMAT, SCF_SELECTION, ref fmt);
if ((fmt.dwMask & CFM_UNDERLINETYPE) == 0)
{
return UnderlineColor.None;
}
else
{
byte style = (byte)(fmt.bUnderlineType & 0xF0);
return (UnderlineColor)style;
}
}
set
{
// If the an underline color of "None" is specified, remove underline effect
if (value == UnderlineColor.None)
{
SelectionUnderlineStyle = UnderlineStyle.None;
}
else
{
// Ensure we don't alter the style
UnderlineStyle style = SelectionUnderlineStyle;

// Ensure we don't show it if it shouldn't be shown
if (style == UnderlineStyle.None)
value = UnderlineColor.Black;

// Set the underline color
CHARFORMAT2 fmt = new CHARFORMAT2();
fmt.cbSize = Marshal.SizeOf(fmt);
fmt.dwMask = CFM_UNDERLINETYPE;
fmt.bUnderlineType = (byte)((byte)style | (byte)value);
SendMessage(new HandleRef(this, Handle), EM_SETCHARFORMAT, SCF_SELECTION, ref fmt);
}
}
}

#endregion
#region Property: SelectionBackColor

/// <summary>
/// Gets or sets the background color to apply to the
/// current selection or insertion point.
/// </summary>
/// <value>A <see cref="Color"/> that represents the background color to
/// apply to the current text selection or to text entered after the insertion point.</value>
/// <remarks>
/// <para>A value of Color.Empty indicates that the default background color is used.</para>
/// <para>If the selection contains more than one background
/// color, then this property will indicate it by
/// returning Color.Empty.</para>
/// </remarks>
[Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Color SelectionBackColor
{
get
{
CHARFORMAT2 fmt = new CHARFORMAT2();
fmt.cbSize = Marshal.SizeOf(fmt);

// Get the background color
SendMessage(new HandleRef(this, Handle), EM_GETCHARFORMAT, SCF_SELECTION, ref fmt);

// Default to Color.Empty as there could be
// several colors present in this selection
if ((fmt.dwMask & CFM_BACKCOLOR) == 0)
return Color.Empty;

// Default to Color.Empty if the background color is automatic
if ((fmt.dwEffects & CFE_AUTOBACKCOLOR) == CFE_AUTOBACKCOLOR)
return Color.Empty;

// Deal with the weird Windows color format
return ColorTranslator.FromWin32(fmt.crBackColor);
}
set
{
CHARFORMAT2 fmt = new CHARFORMAT2();
fmt.cbSize = Marshal.SizeOf(fmt);
fmt.dwMask = CFM_BACKCOLOR;
if (value.IsEmpty)
fmt.dwEffects = CFE_AUTOBACKCOLOR;
else
fmt.crBackColor = ColorTranslator.ToWin32(value);

// Set the background color
SendMessage(new HandleRef(this, Handle), EM_SETCHARFORMAT, SCF_SELECTION, ref fmt);
}
}

#endregion
#region Property: SelectionAlignment

/// <summary>
/// Gets or sets the text alignment to apply to the current
/// selection or insertion point.
/// </summary>
/// <value>A member of the <see cref="RichTextAlign"/> enumeration that represents
/// the text alignment to apply to the current text selection or to text entered
/// after the insertion point.</value>
[Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new RichTextAlign SelectionAlignment
{
get
{
PARAFORMAT2 fmt = new PARAFORMAT2();
fmt.cbSize = Marshal.SizeOf(fmt);
SendMessage(new HandleRef(this, Handle), EM_GETPARAFORMAT, SCF_SELECTION, ref fmt);

if ((fmt.dwMask & PFM_ALIGNMENT) == 0)
return RichTextAlign.Unknown;
else
return (RichTextAlign)fmt.wAlignment;
}
set
{
PARAFORMAT2 fmt = new PARAFORMAT2();
fmt.cbSize = Marshal.SizeOf(fmt);
fmt.dwMask = PFM_ALIGNMENT;
fmt.wAlignment = (short)value;

// Set the alignment
SendMessage(new HandleRef(this, Handle), EM_SETPARAFORMAT, SCF_SELECTION, ref fmt);
}
}

#endregion

#region Method: BeginUpdate

/// <summary>
/// Maintains performance while updating.
/// </summary>
/// <remarks>
/// <para>
/// It is recommended to call this method before doing
/// any major updates that you do not wish the user to
/// see. Remember to call EndUpdate when you are finished
/// with the update. Nested calls are supported.
/// </para>
/// <para>
/// Calling this method will prevent redrawing. It will
/// also setup the event mask of the underlying richedit
/// control so that no events are sent.
/// </para>
/// </remarks>
public void BeginUpdate()
{
// Deal with nested calls
_Updating++;
if (_Updating > 1)
return;

// Prevent the control from raising any events
_OldEventMask = SendMessage(new HandleRef(this, Handle), EM_SETEVENTMASK, 0, 0);

// Prevent the control from redrawing itself
SendMessage(new HandleRef(this, Handle),WM_SETREDRAW, 0, 0);
}

#endregion
#region Method: EndUpdate

/// <summary>
/// Resumes drawing and event handling.
/// </summary>
/// <remarks>
/// This method should be called every time a call is made
/// made to BeginUpdate. It resets the event mask to it's
/// original value and enables redrawing of the control.
/// </remarks>
public void EndUpdate()
{
// Deal with nested calls
_Updating--;
if (_Updating > 0)
return;

// Allow the control to redraw itself
SendMessage(new HandleRef(this, Handle), WM_SETREDRAW, 1, 0);

// Allow the control to raise event messages
SendMessage(new HandleRef(this, Handle), EM_SETEVENTMASK, 0, _OldEventMask);
}

#endregion
#region Method: RemoveTheme

/// <summary>
/// Removes the themed style from the specified window.
/// </summary>
/// <param name="handle">An <see cref="IntPtr"/> that contains the window handle (HWND) of the control.</param>
private void RemoveTheme()
{
// Check OS version
bool supportsThemes = false;
if (System.Environment.OSVersion.Version.Major > 5)
supportsThemes = true;
else if ((System.Environment.OSVersion.Version.Major == 5) && (System.Environment.OSVersion.Version.Minor >= 1))
supportsThemes = true;

// Call API function
if (supportsThemes)
SetWindowTheme(new HandleRef(this, Handle), " ", " ");
}


#endregion
#region Method: OnHandleCreated

/// <summary>
/// Raises the <see cref="HandleCreated"/> event.
/// </summary>
/// <param name="e">An <see cref="EventArgs"/> that contains the event data.</param>
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);

// Enable support for justification
SendMessage(new HandleRef(this, Handle), EM_SETTYPOGRAPHYOPTIONS, TO_ADVANCEDTYPOGRAPHY, TO_ADVANCEDTYPOGRAPHY);
}

#endregion
}

/// <summary>
/// Specifies horizontal alignment for a segment of rich text.
/// </summary>
public enum RichTextAlign
{
/// <summary>
/// The text alignment is unknown.
/// </summary>
Unknown = 0,

/// <summary>
/// The text is aligned to the left.
/// </summary>
Left = 1,

/// <summary>
/// The text is aligned to the right.
/// </summary>
Right = 2,

/// <summary>
/// The text is aligned in the center.
/// </summary>
Center = 3,

/// <summary>
/// The text is justified.
/// </summary>
Justify = 4
}

/// <summary>
/// Specifies the underline styles for a segment of rich text.
/// </summary>
public enum UnderlineStyle
{
/// <summary>
/// No underlining.
/// </summary>
None = 0,

/// <summary>
/// Single-line solid underline.
/// </summary>
Normal = 1,

/// <summary>
/// Single-line underline broken between words.
/// </summary>
Word = 2,

/// <summary>
/// Double-line underline.
/// </summary>
Double = 3,

/// <summary>
/// 'Dotted' pattern underline.
/// </summary>
Dotted = 4,

/// <summary>
/// 'Dash' pattern underline.
/// </summary>
Dash = 5,

/// <summary>
/// 'Dash-dot' pattern underline.
/// </summary>
DashDot = 6,

/// <summary>
/// 'Dash-dot-dot' pattern underline.
/// </summary>
DashDotDot = 7,

/// <summary>
/// Single-line wave style underline.
/// </summary>
Wave = 8,

/// <summary>
/// Single-line solid underline with extra thickness.
/// </summary>
Thick = 9,

/// <summary>
/// Single-line solid underline with less thickness.
/// </summary>
HairLine = 10,

/// <summary>
/// Double-line wave style underline.
/// </summary>
DoubleWave = 11,

/// <summary>
/// Single-line wave style underline with extra thickness.
/// </summary>
HeavyWave = 12,

/// <summary>
/// 'Long Dash' pattern underline.
/// </summary>
LongDash = 13,

/// <summary>
/// 'Dash' pattern underline with extra thickness.
/// </summary>
ThickDash = 14,

/// <summary>
/// 'Dash-dot' pattern underline with extra thickness.
/// </summary>
ThickDashDot = 15,

/// <summary>
/// 'Dash-dot-dot' pattern underline with extra thickness.
/// </summary>
ThickDashDotDot = 16,

/// <summary>
/// 'Dotted' pattern underline with extra thickness.
/// </summary>
ThickDotted = 17,

/// <summary>
/// 'Long Dash' pattern underline with extra thickness.
/// </summary>
ThickLongDash = 18
}

/// <summary>
/// Specifies the color of underline for a segment of rich text.
/// </summary>
public enum UnderlineColor
{
/// <summary>
/// No specific underline color specified.
/// </summary>
None = -1,

/// <summary>
/// Black.
/// </summary>
Black = 0x00,

/// <summary>
/// Blue.
/// </summary>
Blue = 0x10,

/// <summary>
/// Cyan.
/// </summary>
Cyan = 0x20,

/// <summary>
/// LimeGreen.
/// </summary>
LimeGreen = 0x30,

/// <summary>
/// Magenta.
/// </summary>
Magenta = 0x40,

/// <summary>
/// Red.
/// </summary>
Red = 0x50,

/// <summary>
/// Yellow.
/// </summary>
Yellow = 0x60,

/// <summary>
/// White.
/// </summary>
White = 0x70,

/// <summary>
/// DarkBlue.
/// </summary>
DarkBlue = 0x80,

/// <summary>
/// DarkCyan.
/// </summary>
DarkCyan = 0x90,

/// <summary>
/// Green.
/// </summary>
Green = 0xA0,

/// <summary>
/// DarkMagenta.
/// </summary>
DarkMagenta = 0xB0,

/// <summary>
/// Brown.
/// </summary>
Brown = 0xC0,

/// <summary>
/// OliveGreen.
/// </summary>
OliveGreen = 0xD0,

/// <summary>
/// DarkGray.
/// </summary>
DarkGray = 0xE0,

/// <summary>
/// Gray.
/// </summary>
Gray = 0xF0
}
}

# re: Extending RichTextBox - Part III 3/16/2004 5:40 PM Adrin
I tried to use the code from Part III but my RTB doesn't seem to receive the paint message so it doesn't repaint again after EndUpdate().

If I hide the window (minimize, put another window in fornt of it) when I make it active again the box is updated. (strange)

Am I missing something?

These articles are great. Keep it up!

Adrin

# re: Extending RichTextBox - Part III 3/16/2004 5:42 PM Adrin
Bad mistake in my previous comment. I was referring to the Part I not Part III. :((

Adrin

# re: Extending RichTextBox - Part III 3/29/2004 6:01 AM nathan
I try to adjust the space between letter but fail. Please help me.
Thanks a lot!

# Split views! 6/25/2004 11:55 PM Formula
How could we modify the control to enable 2+ views of the same data using splitter bars?

# re: Extending RichTextBox - Part III 7/1/2004 8:27 AM jdeboard@bellsouth.net
Great stuff! Thanks

# re: Extending RichTextBox - Part III 8/21/2004 6:28 AM Wandrey
Very Cool code!!!!! I am looking for this!!!
Anymore can send more project/code to me ???
Thanks!

# re: Extending RichTextBox - Part III 8/21/2004 6:29 AM Wandrey
Very Cool code!!!!! I am looking for this!!!
Anymore can send more project/code to me ???
wandreyar@hotmail.com
Thanks!


# re: Extending RichTextBox - Part III 8/22/2004 12:30 PM Pete
It's amazing that people are still commenting on this so long after it was made! Thanks to all of you, but I no longer use C# (although I'm considering getting into C++/CLI) so I can't help with any of this code.

Oh and my email has changed to pvidler@mailblocks.com. If you email me there you should receive an automated response asking you to go to a website and prove that you are human -- only then will your email reach me. :)

# re: Extending RichTextBox - Part III 8/26/2004 5:44 PM supra
can u send me zip file? mine isn't working
regards,
supra

# re: Extending RichTextBox - Part III 8/26/2004 7:50 PM Pete
Unfortunately I no longer have a copy of this code. All I have is on this site. But I did test this at one point, so it should work okay.

# re: Extending RichTextBox - Part III 10/14/2004 12:22 PM Parag Tikle
Hi ,it's a nice article in c# . iTested it but it fails to complied and giving error for "Handle" .Any way it's anice solution.
But iwant to give spellchecking functionality in textBox.
I captuared Line and column no in multiline textbox with sendmessage api function.
"-------But i want draw underline of wrongly spelled word ---"
Do u have any solution for that ?

If able to send pls send me,thanx inadvance.
mail me:parag.tikle@mynetsec.com

# re: Extending RichTextBox - Part III 11/15/2004 2:08 AM James Hancock
Fantastic work!!!!

Now my wish list only includes:

Save/Load HTML into it.
Insert of Table and Images without having to resort to copy and paste or manually editing the RTF.

Maybe we can at least get teh Table and Images stuff done, since the control natively supports it :)

# RichTextBox Fonts Problem 11/26/2004 6:39 AM Amit Yaduwanshi
Richtextbox leaves space between some characters when using Hindi Fonts.
Any solution?

# re: Extending RichTextBox - Part III 1/7/2005 9:40 PM Howie
Very nice job.... I have spent a lot of time to study your code. Now I am going to add more features on the richtextbox such as changing selected font size or font family. As you know, SelectionFont is the only build-in property to modify the selected font's size and family. If the selected text has various font size, SelectionFont.Size is an invalid value. In this case, therefore, I cannot use RichTextBox1.SelectionFont = new Font(New Font Family, Selected Font Size) to modify the font family. Could you give me some hint or tell me what classes or functions I might need?
Thanks

# re: Extending RichTextBox - Part III 1/24/2005 12:04 PM Eric Engler
At the very end of your EndUpdate method you have to add this line:
this.Refresh();

This ensures that the control gets repainted.

Otherwise, this is great code! Thanks to everyone who contributed!


# re: Format question 1/28/2005 10:29 AM Chessandmat
Hello,
Your help is very cool but I have steel a problem.
Indeed, if my richtextbox selection font is heterogeneous (for example, the start is bold and not the end) and I want all my selection become italic, all my selection become bold too.
Do you know how can I do.
There is a worst example: if I have in my selection two fontfamily I can't change the format or the size in keeping the font families.
I find a solution but it is too bad to use it:
I apply change on all characters of my selection.
I think that I can keep on a arraylist the position when the font change, but it is too bad.
I need you to help me please.

# re: Extending RichTextBox - Part III 2/9/2005 2:12 PM meetquant
Looks really cool codes..and very indepth coverage going on here.. I've to go through it, BTW how can a multipage document/text can be displayed in page-wise manner (as in MS WOrd) in RTB Control, rather than displaying as a single contigious page. (Page numbering will be more difficult, I think, let's leave that now) By filling up with hidden chars and line-making chars? or there is some simple way thereout? I really need it. Plz help me.

# re: Extending RichTextBox - Part III 4/22/2005 3:23 PM dlondeck@ameritech.net
Is there a way to select columns 1 through 10 for all of the rows which have text in them and either cut or copy them to the clipboard or simply delete them?

Textpad and MS Word support this by holding on the alt key while selecting with your mouse.

I am trying to implement this and I am having much trouble.

Thank you.

# re: Extending RichTextBox - Part III 5/25/2005 9:31 AM Dan
how could i set the selected text from a richtextbox into bold & italic at the same time?

# re: Extending RichTextBox - Part III 7/17/2005 11:17 AM .Net Adventures
Your solution works perfectly! Thanks

# re: Extending RichTextBox - Part III 8/6/2005 1:49 PM Zbigniew Úmiechowicz
Thanks for your work on that, it's great!


# re: Extending RichTextBox - Part III 11/4/2005 11:58 AM Carl Verret
Does anyone knows how to apply underline style to a subclassed listbox ? Thanks!

# re: Extending RichTextBox - Part III 3/4/2006 12:42 AM Jon
Hi, I LOVE your article... I have something I'd love to see however. How to get controls (such as progress bars) and images into the rtb. :-)

Do you think we can see a Part IV? :-)

# re: Extending RichTextBox - Part III 3/14/2006 8:38 PM John Whattam
To Jon above,
There is already a code example on www.codeproject.com showing how to insert images, progress bars, etc into a richtextedit - see the following:
Inserting images into a RichTextBox control (the OLE way)
1 Nov 2005 By Oscar Londoño
If you find this code useful, be sure to vote for his article.

# re: Extending RichTextBox - Part III 3/8/2007 12:30 AM Arun
Thanks for the great article.

# re: Extending RichTextBox - Part III 10/12/2007 11:51 PM siulm
Is there a chance that I get a copy of the code you showed here. I have been trying to write to TextPad I am not able.
Would love to see the code you guys are talking about.

I hope it is not too late to have the joy you guys are talking about.

Thanks,
siulm

# re: Extending RichTextBox - Part III 12/19/2007 5:17 AM supra
I already done similar to mirc chat colour

u don't needed function to call.

here is code:
\\
\\
\\
ElseIf b = Chr(2) Then
Dim IsBold As Boolean = ((rtb.SelectionFont.Style And FontStyle.Bold) = FontStyle.Bold)
rtb.SelectionFont = New Font(rtb.SelectionFont, DirectCast(IIf(IsBold, rtb.SelectionFont.Style And Not FontStyle.Bold, rtb.SelectionFont.Style Or FontStyle.Bold), FontStyle))
ElseIf b = Chr(31) Then
Dim IsUnderline As Boolean = ((rtb.SelectionFont.Style And FontStyle.Underline) = FontStyle.Underline)
rtb.SelectionFont = New Font(rtb.SelectionFont, DirectCast(IIf(IsUnderline, rtb.SelectionFont.Style And Not FontStyle.Underline, rtb.SelectionFont.Style Or FontStyle.Underline), FontStyle))
ElseIf b = Chr(22) Then
Dim IsItalic As Boolean = ((rtb.SelectionFont.Style And FontStyle.Italic) = FontStyle.Italic)
rtb.SelectionFont = New Font(rtb.SelectionFont, DirectCast(IIf(IsItalic, rtb.SelectionFont.Style And Not FontStyle.Italic, rtb.SelectionFont.Style Or FontStyle.Italic), FontStyle))
ElseIf b = "" Then
b = a.Substring(n, 1)
Else
rtb.SelectedText = (b)
End If
\\
\\
\\

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: