Display string with incorrect format using RichTextBox - c#

I am doing some binary decoding of a DataFormat, and is trying to display the text in a RichTextBox in C#.
When looking at the variable in Visual studio the debugger shows this value \u0005\0\0\0\0\0\0\0\0\0?A\b\0building???=\0\0\0\0\0\0\0\0\0\0\0\0\u0003\0\0\0" but my TextBox only shows ``
How could I show an invalid string like this?

Try to change RichTextBoxStreamType.RichText to RichTextBoxStreamType.UnicodePlainText to avoid the Invalid File format.

Related

How to save an entry in a text box in Visual Studio | C#

I understand it for a rich text box, inside an open file dialog control, for example,
richTextBox1.LoadFile(openFileDialog1.FileName.RichTextBoxStreamType.PlainText)
I understand it for using WriteLine, in the console, for example,
File.WriteAllText(path, variable)
But I am unsure how to use something other then a richTextBox to write a text file, for example a textbox, or a label. I tried using textBox1 in place of richTextBox1 but that does not seem correct.
File.WriteAllText(path, textBox1.Text);
You have to extract the text out of the textbox first.
textbox1.Text //this gets you the text in the textbox

C# textbox with mixed Western and Arabic text

I would like to display mixed western & arabic data read from a file into a text box.
An example of the data is I want to display is:
"You have", "يوجد لديك"
I read the data in as follows:
String tsIn = File.ReadAllText(tbxTSFileName.Text, Encoding.UTF8);
tbxBefore.Text = tsIn;
I cannot see any properties that let me set the textbox to "mixed" encoding.
When I open the file in Notepad++ I select Encoding>Character sets>Arabic>ISO 8859-6.
To make matters even more complicated, I would want to use the same textbox for other languages too, so the solution needs to work in all/most cases.
You need to show us the assignment to the textbox - for instance, is this a WinForms textbox, a WPF textbox or an HTML textbox.
Strings in C# are unicode - so can definitely hold Arabic.
You are reading UTF8 format which supports Arabic so I cannot tell what your actual problem is. Your tsIn could easily contain Arabic - is your problem that you cannot see Arabic in your WinForms TextBox ? This link has a lot of detail on displaying arabic on WinForms
Winforms Arabic Input text box

Displaying Raw Data From Image File Using TextBox or RichTextBox?

My program reads a DDS image file and stores it as a byte array. I want to be able to show the users the raw data in a TextBox form so at first I convert the byte array to a string using the following code:
string data = System.Text.Encoding.ASCII.GetString(bytes);
I then set the TextBox text:
textBox.Text = data;
The problem I am having is the text box is not showing all the data. Here is a screenshot of how it looks:
As you can see only the first few characters are displayed. I am assuming this is because the string contains a null terminator which the TextBox interprets as the end of the string. Here is a copy paste of the first 50 or so characters in the string which I copied directly from the debugger watch window:
DDS |\0\0\0\a\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
As you can see the first null character comes right after "DDS |" which explains why that's all that shows up in the TextBox.
What I want to be displayed is similar to what you see if you edit the raw DDS file with a text editor such as Notepadd++.
Opening the DDS file in Notepad++ produces the following:
My question is, how do I get my TextBox (or RichTextBox) to show the data in the same way that Notepad++ shows it?
The simplest solution is to use this:
textbox.Text = data.Replace("\0", #"\0");
This will force the textbox to actually show a backslash followed by a zero where the nulls would be. Alternatively, you could replace the nulls with some other character or string.

RDLC exported to excel to show negative numbers in parentheses

I have an rdlc file with cells showing decimals.
How do I convert a negative number to have parenthesis?
I can't display it as a string, because when the report is exported it treats in as a string and throws an error that the number could not convert a string.
I've tried adding #,0:c0 for the format property but this didn't work.
Any suggestions?
Try to not use the Format function in the Expression of your Placeholder, instead in the text box (or cell) properties, you can set the type and the format of it.
In the properties, there is a section called Number in which you specify that the textbox must contains numbers of a specificated category.
Here is an image to explain:
As you can see, there is an option to set how to display negative numbers (the one selected).
Now, I'm sure that this will works if you export the report in PDF but I hope this will be the same for Excel's export
I worked it out, sorry to answer my own question.
if I use the following in the format property #,0;(-#,0) it works fine.
In my case below custom expression solved my problem.
''#,0.00;''(#,0.00);

How To set content from a textbox in a Textfile in C#, SharePoint?

I have a text file in which I have a word like $variable. I read it all and look if the "$variable" is in it. Then I want to replace the word "$variable" to the content of a text box and afterwards write the text in the same text file back.
If I use constantly strings like
string var = "hello";
It works. But can anyone tell me how to do this with the content of a text box?
This might help:
How to write to a file
http://msdn.microsoft.com/en-us/library/6ka1wd3w
and how to read from a file
http://msdn.microsoft.com/en-us/library/db5x7c0d
and to get the value from the textbox use
string textValue = txtMyValue.Text;
but then use the name you gave to your textbox

Categories