I try to highlight a specifiable line of a RichEditControl of DevExpress.
Here is a sample that uses selection. I don't want to select the line to highlight and I don't have any idea how to calculate the range of a line. The only information I have is the line number to select. There is another sample that uses the CaretPosition to select the line.
Both samples are working perfect but I don't know how to set the selection or CaretPositon by line number.
How can I calculate the DocumentPosition or range of a single line to use the samples to highlight it?
Take a look at:
https://documentation.devexpress.com/#WindowsForms/CustomDocument5890
related with formatting of Text .
Related
I have tried a lot to maintain long text inside RDLC report's columns but it doesn't seem to be adjustable. When some long text appears inside any column then it disturbs the whole report. How to control it, so the text keeps extending downwards in proper and good manner.
Try and put a fixed Column Width and set CanGrow to False and make sure that the Row has it set on True.
If that doesn't work you'll have to edit your datasource before giving it to the reporter. You must break the value into multiple lines based on the length of the string. You can achieve this by inserting System.Environment.NewLine every time it exceeds the size. The exact length at which you need to insert the line breaks depends on your maximum column width and you'll have to calculate this yourself by trial and error until you find the perfect fit.
Edit: Including step by step process for adding break lines based on text size.
Calculate the length of the string and add Environment.NewLine where needed to force the text to break to a new line.
Use Graphics.MeasureString to calculate the size of your text in pixels.
Check if the width exceeds the maximum length of your TextBox.
If the string fits, add it to the final string and continue to step 4.
If the string doesn't fit, continue to step 3.
Remove a character of the string, insert that character to the front of a new (second) sting and repeat step 1. again until the
first string fits.
Check if the second string is empty.
If the second string is empty, we're finished. (The final string can be added to the TextBox / new datasource).
If the second string isn't empty, add an Environment.NewLine at the end of the final string and replace the first string with the
second one and make the second string empty again, repeat the whole
process.
There might be ways of improving this process. For example by breaking the text in fixed predefined intervals and refining it afterwards. Or if there are actual words divided by spaces you could add and remove words instead of characters.
Cut the long-length textbox.
Drag and drop a rectangle there.
Paste the textbox inside the rectangle.
Set rectangle's borders
as the textbox was.
Note: your textbox must be Cangrow:true
Either C++ or C# solutions are welcome.
I have the index of a character in a text displayed in a RichEditCtrl. I need to know its format (is it bold, red, etc) without selecting it.
Thank you all.
Using the base CRichEditCtrl, there is no way to get the format of a char without selecting it. If you don't want to change the selection, then save the start/end position of the current selection, select the character you want the format of, call CRichEditCtrl::GetSelectionCharFormat(), and then restore the original selection of the rich edit control.
I've got a RichTextBox containing lines of text (each line a paragraph), and I have a line number that represents an error. I want to set the caret to be at the start of that line. How?
I haven't got a working installation of C# on my machine at the moment, but from looking at the docs it seems you should be able to first locate the paragraph you want (probably by enumerating through them, there does not seem to be an index function) in yourFlowDocument.Blocks and then:
TextPointer paragraphStart = paragraph.ElementStart;
richTextBox.CaretPosition = paragraphStart;
I have an application where we replace place holding text with other text at run time.
While doing so I have to add character ellipses if the string goes beyond some predefined width.
So I do not have a DrawingContext available nor i have a Graphics.Measure available.
I used FormattedText but I was unable to extract the ellipted text.
I could never find the right way to use a formatted text like this.
Please help.
For WinForms, you can use the TextRenderer.MeasureText function,
and thanks to the comment from vcjones, using the method described at http://smellegantcode.wordpress.com/2008/07/03/glyphrun-and-so-forth/ for WPF.
I am creating a Word document on the fly as a C# VS 2010 Office Word project for a client who wants to be able to generate a document that will allow the appropriate number of signatory locations for a particular deal going down. There is a table that will need to be generated with sufficient rows and then later in the doc I have to produce prefab blocks for personal info per signatory.
I am working on the table part now and have almost everything as I want it, but the text in all of the cells is vertically top aligned. I have visited EVERY site in the ENTIRE internet in the past few days for up-to-date information on Word automation that is current for .Net 4, VS 2010 and Office 2010. I have syntax that compiles w/o error but fails to bottom align as I desire. I have even stabbed about with IntelliSense to see if I could find another solution.
This code focuses on a single row:
tbl.Range.Rows[1].Cells.VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalBottom;
This runs but the text stays helium-filled.
Any Word automation wizards out there?
I was unable to reproduce the problem. This code works just fine:
using Microsoft.Office.Interop.Word;
class Program
{
static void Main(string[] args)
{
DocumentClass document = new DocumentClass();
object defaultTableBehavior = null, autoFitBehavior = null;
Table tbl = document.Content.Tables.Add(document.Content, 2, 2, ref defaultTableBehavior,
ref autoFitBehavior);
tbl.Rows[2].Cells[2].Range.InsertAfter("This is a test.");
tbl.Rows[2].Cells[2].Range.ParagraphFormat.SpaceAfter = 0f;
tbl.Rows[2].Cells.Height = 50f;
tbl.Range.Rows[2].Cells.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalBottom;
}
}
I suspect that some other problem must be in play, like the paragraph spacing after, or perhaps the wrong range is selected?
The text is probably centered vertically, but it incudes a paragraph spacing other than "0." So, Word is viewing the extra line as additional text that needs to be included in the vertical centering.
To get around this, simply highlight the text you want to be vertically centered (or the entire table if that is what you want). Then go to "Page Layout" and reduce the "Spacing" "After" to "0." If you also have a space on the top of your text, you will need to reduce the "Spacing" "Before" to "0" as well. With no spacing before or after the text, the actual text will now be centered.
This is for an old question, but I just ran into the same problem and a fix for this. Add this to your table:
tbl.Range.ParagraphFormat.SpaceAfter = 1; // change the 1 to how much space you want extra in your cell
Just if anybody is following up this post, my text also was arranged at the top of the cells.
So for me the following did what I needed in a qick way
oTable.Range.ParagraphFormat.SpaceAfter = 6;
oTable.Range.ParagraphFormat.SpaceBefore = 6;
Space can be adjusted if needed.
The following worked for me in Word 2011 for Mac- nothing else suggested in numerous sites seemed change the vertical cell alignment for me. Found this out by trial and error.
I highlighted the cells I wanted vertically align to bottom right and changed the line spacing (in my case it was 1.5 for the table) to 1 for those cells. It finally worked. Hope it helps.
Highlight text within the table
--> go to Line Spacing Options
--> in the Spacing Before/After section set Before and After to zero px (or equal).
All the alignment options should now work.