Am using RichTextBox in a C#/Winforms application.
Am showing some text in this control which has got some UNC file paths embedded into it:
for example:
filePath= "\\serverName\DirName\File"
Richtextbox shows this file path as a clickable hyperlink in the UI.
filePath= "\\serverName\DirName\File.doc"
I want to show it as plain text instead.How do i achieve this?
Thanks.
There's a property you can change named DetectUrls. It is set to true by default, set it to false to get rid of the clicking behaviour e.g.
richTextBoxName.DetectUrls = false;
Or you can simply set it to false using the properties editor in Visual Studio.
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.detecturls.aspx
Related
When pasting a file to a WinForms RichTextBox the file is shown as the default filetype icon together with the name of the pasted file.
But: This only works for some file types, for example jpg and msg.
It should look like that:
For other file types, for example pdf and doc, the file type is shown instead of the name:
I verified, that the Name property of the pdf file is properly set, and tried to find the place where the text is set in the .NET source code but I wasn't able to get beyond the call to the native SendMessage method
Question: How can I change the behaviour of the RichTextBox, so that the name is always shown?
How to reproduce:
1. Create a new Form
2. Add a RichTextBox to it
3. Set EnableAutoDragDrop to true (but the problem also occurs when calling .Paste())
4. Drag files from explorer to the RichTextBox
Step 1-3 can be shortened using this code:
using System.Windows.Forms;
public class RTBForm : Form
{
public RTBForm()
{
RichTextBox rtb = new RichTextBox();
rtb.Dock = DockStyle.Fill;
rtb.EnableAutoDragDrop = true;
Controls.Add(rtb);
}
}
I am trying to pass a Unicode character corresponding to fontawesome icons to the text property of an asp.net web forms button control from the code behind. It works fine when I do the following:
button1.Text = "\xf044";
However I have to get it from a resource file to conform with the company requirement. When I set the resx file with name/value as "Edit" and "\xf044". The problem is that when I set the Text property equal to this value from resx, it is set automatically as follows.
button1.Text = "\\xf044";
Is there anyway to avoid this? I tried something as follows
button1.Text = myResx.Edit.Substring(1);
Now the button instead of displaying the corresponding font icon, simply displays "\xf044".
Thanks
In winforms, I have something similar to a HTML editor where a textbox control is used to write Html code and a browser control to display a preview.
I am trying to set an InnerHtml property of a HTMLElement with something like this:
htmlElement.InnerHtml = txtCode.Text;
The problem is when assigning a string like:
"<a href='/foo/bar.aspx'>Click Here</a>"
htmlElement.InnerHtml returns:
"Click Here"
The HTML code of the InnerHtml property is saved in a file and the file is used to render content in a website which renders and invalid link.
Is there any way to avoid this behavior of the InnerHtml property, without saving the text directly from the textbox?
My only idea is to delete the text node child of the <a> element, and then append a newly-created text node with your text. This might work around whatever process is interfering with your assignment of InnerHtml.
As a workaround you can try to put script block in your txtCode:
<script>document.write("<a href='/foo/bar.aspx'>Click Here</a>")</script>
I have a WebBrowser control and I will like to get all the text from that control. In other words I will like to get the same text that if I where to grab my mouse select everything from the browser and paste it in notepad. I know there are several techniques to get the text such as WebBrowser.DocumentText or innerhtml but none of those techniques gives the same text that I would get if I where to copy everything from the browser to the clipboard.
This should work:
webBrowser1.Document.ExecCommand("SelectAll", false, null);
webBrowser1.Document.ExecCommand("Copy", false, null);
I'm Using Watin tool in C# to find a text is available in webpage/URL. Using the code:
bool flag = browser.containsText("Some Text");
But returns true, but the text("Some Text") is hidden in page. I need to get only visible text of a URL. i Dont Have the ID/Name of the Element...
Find the control that is hidden and check to see if it is visible and contains the text.
Example if it were a Div and using NUnit:
Assert.IsTrue(myBrowser.Div.Style.GetAttributeValue("visibility") == "hidden" && myBrowser.Div("myPossiblyHiddenDiv").Text.Contains("the text"));
Lots of ways to check for the text; I usually try to go as granular as possible in case there are other controls on the page that contain the text in question.