Pete's Weblog

The Blog Formerly Known as Fun with WinForms

  Home  |   Contact  |   Syndication    |   Login
  14 Posts | 0 Stories | 37 Comments | 100 Trackbacks

News

Archives

Post Categories

.NET Programming

Software

Weblogs

For a while now I've been toying with the idea of writing a C# editor (almost an IDE, but with only the features that I need). Clearly the hardest part of this task would be getting some form of edit control working.. the obvious choice for which is the RichTextBox. Anyone who has tried using RichTextBox in this situation will know that it has a number of flaws, the most serious being that it's rather slow when trying to colourise the text.

I've long since given up on using RichTextBox for a code editor, but while I was investigating its use I came across a number of ways to improve it's functionality. I'll present these here in a series of posts on the subject.. first up is how to speed up the control's updating, as well as adding one little extra formatting option.

Faster Updating

There are articles on this subject on the internet. The standard method seems to be to send a WM_SETREDRAW message to prevent the control from being redrawn while updating. I had this implemented and running nicely when I came across another article showing that an extra speed increase can be gained by sending EM_SETEVENTMASK to prevent the control from handling events. Here's the code:

+ Code to help speed up RichTextBox updating.

Although I'm using HandleRef here, I have absolutely no idea if this is the correct usage (or even if it's needed). Full code will be at the end of this posting. I have not fully tested these methods so I have no idea what the performance gains might be (if there are any). If anyone wants to try benchmarking, please let me know the results.

Justification

It always bothered me that the SelectionAlignment property of RichTextBox does not allow fully justified text. Especially since I know it's possible with the richedit control that RichTextBox wraps. Here's some code that will replace SelectionAlignment with something a little nicer for those that are writing word processors in C#:

+ Code to allow justified text in the RichTextBox.

The TextAlign enumeration contains Left, Right, Center and Justify. Again, this is mostly untested -- it should work on any machine with the richedit 2.0 common control (I believe), but I offer no guarantees.

Code

Here's the full code for the AdvRichTextBox control (plus the TextAlign enumeration):

+ Full AdvRichTextBox code.

Conclusion

I'll add to this code in future posts and if anyone has any comments or suggestions (or even requests), feel free to ask them. Hope you found this useful.

posted on Tuesday, October 14, 2003 5:02 PM

Feedback

# re: Extending RichTextBox 12/3/2003 5:25 PM Eugene Mortimore
Hi,

Thanks Sooo Much! for your Extending RichTextBox articles -
very-helpful.

Do you know of anyone who put those extensions into a
standalone .Net WinForm control to bring into a VSNet
project?

Thanks
Gene



# re: Extending RichTextBox 5/5/2004 4:10 AM Asim
Hi,

Can you help meinadding Pagebreaks in a richtextbox.

I am in dire need of this functionality

Thanks in advance.
Asim

# re: Extending RichTextBox 5/9/2004 8:46 PM Repstat
EXCELLENT! you are a genius

# re: Extending RichTextBox 7/14/2004 2:49 PM jackz
This is good stuff.
I have a simple problem I can't get over with richTextBox. I am dragging text over and dropping it in the middle of other text. - Using the Rtf of the text, I can't find the insertion point SelectionStart is only for the Text property, not the Rtf.

How do I find Rtf insertion point without lots of code?
Thanks.

# re: Extending RichTextBox 7/20/2004 7:00 AM gof
After hours and hours searching I finally found what I was looking for :)
Thank you, thank you, thank you



# re: Extending RichTextBox 7/30/2004 12:51 PM mav.northwind
Your RichTextBox extension partially overlaps with an article of mine on <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/wnf_RichTextBox.asp">MSDN</a>, so you could save yourself some time with the code published there (regarding printing, for example).

Oh, and btw. in EndUpdate() I think it should read
<pre>if ( updating < 0 )</pre>
instead of
<pre> if ( updating > 0 )</pre>

mav


# re: Extending RichTextBox 8/9/2004 10:52 PM phil
Hi,
can you help me figure out how i can set number bullets and keep them even when we enter 2 "enter key". When we press Shift + Ctrl + L it goes through the bullet styles but no public inerface or properties to set it.
thanks


# re: Extending RichTextBox 8/22/2004 12:15 PM Pete
Wow, so many comments... sorry I haven't been back to this site in a while.

mav.northwind: Your link doesn't appear to work. Also, EndUpdate is correct as it should only reset the events to the richtextbox when updating is finished.

phil: Sorry, I have no idea -- it's been too long since I touched this stuff.

# re: Extending RichTextBox 8/22/2004 12:17 PM Pete
On closer examination the link does work, it's just the browser picking up extra junk (the ">MSDN</a>").

# re: Extending RichTextBox 10/13/2004 5:37 AM Nitin Rastogi
Hi,

I want some of the text in RichTextBox to be right indented. Can some point to how it can be done?

--Nitin

# re: Extending RichTextBox 10/29/2004 3:40 AM Tran Thien Nhan
thank you very much


# re: Extending RichTextBox 11/16/2004 9:47 AM matthieu
Thank you for your job. It's great.
I have one question.
During a selection, I have some bold caracters and some italic caracters for example.
When I use the FontDialog class, I must enter the style and so the style selection become always the same even if I just want to change the size of font.
Do you know how I can doing?


# re: Extending RichTextBox 11/26/2004 12:10 AM Pet
I need to show editable form fields. Can I ??

# re: Extending RichTextBox 1/26/2005 8:55 AM greeky creek
any comment for number bulleting
my email is garconalapipe@hotmail.com

# re: Extending RichTextBox 2/1/2005 9:37 AM Jaan Ji
I need help for making Numbering (Bullets and Numbering) List so any body know about this ?????????

# re: Extending RichTextBox 2/24/2005 1:52 AM reinux
I'm having a problem with RichTextEdit.AppendText pounding the GC. At first it causes a gen 0 collection pretty much every call, and then more later.

Are there any ways to get around this?

Thanks in advance.

# re: Extending RichTextBox 2/25/2005 12:24 AM Al
If I insert data towards the bottom of the AdvRichTextBox when scrollbars are present the control scrolls so that the cursor is now at the top of the control. I don't want this functionality i just wan the view to remain unchanged. Any thoughts?

# re: Extending RichTextBox 3/25/2005 6:27 PM Craig

I'm having the same problem as 'reinux'. Has anyone figured out how to prevent AppendText causing scrolling to be incredibly slow? I'm simulating an overnight load on a richtextbox log window and loading in, line by line, 13M of a previously recorded log. Slowly but surely scrolling becomes *incredibly* slow.

I see the same behavior when I set SelectedText to supposedly add the new line of text without creating copying the existing contents

private void DoAppend(string m)
{
// richTextBox1.AppendText(m + Environment.NewLine);
richTextBox1.SelectionStart = richTextBox1.Text.Length;
richTextBox1.SelectedText = m + Environment.NewLine;
}

Craig


# need code for changing selected rtb text format 3/28/2005 10:49 AM dhana
i need a code to change format the selected text of rich text box in vb.net. vb.net tells that

RTF1.SelectionFont.Bold is readonly property.

other wise, how can i make it possible.

tellme.
dhana.

#  RichTextBox 5/17/2005 7:25 AM raj

i use your adv rtf control ,fine.

i have a problem with rtf control.

to disable scroll , while scan entire text for color changing,
or to restore old position after scanning.

i tried lot not working

and another
in rtf Additional new line control charater is found in rich text box. Is there any way to disable that.


#  RichTextBox 5/17/2005 7:25 AM raj

i use your adv rtf control ,fine.

i have a problem with rtf control.

to disable scroll , while scan entire text for color changing,
or to restore old position after scanning.

i tried lot not working

and another
in rtf Additional new line control charater is found in rich text box. Is there any way to disable that.


# re: Extending RichTextBox 7/6/2005 5:23 AM JM
To toggle the font to bold in VB .Net

Dim tb As RichTextBox

tb.SelectionFont = New Font(tb.SelectionFont, FontStyle.Bold)



# re: Extending RichTextBox 9/23/2005 9:31 AM Manohar
Its really gr8 , thanks for writing such a nice article.It helped me a lot.Keep writing the articles of pratical usage.Once again I thank for writing this kind of article.

# re: Extending RichTextBox 11/20/2005 8:39 PM David Douglass
This works excellent as far as speeding up the SelectionColor process, but I have a different problem now.

It colors all the right selected text to the color of blue, but then the very next time I populate the RichTextBox all of the text turns blue.

I've tried to reset the forecolor and the selectedColor to black each time before using it again, but it insists on coloring all of the text blue!

# re: Extending RichTextBox 11/24/2005 2:16 PM Alex Malyakin
I have a problem with a RichTextBox control.
It does not properly support Punjabi font.
The same file with the same program it works on Windos 2000 but does not on XP it adds spaces inside the word.

I tried on many computers and it's the same.
Please help me....

# re: Extending RichTextBox 11/25/2005 1:38 PM jim
I had the same problem as Al, adding text when scrollbars are present makes the cursor scroll up to the top of the control.
This can be prevented by adding the following code to store then restore the scroll position at the end of the update.



//used for saving and restoring the scroll position to avoid flickering...
[StructLayout(LayoutKind.Sequential)]
private struct POINT
{
public long X;
public long Y;
}

private const int EM_GETSCROLLPOS = 0x0400 + 221;
private const int EM_SETSCROLLPOS = 0x0400 + 222;

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


//used to store the scroll position at the start of updating
POINT _scrollpos = new POINT();


//--------Add this code to BeginUpdate() after "if ( updating > 1 ) return;"----------

//store the current scrollposition
SendMessage(new HandleRef(this, Handle), EM_GETSCROLLPOS, 0, ref _scrollpos);
//------------------------------------------------------------------------------------


//--------Add this code to EndUpdate() after "if ( updating > 1 ) return;"------------

//restore the scrollposition
SendMessage(new HandleRef(this, Handle), EM_SETSCROLLPOS, 0, ref _scrollpos);
//------------------------------------------------------------------------------------

# re: Extending RichTextBox 2/11/2006 6:19 AM Scott Campbell
I hate to tell you this, but number bullets isn't supported in the .NET Framework. Even 2.0 Framework doesn't have it.

To do bullets you need to do some unsafe calls so you can send a message to the richtextbox and tell it to use number/letter/normal bulleting.

# re: Extending RichTextBox 2/11/2006 6:26 AM Scott Campbell
OK. Here is some sample code for adding numbered bulleting to your richtextbox.

You need to add a few usings.
using System.Runtime.InteropServices;

Then a structure for paragraph formatting. .NET Framework only has PARAFORMAT (not the extended version)
[StructLayout(LayoutKind.Sequential)]
public class PARAFORMAT2
{
public int cbSize;
public int 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 = 0x20)]
public int[] rgxTabs;

public int dySpaceBefore; // Vertical spacing before para
public int dySpaceAfter; // Vertical spacing after para
public int dyLineSpacing; // Line spacing depending on Rule
public short sStyle; // Style handle
public byte bLineSpacingRule; // Rule for line spacing (see tom.doc)
public byte bOutlineLevel; // Outline Level
public short wShadingWeight; // Shading in hundredths of a per cent
public short wShadingStyle; // Byte 0: style, nib 2: cfpat, 3: cbpat
public short wNumberingStart; // Starting value for numbering
public short wNumberingStyle; // Alignment, Roman/Arabic, (), ), ., etc.
public short wNumberingTab; // Space bet 1st indent and 1st-line text
public short wBorderSpace; // Border-text spaces (nbl/bdr in pts)
public short wBorderWidth; // Pen widths (nbl/bdr in half twips)
public short wBorders; // Border styles (nibble/border)

public PARAFORMAT2()
{
this.cbSize = Marshal.SizeOf(typeof(PARAFORMAT2));
}
}


Then some code to do numbering.

#region PARAFORMAT MASK VALUES
// PARAFORMAT mask values
private const uint PFM_STARTINDENT = 0x00000001;
private const uint PFM_RIGHTINDENT = 0x00000002;
private const uint PFM_OFFSET = 0x00000004;
private const uint PFM_ALIGNMENT = 0x00000008;
private const uint PFM_TABSTOPS = 0x00000010;
private const uint PFM_NUMBERING = 0x00000020;
private const uint PFM_OFFSETINDENT = 0x80000000;

// PARAFORMAT 2.0 masks and effects
private const uint PFM_SPACEBEFORE = 0x00000040;
private const uint PFM_SPACEAFTER = 0x00000080;
private const uint PFM_LINESPACING = 0x00000100;
private const uint PFM_STYLE = 0x00000400;
private const uint PFM_BORDER = 0x00000800; // (*)
private const uint PFM_SHADING = 0x00001000; // (*)
private const uint PFM_NUMBERINGSTYLE = 0x00002000; // RE 3.0
private const uint PFM_NUMBERINGTAB = 0x00004000; // RE 3.0
private const uint PFM_NUMBERINGSTART = 0x00008000; // RE 3.0

private const uint PFM_RTLPARA = 0x00010000;
private const uint PFM_KEEP = 0x00020000; // (*)
private const uint PFM_KEEPNEXT = 0x00040000; // (*)
private const uint PFM_PAGEBREAKBEFORE = 0x00080000; // (*)
private const uint PFM_NOLINENUMBER = 0x00100000; // (*)
private const uint PFM_NOWIDOWCONTROL = 0x00200000; // (*)
private const uint PFM_DONOTHYPHEN = 0x00400000; // (*)
private const uint PFM_SIDEBYSIDE = 0x00800000; // (*)
private const uint PFM_TABLE = 0x40000000; // RE 3.0
private const uint PFM_TEXTWRAPPINGBREAK = 0x20000000; // RE 3.0
private const uint PFM_TABLEROWDELIMITER = 0x10000000; // RE 4.0

// The following three properties are read only
private const uint PFM_COLLAPSED = 0x01000000; // RE 3.0
private const uint PFM_OUTLINELEVEL = 0x02000000; // RE 3.0
private const uint PFM_BOX = 0x04000000; // RE 3.0
private const uint PFM_RESERVED2 = 0x08000000; // RE 4.0

public enum AdvRichTextBulletType
{
Normal = 1,
Number = 2,
LowerCaseLetter = 3,
UpperCaseLetter = 4,
LowerCaseRoman = 5,
UpperCaseRoman = 6
}

public enum AdvRichTextBulletStyle
{
RightParenthesis = 0x000,
DoubleParenthesis = 0x100,
Period = 0x200,
Plain = 0x300,
NoNumber = 0x400
}
#endregion

[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern IntPtr SendMessage(System.Runtime.InteropServices.HandleRef hWnd, int msg, int wParam, [In, Out, MarshalAs(UnmanagedType.LPStruct)] PARAFORMAT2 lParam);

private AdvRichTextBulletType _BulletType = AdvRichTextBulletType.Normal;
private AdvRichTextBulletStyle _BulletStyle = AdvRichTextBulletStyle.Plain;
private short _BulletNumberStart = 1;

public AdvRichTextBulletType BulletType
{
get
{
return _BulletType;
}
set
{
_BulletType = value;
}
}
public AdvRichTextBulletStyle BulletStyle
{
get
{
return _BulletStyle;
}
set
{
_BulletStyle = value;
}
}
public short BulletNumberStart
{
get
{
return _BulletNumberStart;
}
set
{
_BulletNumberStart = value;
}
}
private void NumberedBullet(bool TurnOn)
{
PARAFORMAT2 paraformat1 = new PARAFORMAT2();
paraformat1.dwMask = (int)(PFM_NUMBERING | PFM_OFFSET | PFM_NUMBERINGSTYLE | PFM_NUMBERINGSTART | PFM_NUMBERINGTAB);
if (!TurnOn)
{
paraformat1.wNumbering = 0;
paraformat1.dxOffset = 0;
}
else
{
paraformat1.wNumbering = (short)_BulletType;
paraformat1.dxOffset = rtbData.BulletIndent;
paraformat1.wNumberingStyle = (short)_BulletStyle;
paraformat1.wNumberingStart = _BulletNumberStart;
}
SendMessage(new System.Runtime.InteropServices.HandleRef(rtbData, rtbData.Handle), 0x447, 0, paraformat1);
}



I am sorry if this code doesn't work straight away. It was a cut and paste from a AdvRichTextBox that I am working on for a project. Hopefully it will set you on the right track though.

# re: Extending RichTextBox 2/15/2006 11:58 AM Max
Jim, i'm not sure if your code will work properly after the Richedit box has been resized by user?

# re: Extending RichTextBox 2/23/2006 3:28 PM J. K. Johnson
I'm trying to add annotations to a rtb with limited success. I'm simply embedding panel in the rtb. It scrolls H & V just fine, but when zoom is changed I can't get the panel to scale appropriately. Could you provide some insight on how to do this? I could send a sample app to try an show what I'm doing if necessary...

# re: Extending RichTextBox 3/15/2006 4:38 PM M. Drzazga
Hi, could you tell me how did you include annotations in a RichTextBox? When I paste some RTF code with annotations in a RTB, the annotations are lost. I mean, the .rtf property of the control does not have those annotations anymore.

# re: Extending RichTextBox 6/13/2006 4:59 AM jeya
this is very useful. i'm trying the linespacing for richtectbox using this coding. but no changes. here You are used Unmanged code. i want managed code.

# re: Extending RichTextBox 6/14/2006 8:22 AM Naga
i want to format the richtextbox content: it's very uregent. Pls..
Text Orientation->top-bottom,right-left...like as content alignment
bullets and numbering
oulinelevel-body,level1,level2..
line spacing-single,double,1.5
para -after ,before


# re: Extending RichTextBox 6/15/2006 5:27 AM AS
Justify text does not work. I converted the code to C++/CLI and justify just aligns text to left. Code works because align left, center and right works just fine. I wonder has anyone got Justify alignment working?

# re: Extending RichTextBox 10/28/2006 12:04 AM Brian Reynolds
I have been experimenting with linespacing, using the flags, etc outlined on the MS web page and I can get linespacing to work using SETPARAFORMAT and I can see the linespacing after using GETPARAFORMAT but I get zero linespacing USING GETPARAFORMAT without first using SETPARAFORMAT.
That doesn't make sense to me because it would seem logical to GET the linespacing before changing it with SET.
I would appreciate some advice on this.
Brian.


# re: Extending RichTextBox 3/8/2007 3:44 PM Isaac
We are working on a .NET (C# WinInforms) windows application where our customer has a requirement to have Word Style Editor. Therefore we are using RichTextBox . But we have the following issues with the RichTextBox.

1) Unable to implement “Justify” text like in Microsoft Word Application.
2) Programmatic Page breaking between two pages.
3) Bulleting and Numbering inside RichTextBox

Could you please help me on the above.

Thanks
Isaac
Email - baby.isaac@wipro.com

# re: Extending RichTextBox 3/9/2007 3:19 AM Mahesh.N
Thank you Sooo Much! for your excellent Extending RichTextBox articles -
very-helpful.
Can you help me out please,how to add numbers,bullets in a richtextbox.

Thanks in advance.
Mahesh.Naragund


# How to keep the richtextbox size constant(not extentable) 5/17/2007 6:58 AM K P Ranjith
I am perplexed with a scenario in richtext box. Hope this is the right forum to post it!!


I have a richtextbox in a form and through crystal reports i am taking the text/picture entered in the richtextbox for exporting the report in pdf. The form has the options to change font, size etc of the entered text.

My requirement is that the richtextbox in the form should not be extendable vertically(word wrap is already set to True) beyond a prefixed limit.

i.e. The User should be capable of entering text only in that
particular area of the richtextbox, afterwhich he should not be able to
enter any more data/ image.
(The concept of line number doesnot work because, the fonts may be of different type and sizes in the richtextbox)

Thanks in advance
Ranjith


# re: Extending RichTextBox 11/21/2007 1:15 AM Neal
Why not just implement the Text Object Model interfaces. It 's just like using MS Word ;-). Export them from the RichEdit20 dll and then import the COM types as source code into Visual Studio using .Net Reflector. Trust me it's worth it.

# re: Extending RichTextBox 12/23/2007 1:22 AM sada
i m using vb.net, can u plz write the justification code in vb.net

# re: Extending RichTextBox 1/22/2008 9:25 AM Gervais
Hi, i have a question concerning the richtextbox control.
i will like the richtextbox to detect in a Text some text with a given pattern (for instance FF_Text1, FF_Text34)
as a hyperlink, so that i can click the link to open with the Process class a new document on
my hard drive.
i will be so kind if anyone knows how to solve this problem.
Thanks
Gervais


# re: Extending RichTextBox 2/2/2008 10:16 AM Pritesh Ostwal
Nice code. I want to show copy paste dialog on richtextbox. Any idea how I can do that?

Also if my form has one accept button richtextbox does not handle enter click, really appreciate any help on handling this...

# re: Extending RichTextBox 2/19/2008 3:16 AM DagVador
Thanks you so much for your helpful extended RichTextBox.
It works nicely.
It's exactly what I was looking for ! :-)

# re: Extending RichTextBox 2/23/2008 2:40 AM High Mountain

the advanced rich text works properly for justification, thanks a lot
but when the last line is not completed, it is viewed aligned left
what should i do to make that last line aligned right not left

also can i add a line at the begining that is aligned center ?
how could i do this ??

thanks in advance

# re: Extending RichTextBox 3/11/2008 3:22 AM Ehsan
Hi
Thats nice job, but a i wanted Right justify ricj text box , in your project when set justfy only show in left align justfy and could not show right align , how do i set right justify ? please help me too do this
thanks so much

# re: Extending RichTextBox 4/18/2008 1:12 AM Jaison Thomas
I use your adv rtf control , it works veryfine.

And I have a problem with scrolling. My requirement is when mousescroll the form scorll should work. For that I used the following code.

private const UInt32 WM_MOUSEWHEEL = 0x020a;


protected override void WndProc(ref Message m)
{
//Console.WriteLine(m.ToString());
// Pass WM_MOUSEWHEEL to parent
//source http://www.msdner.com/dev-archive/205/2-8-2056365.shtm
if (m.Msg == WM_MOUSEWHEEL)
{
SendMessage(this.parent.Handle, m.Msg, m.WParam, m.LParam);
m.Result = (IntPtr)0;
}
else
{
base.WndProc(ref m);
}
}

It is working fine when there is no code for Bulleting or Justification.

With Bulleting or Justification this responds strange.

When we scroll first form scrolls and then the scroll goes upward to the richtextbox control.

How can i get out of this?
I would appreciate some advice on this.

Thanks in advance

regards
Jaison Thomas


# re: Extending RichTextBox 4/18/2008 3:17 AM Thorsten
Has someone put all these suggestions and code together ?

I have an other question: How can I set (Add) a Font style to text which alreade has other styles?
e.g.: I have a selcted text wich contains lets say Bold and Underline Text.
Now I would like to add the 'italic' style to the text so that the bold written text now has 'bold and italic' and the undelined text is now 'underline and italic'

My first try was
.selectedText.font = new font(selectedText.font, selectedText.font.style OR Italic)
This works well as long as there are no mixed font-styles is it.

Any Ideas?



# re: Extending RichTextBox 4/18/2008 7:31 AM KnowledgeMatters
Hi,

I'm working on C#.Net.We are constructing IDE where i required transparent text control which i inherited from RichTextBox but I'm facing one problem.I want to incorporate TextAlign property which RichTextBox control don't have.
How can I achieve this? Please help me in this regard.

Thanks.

# re: Extending RichTextBox 5/7/2008 6:14 AM Gary Hall
This might help some people like it helped me:

private const int EM_SETEVENTMASK = 1073;

may not work for all situations...

private const int EM_SETEVENTMASK = 1093;

seems to cover more bases.

The event is defined in many places as WM_USER + 69 which is 1024 + 69 = 1093.

This prevented my databound text box from firing 'OnTextChanged' messages to the underlying data object. This then called validation code which was non-trivial. Changing the event value prevented this.

Other than that, this article was a godsend, thanks!

# re: Extending RichTextBox 10/16/2008 5:43 AM Worried
How to view the print preview

# re: Extending RichTextBox 11/1/2008 5:17 AM Bonyadi
Thank you for justify.But please help me how i can set last line alignment to right.

# re: Extending RichTextBox 12/12/2008 5:11 AM adnan el-shaer
To add mixed styles do somthing like this
In C#:
FontStyle rtfStyle = rtfDoc.selectedText.font.style | FontStyle.Italic;

rtfDoc.selectedText.font = new Font(fontName,fontSize,rtfStyle);


selectedText.font = new font(selectedText.font, selectedText.font.style OR Italic)

# re: Extending RichTextBox 12/16/2008 11:34 PM Jadan Bliss
Thank you!


# re: Extending RichTextBox 1/4/2009 6:13 AM Brian Akehurst
Hi,
I have used most of the code here from Pete and Scott with great sucess and I would like to thank them both. It has saved me a lot of time.

I have a few issues I'm working on that someone might like to help me with if they have already found a solution:

Dropping (as in dragdrop) images onto the textbox though seems to be a problem. I can detect the drop in OnDragDrop() convert the image to a bitmap, add it to the clipboard then paste it rtb.Paste() or insert it as as a rtf string with metafile, but whatever I always end up with the last file in the filedrop inserted as a blank image with the image type as text, ie. the standard rtb image drop. Anyone know how to drop an image sucessfully?

An image when selected has nice resize handles and the image resizes as expected, but the cursor remains as the Ibeam and not the various resize cursors that the user would expect. Anyone solved this problem?

And of course it would be wonderful to find a way to wrap the text around an embedded image and not simply have it aligned with the text, but I suspect this is beyond RTF, unless anyone can tell me otherwise.

Thanks again
Brian

# re: Extending RichTextBox 1/23/2009 7:06 AM Mark
Hi for inserting a page preak use the following

Dim CurrentRTF As String

'inserts a pagebreak at current position
CurrentRTF = Mid(txtPrintLetter.SelectedRtf, 1, Len(txtPrintLetter.SelectedRtf) - 3)
txtPrintLetter.SelectedRtf = CurrentRTF & " \page\par }"

# re: Extending RichTextBox 2/27/2009 7:34 AM makdev
Hi All,
I am developing a control which extends from RichTextBox.
Does anyone knows how to restrict bulleting which occurs after Ctrl + Shift + L in RichTextBox.

Thanks in advance....


# re: Extending RichTextBox 3/4/2009 11:23 PM Robert
Sorry! Can you give an example of how to call this TextAlign.

New to C#, and would like an example.

Thanks.

# re: Extending RichTextBox 3/11/2009 8:42 AM Carlos

AdvRichTextBox text;

text.SelectionAlignment = TextAlign.Left;

# re: Extending RichTextBox 3/22/2009 5:43 PM Robert
Just copied your code and translated it to VB.Net 2008

Unable to make it work.

Any chance you could email me a small sample on how this is to function. I like the part about Bullets, and the Justify of the text. Just cannot see how to make it work.

Thanks in advance.

# re: Extending RichTextBox 3/24/2009 4:18 PM Peter
As did Robert, I ported this code to VB.NET 2008. I did not get any errors compiling, but when I use the BeginUpdate and EndUpdate, the text i type does not display in the text box.

# re: Extending RichTextBox 5/19/2009 2:44 PM Daniel Stutzbach
Using BeginUpdate/EndUpdate, I was having all sorts of odd display problems, such as duplicate cursors and the extra text being underlined.

I was able to solve the problem by adding "Invalidate(true);" at the very end of EndUpdate(). I got the idea from the article you linked to, which invalidates the control in its equivalent C++ Win32 code.

# re: Extending RichTextBox 7/22/2009 12:30 AM Mike
I hav converted ur code for text justification into Visual Basic 2005 and its working fine. But when i use it for my urdu editor(urdu is written from right to left and i hav implemented this using rtb.Selectionalignment = horizontalalignment.right in form load event and i use SendKeys.Send ("{LEFT}") after evey letter that i type) it is not working. When i run my application cursor is at leftmost position and when i type any letter the cursor starts moving down and never stops. I hav to stop my application thru taskmanager. I tried setting
if ( ( fmt.dwMask & PFM_ALIGNMENT ) == 0 )
return TextAlign.Right;

but its not working. How can i implement it for righttoleft languages?

# re: Extending RichTextBox 8/4/2009 7:37 PM Ed
Does anyone know how to display text that contains more than 4096 characters as one line in RichTextBox?

# re: Extending RichTextBox 9/23/2009 5:33 AM Ratnesh
how to add new line rtf format data in richtext box.
my database is sql server2000, data type is ntext
i m using this code but it is not working
richtextbox1.text+=ds.tables("qb").rows(0).item("Question").tostring & vbnewline
it add only text format data. i wanted text format data as well as rtf format data also
plz help

# re: Extending RichTextBox 11/16/2009 3:18 AM Kamal
I also converted the code justification in (Vb.net) VS 2008 and it does not seems to work. Can u kindly post me the code for VS 2005. Thanks in advance.



# re: Extending RichTextBox 11/21/2009 10:10 AM Oscar Quintero
Hola, muchas gracias, esta excelente este aporte...

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