Contextual Text Editor in WPF - c#

We are currently looking to create a text-editor in WPF (.NET 4.0) which will allow writers within our team to create movie scripts. In short, the functionality should ressemble that of FinalDraft or Adobe Story (i.e.: contextual positioning of text depending on the cursor's position and user intentions)
We are currently looking at two different solutions design-wise:
One WPF control which will act as the container, and multiple small text-editing controls which will represent rows within the script. This will allow us to position the controls using their margin, while also making binding easy. The challenge here would be the handling of multi-line selections. I was thinking of using a Listbox as the container, and each listbox item would be a custom control containing a textbox. This would require the instantiation of controls depending on the user's action. Everything would be skinned to give the impression that the user is working on a blank page.
One big textbox capable of displaying custom XML data. The challenge here would be to determine where exactly the cursor is located (i.e.: is the cursor on top of an actor's name, etc.) and positioning the text appropriately (i.e.: actor names are centered and in caps, etc.)
I recently tried implementing the first solution, but having to re-implement the whole selection behavior that is built-in in basic text boxes is non-trivial and requires a lot of work. As for the second solution, binding to my business objects will be much harder than simply instantiating multiple controls with different bindings.
Do you have any other solution in mind ?

I needed a text editor for a application once. We had a big xml file for settings and the user should be able edit those.
Turns out , if your file is large enough (+ 10000 lines) the rich text box is getting pritty slow.
As for building a gui mask : only if your user wirtes some short options like text. But is i understand you want your useres to write creativ text. This "mask" gui - "lot of small places" will make them feel like they are in the 80ties.
I suggest: Dont write the Programm , only write a Plugin to an exitings editor. Some are free like:
http://www.codeproject.com/Articles/42490/Using-AvalonEdit-WPF-Text-Editor
or an add in for word - people love Word and know Word
http://www.codeproject.com/Articles/8837/Writing-a-Word-Add-in-Part-I
And for binding data and the like: Once the text is written, the user just need to press the save button and you can parse the input for information. I would not do it on the fly as it can get pretty slow. Also you say that the information is linked so only if all the data is written you can make use of it.

Related

WPF - Export XAML content to file (PDF or Word)

I have a pretty straightforward WPF application, but with a lot of forms, nearly 80, spread out to UserCcontrol xaml files and navigated with TabControl on a main Window file. Some of those forms contain a lot of data, but basically everything is broken down to TextBlock, TextBox, Label, Grid, RadioButton and ComboBox controls.
I am done with everything, but there is a requirement that everything at the end should be exported to a file - either PDF, or Word. Is there an easy way to do that? I don't have a requirement to have the same style and formatting. I only need the text - question and given answer, either text, or chosen option.
I have searched the web and saw many solutions, but PdfSharp was the best, I believe. However, I do have a lot of forms and it would be an overkill to map every single user control in a loop or something, to write to file. Creating a bitmap or an image and print to file would not help, since I have text boxes with scrolling and the whole text would not be visible in such cases.
What best would work for me would be a library that accepts, let's say, a user control and then prints its content on a page(s) of a file. Once again - I don't need any styling or formatting or images, just text.
Here is a small example of what one of the forms looks like, just to give you an idea:
Thank you in advance!
I've looked for similar tools and there isn't much out there, especially if you are looking for something open-source.
The most straightforward approach will be using tools found in the System.Windows.Automation namespace. That should help you write some helper functions that can capture text from all of the elements in your controls.
This link should be helpful:
https://learn.microsoft.com/en-us/dotnet/framework/ui-automation/obtain-text-attributes-using-ui-automation

accessing another app's elements using C# WinForms app

I'd like to be able to do following actions within another application:
to change Tabs
to Copy text from within a TextBox
to click on a Button
to enter text into a TextBox
to select DropDownList element
Right now I'm using separate methods such as:
mouse_event() to change mouse coordinates and click on a button
another mouse_event(LeftMouseClick followed by the RightMouseClick) to copy a text within a TextBox
Clipboard.GetText(System.Windows.Forms.TextDataFormat.Text) to Copy what's inside the clipboard
SendInput (for each key) - enter the text into a TextBox
Disadvantages of this approach are:
(not crucial) PC becomes unusable (you can't work while script is running)
I have to know exact pixels (read - position/coordinates) of EVERY element within an app
slow execution time (each key has to be typed separately)
I'm looking forward to create an application which can click on a TextBox/Button/List without the need of having exact coordinates of these elements.
Is such task possible with C# WinForms? My current approach works but it has it's flaws.
Any advice?
Read about Mutex. If you plan on scale-ability, read about network communication (for example, the TCP protocol. TcpListner, and TcpClient).
This sounds like a job for UI Automation. I have only used it to get text from another application, but it has functions to activate controls by name or to navigate the control tree if there is no name.
You can get text and interact with controls using AutomationElements that you find using patterns or navigating the control tree.
There is a complete framework for doing exactly this kind of thing, and it's called the UI Automation Framework
Here's some examples on how to use it.
And you can also apply this technique to generic windows's using the UI Spy to determine the automation elements.

How can I implement an interactive tutorial inside an app?

I have C# add-in for Word and would like to implement an interactive tutorial like games usually have. I'd like to somehow highlight (maybe by circling) certain visual elements and display text boxes that describe what the element does. For example, say the add-in is a generic workflow editor. I'd like to show to the user, step by step, what needs to be done by visually selecting elements and explaining what they do and what options (s)he has. My first question is: can this be done in C#? My second question is how? :) I suppose I'd have to get the positions of said visual elements and then draw an image on top but I don't know how that could be done.
I'm a bit disappointed that not even a single member of the Stack Overflow community took the the time to at least give a hint about this. But such is life and I'm just going to share my findings here because I'm certain someone else will benefit from them.
To be able to do an interactive tutorial you need three things:
a method to find where a control is located in terms of screen coordinates
a method to point the user to the control by highlighting it or
surrounding it with a red line for example.
a method to do its default action (ie: click a button).
In other words, the idea is to have some sort of window with text describing a control and some graphical way of indicating the control in the app. Optionally, the window could provide something like a ShowMe button which shows the user how to use the control by taking control of the mouse and keyboard.
This is trivial when the controls are made by yourself and thus have source code access. However, when doing such a thing for a black box app such as Word you can use the Windows IAccessible interface. Searching for that with your favorite search engine will yield everything you need to understand it and use it. IAccessible allows one to do many things but most importantly it can get a control's position and can also do the default action.
Having sorted out these things the next step is to figure out how to graphically point out the control. There are many ways to do this but in my case I chose to surround it with a red rectangle. I did this by creating an invisible, borderless form with an empty red rectangle on it. Having the control's position and size, I had no problems placing the aforesaid form over the control.
So there you have it. I laid out the building blocks that one needs to make an interactive tutorial for any app.

What is raw code of textbox

May be i can get some negative points on this question but, really this question is boggling in my mind from last many days that what is the basic/raw code behind textbox(or other such controls).
i mean i understands that, we can inherit the textbox class and make our changes, we creates its object and use it.
but wants to know how that class creates a textbox(the design which allow us to enter text) (same query for other components), is it a code of 'C' language which are generating it using CG (computer graphics) programming or any other thing.
Experts please resolve my curiosity.
Thanks
Windows provides several basic API's for drawing on the screen. You can draw pixels, lines, boxes and more complex geometric shapes. There are also API's to draw text. Other API's allow you to react to user input, e.g. mouse movement and clicks and keyboard input.
From these basic API's you can create your own text box by drawing the exact pixels of how the text box should look and react to user input. However, Windows has a built-in concept of a text box. This text box has a standard look and feel and is also integrated with UI concepts like focus, tab order, the clipboard and the caret. But behind the scenes Windows is using the low level API functions to draw on the screen and react to user input.
When you create a TextBox in Windows Forms it actually creates and wraps a standard Windows Edit control. This control is drawn using GDI. However, other programming models like WPF may create TextBox controls that looks like a normal text box but uses a custom implementation supplied by WPF and is drawn using DirectX.
Use http://www.red-gate.com/products/reflector/ and see for yourself...
Here is what I think it is doing:
The Raw code behind TextBox or any other Control uses Windows API that is responsible for drawing these controls and provide Handles of these controls for later reference.
Windows has been using different methods to draw it's UI like GDI, GDI+ and sometimes DirectX. I may be wrong and there may be some other techs I forgot to mention.
These controls use each window's WinProc to receive Input Notification and other callbacks that notify these controls when clicked, typed or for example resized.

How to make a tab's name editable in C#?

So I have a few tabs in the form, and i want it to work like that:
When you click on the tab's name, it becomes editable, and when i stop editing it remains with the new name.
How would i do that with C# and winforms?
You can dynamically create a text box and place it over the tab area to make the user think they are editing the tab directly. When the text box loses focus you can then put the typed in value into the tabs property.
I agree with Eric, regarding how you could do this with the standard TabControl. You could also provide a dialog to do the name change (a slight variation on Eric's suggestion).
However, I would also recommend that you consider rolling your own tabbed control. They're not difficult to create and by rolling your own, you will be able to put in the exact functionality you need in a robust way rather than trying to piece it together from existing components that may not play nicely together.
There's no standard Windows control that does this, so you'll either need to look for a third-party control with this functionality (iffy) or write your own control which draws the appropriate edit box on the tab, etc.

Categories

Resources