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.
Related
I have a form with many text boxes on it. beside some of its text boxes i used a button that user should click on it to open another form and chose a value from Data grid view on it that shows selected value in a text box. by click on a button this text box value should pass to a text box of first form.
most of codes that I find in internet made an instance from form. but my main form is open and just have to get value from other form.
if you use Linq then it can be very simple.
Application.OpenForms.OfType<Form1>().FirstOrDefault();
Or whatever the form class name is.
You can then get the instance of the form and address the function or property that you want to change.
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?
I'm using a form (FormView) with databinding (ObjectDataSource) and all my input fields are bound by using '<%# Bind("field") %>'.
Everything works fine, but I have two problems (which I found various hints about like using this.Validate() or .EndEdit() - but none seem to work):
Entries are only saved after leaving the input field so it looses focus
Let's say I have a textbox with an ID of Name and enter "George". When I would tab to the next textbox or when I click somewhere else and click save - everything is saved. But when I keep the focus in the textbox the value is not saved. Why is this happening? What magic can I use to circumvent this (JavaScript to the rescue?).
I set a textbox's field value (element.value) via Javascript (upon selecting something in a combobox).
The same problem as above applies, only when I give the textbox focus and tab out the value is saved. This creates the problem that I only want the user to choose something in the combobox (the textbox is updated accordingly) and move on - I don't want the user to click into the textbox afterwards and tab out again.
Edit:
The second problem I resolved now by setting the focus onto my textbox via Javascript (textbox.focus();) and right after set the focus back to the combobox (combobox.focus();) and that does the trick - this seems fairly hackish to me, doesn't it?
I'm assuming this is fairly common, but my mighty Google fu hasn't help me find a simple solution.
A similar issue can crop up in Winforms development when working with DataGridView controls. I typically attach some logic to the submit button's Click event to cause the DataGridView to validate. I suspect a similar solution would work for you here.
I have a question? How can I wire up an button in a winform to take an input from a label, and put it in a text box to display the result?
I'm confused!
I have 4 labels... I want to be able to have people put input into the labels click the update button, and then display the results in the textbox below.
Any help? Thank you!
OK so basic outline of what you need to do:
1) Go to the toolbox and put textbox(es) on the form for the user to type in.
2) Add at least one label for your output text
3) Add a Button
4) Select each item on the form, go to its properties (f4) and set the Name property for each one to something that you can remember (this is how you'll reference the controls in your code)
5) Double click on the submit button. This will open up an "Event Handler" for Button.Click, which means the code you write will run when someone clicks the button.
6) Write the C# code to do what you want. For instance, this takes the contents of a textbox (tbInput.Text) and copies it to the label text (lblOutput.Text):
lblOutput.Text = tbInput.Text;
Hope this helps...if not, read the first 3 or 4 chapters of any beginning C# book.
You don't put input input into label, you do that in a TextBox. A label is a as its name implies a "label" (fixed unmodifiable text).
Most simply, create a method to handle the Click event of the button, bind it in.
Inside this method get the text from the labels, and then update the textbox with the input.
.NET standard Labels are not the controls you are looking for. Labels are just that...text labels that do not provide for text input. What you want is a TextBox, which you will be able to find in the Visual Studio Toolbox.
If you want the look and feel of a Label, but the functionality of a TextBox, you can modify the TextBox properties accordingly (border style, background color, etc).
Drop a Button onto your form, and from the Designer if you double-click the button, a _Click event handler will be generated in your source file from which you can implement the code to do whatever it is you want to do.
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.