I'm using WPF, .NET4, VS2010.
I have a RichTextBox that I'm letting the user edit in. I have implemented a Find/Replace dialog. The user puts in a Find string and a Replace string. When they click on Replace, it searches in the RTB for the next occurence of the Find string and selects (highlights) it. If the user clicks Replace again, it replaces the text and searches again, selecting(highlighting) the next occurence.
The problem is, the user cannot see the highlighting in the RichTextBox. I have found solutions for how to preserve the highlighting when the RTB loses focus - notably, handling OnLostFocus and setting e.Handled to true. But, this only seems to work when focus is going to another control on the same WPF form. In my case, I have a separate WPF form (my Find/Replace dialog). When focus returns to that, the highlight of the selected text in the RTB disappears - though when I close my Find/Replace dialog and focus returns to the main form, the selected text is highlighted appropriately.
I have tried this using ShowDialog() to display my Find/Replace dialog and also using Show().
So, the question is, is there a way to have my RTB show the selected text even when focus is on my Find/Replace dialog?
Related
I needed a TextBox in C# UI with the capability of showing the multiline content if needed. Once the down arrow or ellipsis (located at the inner edge of the text box)is pressed, then a dialog pops up and either allows the user to type more text or shows the already saved multiline text.
To that end , after research I found MemoExEdit from DevExpress. Now I have everything I need except the textbox(MemoExEdit) does not show anything until the down arrow is clicked. in other words the text inside the box is blank actually just a blue A shows up regardless of my content. Thanks for any help how to fix this.
I got my answer : Set the MemoExEdit's Properties.ShowIcon property to false.
I wanted to adjust the width of the Autocomplete dropdown box of a textbox. I dont want to adjust the width of that textbox, but only Autocomplete dropdown. I know that there is no way I can increase the width of the Autocomplete dropdown by using properties provided with textbox.
Hence I wanted to know whether there is any way to get the handle of that Autocomplete box and then increase the width of that drop downlist without changing the textbox width?
If this is not possible then I would like to create my custom textbox with autocomplete, in this case how to use the existing autocomplete functionality provided by microsoft? Is there any way to do it. Are there any libraries available for this?
I don't think you can use Microsoft's implementation of autocomplete, which does not have an option to adjust dropdown width.
Create a background thread to not get into the way of typing, and hook up the text change event of a combobox box or a textbox to update the candidate list (assuming autosuggest mode since you mention a dropdown). You can probably add/remove the combobox items on the fly if you have a combobox. But for dropdown list and textbox items you need a popup window
It is easy to get a popup to show, but you need to not use a fixed position so it won't go off the screen when the textbox is close to the edge of the screen. And the focus logic is a little bit complex. you need to keep focus on the textbox unless the user press the arrow keys to make a selection.
so
when focus is on textbox:
arrow keys move the focus to the popup
other keys goes to the textbox, if not handled by the dialog itself, except for the delete key when mouse is over the popup.
when focus is on popup:
arrow keys move the focus to the sibling candidate item or the textbox
other keys goes to the textbox, if not handled by the dialog itself, except for the delete key
mouse clicks:
dismiss the popup outside of the popup or the popup.
update the value of textbox if a candidate item in the popup is clicked on
It takes a lot of effort to get the focus/threading right. If you can afford some form space, you can just add a fixed width listbox to the form instead, like Visual Studio help viewer's index pane.
After going through lot of blog posts and different articles, I came to a consensus that it is next to impossible to get a solution to my problem in the way I wanted. So I've decided either to come up with a custom solution or as Sheng Jiang said I need to implement my own autocomplete object.
I've come up with a solution which fits my requirement by increasing the width of the textbox as per the largest string in the autocomplete string list while I'm adding the autocomplete custom source. As I said I cant increase the width of the text box because of the size constraint on the form, so I decided to keep this textbox in a panel and increase the size of the textbox inside that. Panel will not grow with the textbox so that solved my problem.
I know this is not perfect solution but it fits my requirement.
I have a control with several textbox controls on it.
Now, when I press tab after I edit one of the textboxes, the focus is switched to the next textbox BUT I need to press an additional tab in order for it to enter the "editing" stage.
The first tab simply draws a dotted background on the textbox ... and the second one actually puts the cursor position inside the textbox. Is there a way when I press tab, to automatically set the cursor inside the textbox?
Thanks./
Are you sure you don't have any hidden controls or other controls that might be accepting focus before your textbox? Either way, you should be able to update the tabindex value of your controls so they follow a logical sequence when tab is pressed.
I have 2 forms. A main one which has a richtextbox on (aswell as other stuff) and another which is used to find text in the richtxtbox on frm1. The second form consists of a textbox for the user to enter the word they are looking for, and 2 buttons. One for Find and one for Find next.
When the find button is selected the found text is highlighted in the main form (neither forms close) and if find next button is clicked the next item is found. (the next button is disabled if there isnt anymore text found)
Now problem is...i dont no how to code this!
You will need to share the textbox with the Find form.
The simplest way to do this is to make the Find form's constructor take a RichTextBox parameter, and pass the textbox to it on the main form.
Then, make a field in the Find form to store the textbox, and set the field to the constructor parameter.
I want to implement a search box in a window form. In that window form, I have a few botton and a text box.
I want to support the use case when user enter a string in the search box and then we can find the that string and highlighted like firefox does. Is it hard to do this?
I googled and found this link that has the search box control. but I don't quite understand the code. If anyone is familiar with control.sendMessage, Could you please give me some help on understand that control.
here is the link:
http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/a07c453a-c5dd-40ed-8895-6615cc808d91/
Thanks
There is no single WinForms or Windows control that provides this functionality. You need to break the problem down into parts:
1) Create a search box
I believe the link you give adds the "Search" cue to a textbox but doesn't add the search button(?) - if that is the case you'll want to combine the textbox with a new button in a user control.
SendMessage sends a message to a Windows control or Window. In this case it tells the textbox to display the "Search" cue. You need to do this because this behaviour is not exposed by the WinForms controls.
2) Work out how to highlight sections of the text
If you are just using the WinForms controls you'll need to use a RichTextBox control and work out how to change the background color at various points in the text.