Adding text in a richtextbox after adding a graphic - winforms

When adding a graphic to the end of some text in a richtextbox. It works great. However, when I begin to add more text, the graphic is overwritten. This is not the desired outcome.
I am using the clipboard method for taking a graphic from resources and pasting it into the richtextbox.
// initiate the horizontal bar file
Image image = Properties.Resources.hoz_line_212x4;
// Put the image on the clipboard
Clipboard.SetImage(image);
//// Paste it into the rich text box.
this.msgsrtbx.Paste();
this.msgsrtbx.SelectionLength = 0;
this.msgsrtbx.ScrollToCaret();
When I come to the next bit of text I want to place in teh richtextbox, the graphic is overwritten. I would like it to still remain in the box.

Related

WinAPI: Draw rectangles behind Edit Control text

I have a read-only Edit Control that displays a multiline string. I set the background color for it using WM_CTLCOLORSTATIC in the window procedure of the dialog that my control is subclassed from. If the window is shrunk, scrolllbar appears for the Edit Control. It all works fine, you can select, copy, scroll the text left and right.
case WM_CTLCOLORSTATIC:
if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_DEBUGGER_DISASSEMBLY))
{
SetBkColor((HDC)wParam, RGB(255, 255, 255));
return (LRESULT) GetStockObject(DC_BRUSH);
}
break;
I want to make custom background color behind a particular line. My normal BG is white there, and for that line I want, say, blue.
I tried using WM_PAINT for the Edit Control, but then I seem to have to draw the text once again, or the original text of the control won't be visible until I select it. And if I manually draw text too, it won't scroll the same as the original text.
If you absolutely have to have an edit control, then I don't see a solution. However, with some tweaking, you might be able to use a rich edit control. It accepts most of the same messages as an edit control. The trick would be using SetCharFormat to set the format of the line you want to change.

Extract text and all Font information from pdf viewer

User will see a pdf in webbrowser Control(or any other viewer) and select the text from it then I want to find
1)Coordinates of selected text.
2)Font Size of selected text.
3)Font Color of Selected text.
4)Page Number of selected text.
So that i can use this information to find the text from pdf with same theme .
Problem 1:
Is it possible to find which text or coordinate is selected in webbrowser control? There must be a better way to do it using pdf tron viewer?
My approach will be to fix the Form ,so that user will not change the length, width
a) i will find a way to transform screen coordinates to pdf rectangle coordinates(#problem 2)
b) then i fill fetch text from those coordinates
c) then i will find color and other properties of that text
but i am sure ,there must be a easy way .I tried to find help but was unable to find such help. Kindly provide related documentation and a help to figure out starting point to start a task.
This is not possible using webbrowser but there is an alternative using PDFViewCtrl.
1) add control in toolbox by browsing PDFNET.dll
2) its better not to drag and drop the control ,alternatively initialize pdfviewctrl in after initializeComponent();
3) Add these lines to give user option of selection
pdfViewCtrl1.SetDoc(doc);
pdfViewCtrl1.SetToolMode(pdftron.PDF.PDFViewCtrl.ToolMode.e_text_rect_select);
4)Add this code behind the click event of start button so that user tell the program that he/she has selected text.
int pagenumber = pdfViewCtrl1.GetCurrentPage();
if (pdfViewCtrl1.HasSelectionOnPage(pagenumber))
{
pdftron.PDF.PDFViewCtrl.Selection selection = pdfViewCtrl1.GetSelection();
string HTML = selection.GetAsHtml();
HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
document.LoadHtml(HTML);
double[] coordinates = selection.GetQuads();
Rect rect = new Rect(coordinates[6], coordinates[7], coordinates[2], coordinates[3]);
}
you will get everything in html else you have text and coordinates so you can find more information ,
Find samples of code on http://www.pdftron.com/pdfnet/samplecode.html

WPF Rich Text Box doesn't accept \sl rtf tag

I have a WPF (vb.net) application with a RichTextBox and load a rtf file into it. This works basically as expected except with the line spacing tag \sl
For me it looks like the RichTextBox does not handle this tag correctly - am I right with this assumption? The same file shows the correct line spacing in MS Wordpad.
Has anyone of you had the same problem - and found a solution?
Thanks for each hint?
This is the code I use to load the rtf into the box
Dim tr As TextRange = New TextRange(TextBoxMain.Document.ContentStart, TextBoxMain.Document.ContentEnd)
tr.Load(myFileStream, System.Windows.DataFormats.Rtf)
Alois

text in paint like application

Hope I can make the question clear.
I am working on a paint like application where users can add different objects and also text. The way to add text is that we show a dialog where user can enter text and then that text is added to the draw area.
Now we want that text should be added in the same way as in Power Point. A user clicks any where in the draw area, a rectangular text entering area is shown, where user can enter text, format it, move the rectangle to move the text and then click outside to enter the text on the drawing area.
Since the paint event of the draw area is called and every object is added to the draw area using graphics and paint, what is the best way to add text using the interface as I explained above.
Any suggestions would be appreciated.
Your best option is to place a TextBox as a child control and that will allow the user to modify the text as required. Once they finish changing the text you then remove the text box and draw the string instead. If they click the text becaues they want to change it then you put the text box back again so they can edit it.

Is it possible to Trim Wrapped Text at the bottom of the container in WPF?

I would like to trim the contents of a TextBlock at the bottom of the container when it runs out of space. The image below shows what I am trying to achieve.
The left cell contains text that is being wrapped at the end of the line, but is being cropped on the final line. The right cell (which I edited by hand) shows the effect I want to achieve by trimming the text on the last line.
Is there an (easy) way to achieve this in WPF?
Did you try the TextTrimming property?

Resources