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
Related
I am using the RichTextBox control in Windows Forms to convert RTF to plain text. In the RTF document there is a string like "www.google.com" which the RichTextBox control converts to a URL. However, if I omit the preceding "http" or "www" (e.g. "google.com"), the string is not converted to a URL.
How can I get the RichTextBox control to convert these strings to URLs?
you can use this post and this msdn for guldens - How to: Display Web-Style Links with the Windows Forms RichTextBox Control
The practice is pretty easy: RichTextBox contains LinkClicked property to help you achieve your goal and you use it by invoking event:
this.richTextBox1.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.richTextBox1_LinkClicked);
If you really want, you can extend the base class and create your custom RichTextBox to support DetectUrls.
I have seen a lot of answers on the web stating that a Label's text can't be selected/copied in the way that a TextBox's contents can,
but what is the underlying reason that a Label's text can't be copied?
Windows itself can find text under the cursor position, so why can't the WinForm Label control?
In order for a user to select or copy a control's text, the control must allow you to set focus to it, either by clicking or tabing to the control.
A Label doesn't allow this, by design.
Label controls are typically used to provide descriptive text for a control. For example, you can use a Label to add descriptive text for a TextBox control to inform the user about the type of data expected in the control.
So while Labels and TextBoxes both inherit from System.Windows.Control they are different things, intended for different purposes. In the same way that oranges and apples are both fruit, but are different.
However, if you're creating an application and want to have something that looks like a label, but allows the user to select (but not edit) the text, then you can use a TextBox with the following properties set:
Backcolor = Control
ReadOnly = true
BorderStyle = none
As shown below...
Alternatively, if you have an application and want to get text from something like a label, you can use the Win32 API function GetWindowText, if you know the handle to the window that contains the text. In a Win32 context a "window" means just about anything distinct that is on the screen, not just the windows that you can drag around with your mouse. WinForms is an abstraction on top of all this.
As for getting the handle to the window that is under the mouse cursor, see this question.
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)
Do You know any good example or any good hint on how to make user controll that has defined text with blank areas which has to be filled out to complete excercise. Then submit answer and check (what was written in blanks and check if its good or not).
What Is the best way of doing that in order to be quite generic for example user (teacher) marks text which should be hidden.
It may be in WPF or WinForms (whatever is better for that).
thanks for any hint on how to begin and what to use.
I think I would have a (WPF) UserControl derived class that can take a custom formatted string (or xml) that contains the text and the placeholders to display:
myUserControl.DisplayContent="Rome was built in #numberofdays# day(s). The first mayor of Rome was #mayorofrome#."
The UserControl parses that string and builds the UI consisting of TextBlocks (the static text) and TextBoxes (the input controls).
Additionally the UserControl has a Property of Type Dictionary<string,string> that contain the strings entered by the user (keyed by placeholder string):
Console.WriteLine(myUserControl.Result["numberofdays"]);
Console.WriteLine(myUserControl.Result["mayorofrome"]);
This dictionary will be filled by the UserControl as the user enters the texts.
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.