I have a WinForms application with a multi-line textbox. I'm populating the textbox as follows:
TextBox1.Text = File.ReadAllText(filename);
The problem is that some of the files have binary characters in them, including '\0', and the textbox truncates the text at that point.
I understand the reason for this (internally, the control uses '\0' to signal the end of the string); however, I can load these files into Notepad. I thought Notepad uses the very same edit control that the textbox does.
Is there any way to duplicate what Notepad does? These are old .WRI files, which NotePad reports as being loaded using UTF8 if that helps at all.
TextBox1.Text = File.ReadAllText(filename).Replace("\0", "");
Related
I have a RichTextBox in which I write text and I give it color and format and what I want is that when I press a button that I have programmed, I open the Word application and pass the text that I have in the RichTextBox to the Word document, along with the color and format that I have given in my application.
I have the following code that opens Word and it passes the text that I had in the RichTextBox but the problem is that it does not show me the color and format that I had in the text in my application.
colorLetra = new ColorDialog();
objWord = new Word.Application();
objWord.Visible = true;
objDocumento = objWord.Documents.Add(Missing.Value);
objWord.Selection.Font.Color = objWord.Selection.Font.Color;
objWord.Selection.TypeText(richTextBox.Text);
Could you tell me why it does not show me the color and format in Word?
Your question is:
Could you tell me why it does not show me the color and format in Word?
The reason is because you only enter/type the text. You don't apply any formatting. You're simply transferring the string value of the Windows Forms control to the Word document, as a string.
Your implied question is: How do I pass formatted RichTextBox content to Word...
There is no way to directly pass formatted information from a Windows Form to a Word document. You must go over the clipboard, as was suggested in a comment. The code that comments points to, however, is incorrect for formatted text. The following works for me:
if (richTextBox.Text.Length > 0)
{
// Copy the formatted content to the clipboard
Clipboard.SetText(richTextBox.Rtf, TextDataFormat.Rtf);
objWord.Selection.Paste();
}
i wrote a small application that will monitor the clipboard and paste text directly in a webbrowser component.
...
DocumentWysiwyg = ClipBoardWebBrowser.Document.DomDocument as IHTMLDocument2;
DocumentWysiwyg.designMode = "On";
...
and when the Clipboard changes, i paste the Clipboard content into the webbrowser using:
ClipBoardWebBrowser.Document.Write(Clipboard.GetText(TextDataFormat.Html));
now, when pasting any copied content from web as html, i get inside the html
span class="Apple-converted-space">Â </span
which does not belong to the html i copied from a website.
what are those? and how can i get rid of them?
any help is really appreciated .
here is the html code for google.de as example
http://pastie.org/pastes/3706386/text
how would i make sure that the pasted clipboard is exactly the same as the copied data in the clipboard?
On Mac multiple occurrences of a regular space " " get converted such that they replace every other regular space with a non-breaking space character aka This allows the spaces to still break on every other character, but preserve such ranges of spaces.
The reason for this is because without this trick HTML would compress multiple spaces to a single one. Having only characters would disable line wrapping, because as their name states they would be non-breaking.
In addition to "Apple-converted-space" there was also "Apple-style-span" but that was eliminated from Webkit in 2011: https://www.webkit.org/blog/1737/apple-style-span-is-gone/
So to answer your question: since Webkit is filling the pasteboard you cannot do anything to prevent such behavior.
C# doesn't want to put Unicode characters on buttons. If I put \u2129 in the Text attribute of the button, the button displays the \u2129, not the Unicode character, (example - I chose 2129 because I could see it in the font currently active on the machine).
I saw this question before, link text, but the question isn't really answered, just got around. I am working on applications which are going all over the world, and don't want to install all the fonts, more then "don't want", there are that many that I doubt the machine I am working on has sufficient disk space. Our overseas sales agents supply the Unicode character "numbers". Is there another way forward with this?
As an aside, (curiosity), why does it not work?
The issue is:
C# will let you put Unicode in, like button1.Text = "Hello \u2129";, no problem
but the Visual Studio Forms designer will not recognize '\u2129' as anything special. By design.
So just paste in the '℩' in the Properties Window or use code.
Change the "Font" of the button to the "Font" (From google:Arial Unicode MS) which supports "u2129". It may help you
have you tried entering the characters manually? also, have you tried using a literal string with #"blahblahblah" ?
I was trying to include copyright symbol (\u00a9) in the form title. Using escape characters or changing fonts didn't work for me. I simply copy-pasted the symbol from text editor.
These characters show fine when I cut-and-paste them here from the VisualStudio debugger, but both in the debugger, and in the TextBox where I am trying to display this text, it just shows squares.
说明\r\n海流受季风影响,3-9 月份其流向主要向北,流速为2 节,有时达3 节;10 月至次年4 月份其流向南至东南方向,流速为2 节。\r\n注意\r\n附近有火山爆发的危险,航行时严加注意\r\n
I thought that the TextBox supported Unicode text. Any idea how I can get this text to display in my application?
You need to install and use a font which supports those characters. Not all fonts support all characters. the [] box character is the fonts representation of 'unsupported'
The textbox might be using MS Sans Serif by default, so change it to Arial or something else.
I changed from using a TextBox to using a RichTextBox, and now the characters display in the RichTextBox.
I was facing similar problem.
It was problem with reading file properly and not with TextBox control.
StreamReader reader = new StreamReader(inputFilePath, Encoding.Default, true)
Copied from THIS.
Works for me and that too without switching to RichTextBox.
Did you add Application.SetCompatibleTextRenderingDefault(false); to your main.cs file? If not, the unicode characters won't show.
Microsoft Sans-Serif does support unicode characters to my knowledge. Check that you have these lines of code in your main.cs file:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
In Visual Studio 2008 in a C# WinForms project, there is a button on a form. In the properties view, the property "Font" is set to "Arial Unicode MS".
What do I need to put into the property "Text", so I get the unicode character \u0D15 displayed on the button?
When I put \u0D15 into the "Text" property, the button displays the six characters "\u0D15" instead of one unicode character.
In the following PDF, you can see the unicode character for \u0D15:
http://unicode.org/charts/PDF/U0D00.pdf
You don't have to escape your unicode characters in strings as C# is inherently unicode. Just put your unicode characters as they are into the string. For example:
button1.Text = "日本";
One possible way is to run "charmap" and copypaste from there or copypaste it from elsewhere.
Just try the following in you C# code:
button.Text = "0x0D15";