how to implement a search box in c# - c#

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.

Related

Windows Forms Adding Text without Textbox

I am using Visual Studio 2019 in order to create a Windows Form Application. I need some titles in my application, which means these strings will not be modified by the user.
For now, I created textboxes for these titles and made these textboxes "read-only". However, this does not satisfy my aesthetical expectations.
Therefore, I wonder if there is a way to add a string without adding a textbox, to the form. Is there a way?
Thanks in advance :)
Consider using a Label control rather than a TextBox.
The only time I would use a TextBox as a label is if I want the user to be able to copy the info, and I make it borderless, readonly and have the same colour as the background of the form. It's not superb UX though as there isn't anything that screams "you can highlight and copy this text" other than an I beam cursor, which is pretty much "mystery meat navigation" - better off putting a copy button next to it if you expect the user to copy info often
Why not use Label for your titles?
Since label, by default, cannot be modified by the user, thats what you want. Textbox is used for the user input, not for the titles.
Use Label control that is the right control to use for your requirement

Find Window to search string in richtextbox in winforms application

I have written a winform application where i have a form with richtextbox control populated with string. I need to search specific pattern of string from the the string in the richtextbox control when user presses ctr+F just like we Find specific pattern of string in notepad++. Do i need to create the Find window by myself or is there any default Find window control which I can use?
Any help is highly appreciated.
You have to create a window that finds the specific character/word or sentence what you want. Windows Form Control doesn't provide any kind of UI facility to find your string. It is also depends on that from where you want to find the string. you must have an editor like Textbox, RichTextbox or any control which contains string values like DataGridView, WebBrowser Control, ListView etc. but, each control can have their own method to find a specific string. for example if you want to find a string in RichTextBox then you have to call the method from that particular control (richTextBox1.Find(...)). You can't find the string from all controls globally.
If you want to implement the feature in particular control like TextEditor (Word Pad) then there is an example on Code Project site that you can refer.
RichTextBox Control with Find functionality

Highlighting particular text ina WPF textbox and registering event to that text only

In my WPF application I am having some following type of textbox
So, In this textbox, the text is not written by user it is generated by program, i wish to Highlight the particular text "Enter String Value" and when user clicks on that particular highlighted text only then I wish to fire a event.
Can u guys give me some hint or overview to achieve this. I tried few tricks but can't get success.
Thanks in advance.
Use <RichTextBox> with <FlowDocument>. As I know, TextBox allow you to determinate font (color, size, etc.) only one time, and you wouldn't able to modify color of partial text in one TextBox
I think you can use Regex to get your match from your textbox, and then create Run objects using that match. You can set the Background of the match (runobject.Background = Brushes.Red)

Is it possible to place "hints" in Windows Phone 7 TextBoxes?

I just got started programming for Windows Phone 7 after programming on Android for about half a year now. In Android, when I wanted textual input from a user, I would put a "hint" in the text box which would tell the user what they should input. When the text box was selected the hint would disappear. So far I've only seen ways to set text inside text boxes. The problem with this is that the text does not disappear when the user selects the text box forcing the user to erase the currently existing text.
I did some Google searches and skimmed through relevant documentation as well as a book I have but I've not found an answer yet. Thank you very much in advance for your time answering my question.
What you're looking for is normally called a "Watermarked" textbox. It's quite simple to create a control which implements this functionality.
Here are links to a few versions of implementations of this:
http://blogs.msdn.com/b/arun/archive/2010/03/29/watermarked-text-box-for-windows-phone.aspx
http://www.windowsphonegeek.com/articles/WP7-WatermarkedTextBox-custom-control
http://www.danielmoth.com/Blog/Watermark-TextBox-For-Windows-Phone.aspx
http://weblogs.asp.net/jdanforth/archive/2010/09/17/silverlight-watermark-textbox-behavior.aspx
WatermarkedTextBox for Windows Phone 7?
http://www.silverlight-zone.com/2011/03/wp7-watermarkedtextbox-custom-control.html
http://watermarktextbox.codeplex.com/
As I understand you want something similar to the default text in the searchbox (upper right corner of stackoverflow.com).
You have a few options.
Bool to check if user press the TextBox for the first time.
private bool m_textBoxPressedFirstTime = false;
and inside the event (double click the TextBox)
if(!m_textBoxPressedFirstTime)
{
myTextBox.Text = String.Empty;
m_textBoxPressedFirstTime = true;
}
Define your own template with a diffrent visual state.
You could use some WPF examples
How do you implement default text for a search box in WPF?

WPF: message box with checkbox added

In WPF I am looking for a "do not show again" checkbox on my messagebox popup.
Does anyone know where I can get such a control or maybe how to copy the style of the regular WPF messagebox so I can create my own?
Thanks
Take a look at the Dialog Boxes Overview. The overview covers Message Boxes, Common Dialog Boxes, and Custom Dialog Boxes. In your case you'll want to create a simple Custom Dialog Box that includes a message, a checkbox, and however many buttons you need.
Basically you need to define a new code-behind file that includes your TextBlock, CheckBox, and Buttons in a panel object, and you need to extend Window. In your code-behind file you implement any necessary logic to implement the user's choice, and you return this result to the object containing the custom dialog box.
Make sure to pay special attention to this line of code when creating your custom dialog box:
// Open the dialog box modally
messageBox.ShowDialog();
The call to ShowDialog() will ensure that the user must take action against your dialog box before moving on to other parts of your application.
I think , you may have to create by yourself and it is really easy in the WPF
You could just use a dialog box. An easy way to do it would be to keep a variable in the project settings that would be updated on the popup close() event. So then you would just have to verify the value in the project settings before showing the popup.

Categories