i was wondering if it is possible in c# to set to a text box a list of strings that are clickable links? at the moment i can set the text box like this
txtBox.Lines = values.ToArray();
ideally though i would like them as links if possible? maybe link labels or something?
(I'm assuming you're using Windows Forms; the answer for WPF/Silverlight may be slightly different.)
A textbox just contains text - it's not "rich" enough to have links.
If you want a list you might want to consider using a ListBox of some description - or possibly a RichTextBox; I haven't tried creating links in a RichTextBox, so I don't know whether it's possible.
Of course, you haven't specified what you want to happen when the user clicks on the links, either...
Use RichTextBox and check this - http://www.codeproject.com/KB/edit/RichTextBoxLinks.aspx
You can try using Windows.Forms.Controls.LinkLabel. It allows storing multiple links along with the text in it.
Related
I am working on a project (simple phone book) for personal use.
Here you can take a look how it looks like:
IMAGE: http://s24.postimg.org/3qlicrcdx/Kruzeri.png
I am just about to finish it, but first I have to configure search bar to work properly. I would like it to find the contact I have entered in the textBox7. Ideally, first of all I would have to enter contact's name and then press the search button located right by the textbox. Then, it should select the contact I was searching for.
I have tried to solve this in numerous ways but with no success.
Does anyone have any idea how can I do this?
If needed, I have uploaded the whole code here where you can take a look at it:
LINK: http://www.sendspace.com/file/qa8rnq
If you use binding to fill your listbox, then you can just filter your list. For example:
element.ItemsSource = contactlist.Where(x => x.Name.Contains("SearchName")).
Have you read on regular expressions (RegEx)? That way you wouldn't need to write the exact name.
Plus, you should start naming your controls properly. Instead of textBox7, name it something like txtSearch. Using the prefix for the control "type".
Button: btnDoStuff
Textbox: txtDoStuff
etc..
I believe am in need of creating custom RichTextBox in C#. One kind of like that:
I admit it might not even have to be RichTextBox, but after some research I decided it's gonna be the easiest way. Functionality I need are icons at each row, checkboxes and text formatting. My program will process each line of the text and mark lines that are correct, incorrect, and strike out lines not necessary in further work, while showing line that's currently processed and allowing user to edit some lines freely (here: lines before Around 3 000 won't be editable, but those under the line will).
What's the problem then? I have no idea how to get it done. I've seen tutorial on how to make single-line textBox with icon or checkbox nearby, but I have no idea how to make both, and for multiline textBox (so I could freely scroll and everything would work fluently). I've read some questions on SO as well, but neither helped me.
I just don't know how to get started, I realize it won't be 5 min work, but I'm willing to do it. Until now I've been only able to create custom control deriving from RichTextBox, but I have no idea which methods and how to override. Any help appreciated.
Try to use WebBrowser control instead RichTextBox.
You can add CheckBoxes and editable content by setting a correct HTML code to it.
Set each TextBox or CheckBoxes ids and use GetElementsByTagName or GetElementById to access inner elements to get or set its attributes or values.
I already did some research and ended up with several autocomplete boxes which have one thing in common: they all match the whole expression which has been entered. Sometimes, they seem to be easily expandable, but at the end, they aren't.
However, I need a Textbox which allows the user to enter a word (e.g. "tag1"), displays a popup with some suggestions based on this single word, accept the suggestion with the return key and type in a new word (e.g "tag1 tag2") in the same textbox, with the popup popping up again. (I like the way CintaNotes handles this)
I need this for a tagging interface. It's often faster for the user to write the tags into a simple box, but sometimes, he needs assistance. This is what the autocomplete is for.
I've found some results, which don't work for my purpose (imho):
http://www.wpfpedia.com/item/details/743/wpf-autocomplete-textbox-control
http://www.codeproject.com/KB/WPF/WPF_Autocomplete.aspx
http://www.codeproject.com/KB/WPF/autocomplete_textbox.aspx
http://weblogs.thinktecture.com/cnagel/2011/01/autocomplete-textbox-with-wpf.html
Btw, I really like the way the Tag-Box for SO operates.
Does anyone have an idea? Is there a "out-of-the-box" - solution somewhere, which suits my needs but I didn't find? Or do I have to build one myself?
Thanks! :)
I think you mean a textbox which autocomplete for multiple words.
Like TokenizedTexbox on WPF Extended Toolkit.
this is the page: http://wpftoolkit.codeplex.com/wikipage?title=TokenizedTextBox&referringTitle=Home
Probably you would need to create your own Dictionary object of Key and Value pairs and hook that Dictionary to the textbox events and popup a suggestions dialog that displays the Value(s) from your Dictionary
Check this implementation out: http://code.google.com/p/kocontrols/downloads/list
You may inject your own Search algorithm and your own converter which converts the selected element to text, which you display in the TextBox. You will have to modify it slightly but I think that you might be able to solve your problem by basing your control on this implementation.
I never thought about this type of use case.
Can't you use different textboxes for the different tags? Something similar to how goole code does it?
If you have time, you can use the RichEditControl or TextBox and apply the same pattern used in Intellisense engine or Code Completation enabled editors: Hook the text changes events, Recogize context (last/current word) and display the options list on popup control. And optionally, on commit (detect acceptation or space key), apply the format to the word.
I have what I consider to be a pretty unique problem here, and no idea how to implement. From what I've seen, there is no documentation, tutorials, samples and/or articles on this. I've spent weeks researching, with nothing to show.
The problem:
I need the user to be able to select the contents of a Label Control at runtime, and edit it.
If this can be done by extending the existing Label control, great! Or, if this requires a whole new Label Control to be created, fine. So be it.
Using a TextBox is not an option I'm afraid.
Any help at all is greatly appreciated!
Thank you,
jase
If it's just because a look & feel issue you can make a TextBox control look the same as a label would looks like (just guessing since I can't imagine any reason for not using a TextBox).
Could you pop up a window with a text box in it and then have them edit it there, then set the text property of the label based on the edited text box or do you need to edit it in place? You can set the label text at runtime, but for user input you will have to use a text box.
I am trying to break out of vb into c# and needed a personal project to get some c# practice in to cement the syntax differences in my mind.
I decided (for want of something better) to write a little twitter client, only something basic.
I have designed a user control to contain the info about each tweet (the tweet itself, the user that tweeted, the date and time etc). As we know tweets can contain embedded links in their text and I was wondering how you handle this in a windows form.
There seems to be a Linklabel control, but you don't seem to be able to have normal text in it, the Label control similarly doesn't support clickable links.
Would I have to embed a link label inside a normal label control and parse the tweet text for url's?
Or am I approaching this in completely the wrong way? :)
You can (sort of) combine normal and linked text in a LinkLabel:
this.linkLabel1.Text = "Here is some text";
this.linkLabel1.LinkArea = new LinkArea(0, 4);
Problem is, there can only (AFAIK) be one link destination, which is obviously not going to work for your purposes.
One possibility may be to use the RichTextBox, and handle the LinkClicked event. I'm not sure if that will give you enough information, but if nothing else, will provide some good practice, since that's the goal anyhow!