wpf DocumentViewer - get ITextPointer by GlyphRun and vice versa - c#

Just wondering whether anybody has tried to hack into WPF DocumentViewer in order to make it more useful. I've spent almost a week already trying to create more powerful API for this control based on it's methods which I extract using reflection.
Everybody knows how to get selected text from document viewer via reflection but my task is more complicated. Selected text has End and Start properties which return ITextPointers. Also I have a collection of GlyphRuns extracted using this code. And now finally I want to find out which GlyphRun contains selection start.
So I want to know how to convert ITextPointers into GlyphRuns and vice versa. I understand that they do not have 1:1 relationship. This control with closed API and last week spent in Reflector doesn't let me sleep well. I hope maybe somebody tried to do it before or seen code samples and will be able to guide me through these jungles.

I would recommend that you abandon this approach. Doing lots of private reflection like this is not something you should be basing production code on, its very brittle and downright forbidden in some contexts. Frankly, you're better off finding a 3rd party control that suits your needs such as www.infragistics.com
Or if that's not an option you can probably create your own control in the amount of time you'll have to sink into getting this to work.

Related

Word ContentControl handle?

I’m using Word ContentControls to present & synchronize data coming from backend services. I need a way to indicate that content of a given control has changed. One way I can imagine this is to change style around given Range residing in ContentControl. Although this may not be as flexible as requirements I’ve got. The other way I can envision is to use GDI to draw necessary indicators myself. I know I can get handle of main word window but I’m struggling with finding a way to obtain handle to any CustomControl in it. Is that possible?
Use Microsoft's SPY++
i believe it can be downloaded from here
http://mdb-blog.blogspot.co.il/2010/11/microsoft-spy-or-spyxx-for-download.html
Information:
http://msdn.microsoft.com/en-us/library/aa264396(v=vs.60).aspx

How to capture a specific HTML Element as an image?

I asked a question similar to this here:
Is there a way to show part of one form on another form?
This would work great if I could guarantee that every single person who uses this application uses the same monitor as I do.
But I'm a realist so I'll get to the nitty gritty.
If I can (which I can) identify the specific HtmlElement of the WebBrowser control document that houses what I want to create an image from, is there any way that I can create an image from that specific HtmlElement?
I've seen some stuff about IExtractImage but everything I've seen makes my head hurt a little bit. If someone could dumb that down (if that's what I'm looking for) so that I could use that, that would be super good.
To be a bit more clear what I'm hoping for is something like HtmlElement.DrawToBitmap()

Replacement for Index in .NET

I've been out of doing proper programming for sometime, so as an exercise in trying to get some practice, I'm trying to make a program to solve Sudoku in C# (VS 2010)
My problem occurs when I'm trying to create some form of initial grid for the data out of text boxes. Back when I used to use VB6, I could call all text boxes as a single name and then give them all an index number which would allow me to refer to a specific text box when I was in a loop.
As far as I can see, there's no easily visible equivalent in C# and my searching has been to no avail although I can't imagine it'd be a feature that would be removed.
Thanks in advance
You can create a control array.
http://www.devasp.net/net/articles/display/674.html
It would probably be easier, and look better, if you use a genuine grid control like the DataGridView.
One bit of bad news. In the days of VB4,5,6 Microsoft used to release a new grid control with every version of Visual Basic, which was annoying (unless you rewrote your code every year). Well, they are still at it.

How to create a custom text editing control?

I need to create a text editing control in C# and I'm not sure where to start.
For a bit of context: a C# program is going to edit an XML document (using this control). The XML document can be converted to HTML.
The XML document will contain the following:
Normal text (obviously)
Headings (which will be formatted differently)
Lists
Images
Videos (they don't need to be viewed in the control, but there needs to be a box or something to indicate that they're there)
I want this control to take the XML and render it and act as an WYSIWYG editor for the XML.
For the moment, I'm not to concerned about implementing all the above details (although they will need to be implemented eventually), I just want to know where to start with creating this control. Should I be inheriting from TextBoxBase (or TextBox) and going from there? And what methods would I need to override? Or should I inherit from Control (in which case I think I'd need to all the text box stuff - selecting text, copy and paste, the caret etc. - myself, which is something I don't really want to do, but I am prepared to do if I have to).
I am aware of preexisting controls like TX Text Control that do something like what I want (although this one is far more powerful than I need), but I can't use these (this is for a university project), and besides, I really do want to know how to make this from scratch.
The topic of creating a feature rich edition control with syntax highlighting, code completion, etc. has been discussed by the developers of #develop in their book "dissecting a C# Application"
http://www.icsharpcode.net/OpenSource/SD/InsideSharpDevelop.aspx
(I think you can't buy it anymore, the link says it's available for free to download but the links seems to be broken)
The book basically explain the core features of #develop (pre V1, so it's kinda outdated), including the code editor and (what is important, too) which mistakes they made during the process.
Should I be inheriting from TextBoxBase (or TextBox) and going from there?
You can't inherit from TextBoxBase (its constructor is internal).
So you can inherit from TextBox or from Control or UserControl.
The problem with TextBox is that its painting is done by unmanaged code, which isn't overridden when you override OnPaint. For further details, see this question, answer and comments.
I am aware of preexisting controls like TX Text Control that do something like what I want
The TX Text Control is something else: it's implemented using Win32 code, with a .NET wrapper/API.
A few years ago I used the excellent open source Scintilla editor as a base to derive a custom C# control from. Worked great. Nowadays it's even easier if you leverage the ScintellaNET project (CodePlex) which has already done the wrapper work for you. Of course, if you don't mind paying, you can't go wrong with Actipro's SyntaxEditor.
Inheriting from Control will require lots of work, such as painting, implementing default behaviour, etc..
I think you can start with studying RichTextBox control because all of your requirements can be done by changing RichtextBox control.

Print a Winform/visual element

All the articles I've found via google are either obsolete or contradict one another.
What's the easiest way to print a form or, say, a richtextbox in c#? I think it's using the PrintDiaglog class by setting the Document, but how does this get converted?
At least in VS 2008, its very easy. It took me about a couple of minutes to code the answer after reading your question. Here's where I borrowed it from:
http://msdn.microsoft.com/en-us/library/6he9hz8c.aspx
I tested this, and it works.
Someone I know created a component that extends controls with a lot of properties that give you a lot of control over how the form prints. It's worth a look.
MCL PrintForm Helper Component

Categories