Hyperlink inside a WinForms Label - c#

For example, the About dialogue of Notepad has only "Microsoft Software Licence Terms" as a hyperlink but the rest of the text is not. How can I achieve similar result with the Label (or Labels) of WinForms?
I can use two labels, one Label and another LinkLabel, but then the two will not be concatenated naturally (the width of labels may vary by the system font face or the language).

You could use a LinkLabel, then set the LinkArea property. This should highlight the link you want and will also be the only clickable part.
Properties > LinkArea > ... button then just highlight the text part you want as a link

Related

How to lighlight link in text box

I have to create some controls similar to a control TextBox. But I want this control can Highlight link as RichTextBox, Because I have problem with RichTextBox so i can't use it. How do I highlight a link in a TextBox? or I have to set each property by a line of code?
I want to display it in a TextBox as shown below:
This is not possible. A simple TextBox control cannot be used to display formatted text.
A hyperlink is just specially formatted text: all it really does is change the foreground color to blue and the text style to underlined. TextBox controls don't allow this type of granularity. All text in the control has the same formatting applied to it.
What you would need to use is a RichTextBox control. This is specifically designed for displaying formatted text, and not only does it allow you to define arbitrary formatting for specific bits of text, but it has built-in support for detecting and highlighting hyperlinks. You say in your question that you had a "problem" with using the RichTextBox, so that is really the question that you should have been asking.

What is the (technical) difference between a Label and a TextBox?

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.

Aligning controls inside cells of a TableLayout

In the picture below I have defined a 6-row table layout and placed controls inside its cells, in one cell goes the Label, the other cell for the control its self (a text box for example )
The problem is caused by that field options radio box, it will make the cell so big so then the text box that is under "Preview Data Value" label, goes way below...
How do you suggest fixing this issue?
From my prior experience, I would not use the table layout at all. Instead I would set the anchors on each control to dynamically change with resize.
But if you insist on using the table layout, perhaps you should change the RowSpan attribute of the Preview Data Value cell, and have the label at the top with the text box underneath.
Another option would be to use a container like a GroupBox with a title Attribute that you can set to "Preview Data Value", put the text box in that container and set the "Dock" Attribute to "Fill". Then from the looks of it, you don't even need the last Row.
See this article on MSDN if you want to go totally nuts and implement your own drawing.
Make a seventh row and have the option group span two rows.

C#, Display plain text in a form

I can only find rather "complex" functions, like RTF Text box etc. I couldn't figure out how to display "plain text" in a Form1.cs
(I do not talk about HTML to WinForm. Search did not return any useful results)
You can use a Label or a TextBox.
If you use a TextBox, set MultiLine to true and ReadOnly to true to not allow editing.
Use a TextBox or Label. That's what they're designed for - displaying plain text.
Label is not very suitable for that. It makes a new line only on "\r\n", which means a very long paragraph may exceed size of the form.
A TextBox with the following properties is perfect for it:
Multiple lines
ReadOnly = true
No border.
And, drag the right / bottom borders to align with borders of the form, it's size will automatically change along with the form.

how to implement a search box in 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.

Categories