Updating single characters in large TextBox programmatically - c#

Reading lots of characters and updating a textbox was suggested to me when I created this question, and it was exactly what I was looking for (couldn't find it by just searching). However a couple of points need clarifying.
I am looking to upgrade to a ListBox or even RichTextBox. For now I want to be able to replace as little of the onscreen (and off, as an added bonus) text as possible.
In the first link Guffa wrote:
If the data is line based, use a list instead of a text box, so that you only have to update the last line when you add a character.
I have a split pane where updates to one TextBox are translated and shown on the other side, and vice-versa. I've briefly toyed with a ListBox but it doesn't provide the intrinsic text-editing funcionality of a TextBox so I went back.
What component should I be using? I wouldn't have thought that with all of .NET available I should have to consider Win32.

Ok, no one else has offered an answer so I will propose a solution which is the last one open to me short of refactoring back to Win32 API calls.
The solution is to use two textboxes. Instead of replacing the text element of the on-screen one you replace that of its dupe, which at the time is hidden, you then toggle the visible flags of both.
I'll let you know how it goes but it is major work for not much advantage, I'll prolly just live with a bit of flicker for now.

Related

Is WPF adequate for creating such a form or am I missing something?

Intro:
I am quite new to C#.
It is my job to create a certain simulation program.
I can't ask other programers, I'm an intern with a nonprogramer adviser and should not nother them. (I'm doing more of a fun project.)
So before spending a week or two to get really into WPF, I wanted to make sure it fits my needs.
If not, I want to use something else.
What I need:
Show the user a range of radio buttons to decide wether a simulation/plot/opening_of_svg should be done or not. (Can be done.)
A button "Add Task" where the user can choose one. (Can be done.)
Depending on the choice, add a certain form into the existing one, where parameters can be set. (Not found.)
Some of them radio buttons. (Can be done.)
Some of them text box, for integers and doubles only. (Can be done.)
All of them with default values. (Can be done.)
After adding a task, another "Add Task" button should be created, for adding more of them. (Not found.)
If for example a second simulation is added, it should take the values of the first one as default. (Can be done.)
Save the choices and data to a text file in a certain syntax like "Gnuplot Add Restriction = Time" which is used by the rest of the program. (Can probably be done.)
Question:
The biggest uncertainty is the one with adding forms into the forms.
Can this be done in WPF?
If there is any other framework (if this is the right name) specially made for this, feel free to comment.
I can't add many links due to my reputation. I might do it later. Just in case someone will find this later and wants to know about how.
Rather than creating Forms, consider creating UserControls and arranging them within a single Window. This is the same pattern you might use when creating composite windows in WinForms. I'd recommend the Grid or DockPanel layout panels.
In this respect, WPF is quite similar.
In addition, it sounds to me like you are doing a feasibility study for a new requirement. Are you sure it is not appropriate to speak to more senior staff? If I was them, I'd want to know your findings!
On reflection...
It seems like you are trying to create a branching Wizard workflow, like an installer might give you, i.e. Next, Next, I Agree, Next, Finish. WPF Can absolutely do this and some open source solutions already exist. For example, Avalon Wizard.

UIAutomation - Scroll and Text Issues

I made a small uiautomation app that scrolls through a forms windows searching for a specific richtextbox. Once it finds the richtextbox, it would extract the text and verify against a constant. I already coded the entire program but I have two issues:
The FindAll function sometimes misses the textbox. I believe its due to scrolling too fast since if I step through my app, it works everytime.
The TextPattern applied to the richtextbox provides me with DocumentRange.GetText function. However, it doesn't retrieve any returns/new lines.
Is there anything I can implement to consistently catch my textbox without slowing down the scroll?
Is there any option to extract the text with returns/new lines included? I can consider Copy/Paste since some of my textboxes aren't selectable.
Update 1/19/2015
For problem 1, I placed a couple Thread.Sleep(500) . I'm not sure where it would indicate the pane is still loading due to scrolling.
For problem 2, I found out that the textboxes I thought were unselectable are selectable. However, I still don't want to use the copy option since one event that changes my projects focus will copy the wrong location. I barely keep the SendKeys option as it is.

Contextual Text Editor in WPF

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.

Combination of WPF TextBox and RichTextBox

I am writing a small editor, based on a WPF (c#) TextBox. For some functionality the method getRectFromCharacterIndex(), which is only implemented in the TextBox-class is necessary. Furthermore I've got to do some syntax-highlighting in my program. Normally this is easy to handle in a TextBlock or a RichTextBox. Unfortunately these two Controls don't include Methods like the one mentioned above. Has anyone an idea, how to format and/or color single Characters in a normal TextBox with a small workaround?
Thank you very much for your answers!
I did the same effort in the past and I decided to move to this: http://wiki.sharpdevelop.net/AvalonEdit.ashx almost all the work you need is done here.

Control to view a file with a large amount of text

Is there a TextBox-like WinForms control that can show a large amount of text (hundreds of megabytes) in read-only mode? Of course it should work without loading the whole file into memory at once.
I'm trying to implement this myself, using a standard TextBox, processing scroll and keyboard events and reading the amount of text necessary to fill the visible "window". But it's still quite buggy, and I'm feeling that I'm reinventing the wheel.
Loading "hundreds of megabytes" of text into a control sounds like a very, very bad idea memory/performance wise; it will likely crash your program. Anyway, how are you going to read all those millions of lines? Do you really need the whole text in there all the time? Mabye it would be better if you had a buffer and loaded small amounts of text into a RichTextBox and when you reach the end (or even near the end), simply load up the next 100 (or any other amount) of lines. Or, if you are searching for something, search for your keywords and put the relevant text in the RichTextBox. It really depends on what you are planning to do.
I think you got best chances by using Scintilla or its wrapper Scintilla.Net. I think it doesn't it job that perfect, but it makes it much better than TextBox or RichtTextBox.
I've no knowledge of such a control (RichTextBox is slow when you put a single wikipedia page into it, so I'm quite sure he loads everything into memory).
My experience with the winforms is that you often need to customize defaults controls to obtain the behavior you want, even when it seems trivial (nullable DateTime anyone ?). On the other hand, they do offer a good base to add one or two simple behaviors quickly without having to do all by yourself.
I've been using winforms controls for several months and often ended up implementing specific (some trivial, others complex) behaviors in my own controls.
There is no such control from what I know. Long time ago I have written similar control but it is for Delphi, but the principles are the same (read limited block of data and render it). So if you decided to implement it by yourself, then move away from TextBox control, it is not well suitable for such needs. I believe you should create new Control descendant with all custom painting. It is not very easy, but it is the only correct way.
Display the text in parts.....10.000 characters in each text box....i recently discovered thet if you make the textbox bigger the program will run faster when editing the text or scrolling...

Categories

Resources