I have a button in wpf that when clicked does the following:
Clipboard.SetText("a\u0000b")
When I try and paste the contents of the clipboard into notepad all i get is:
a
How can I get the entire string?
If I render this string in a wpf control, i see a[square thing]b. In other words, the view control does not terminate at a null unicode character.
I tried to find if you can copy text with NUL in Windows, and it presumably is not possible. Maybe you could temporarily replace NUL with some other character, which should never appear in any text you process (although it probably will one day, as Murphy's law states), then open the text file and convert all occurrences of this character back to NUL?
var text = "a\u0000b";
var textToCopy = text.Replace("\u0000", "\u3f45");
Clipboard.SetText(textToCopy);
// Next paste the contents to the file and reverse the replacement there
It is a workaround, but if you're the one using those text files, it might be worth a try.
Related
So my current project is comming to an end.
But I have an issue, i need to get a selection from any window and insert that into my current method, and then paste a new string into the selection.
This means that if i mark the following "This is a simple line", and i press my shortcut, i want "This is a simple line" to go into my method, and transform the text to "This line is more advanced", when i press my global hotkey.
Currently the method takes a string and returns a string (So the method works fine), i just need for it to copy the selection, do the method and then paste the new text, when i use my shortcut.
Any ideas?
I've solved it, the "fix" was just to simulate/emulate the "ctrt + c" "ctrl + v" shortcut in the project. I've gotten my inspiration from: This youtube video. Big thanks to "Matthew Watson" for the suggestion
Clipboard.SetText(textBox1.Text); //To copy your text to your clipboard
Clipboard.GetText(); //To get your text from your clipboard
Credit: https://stackoverflow.com/a/10140582/12345062
I have a basic text editor app, and I aim to add a feature where the user can click a button and add premade text after where their cursor is.
I currently have this (using some code I found online)
richTextBox1.CaretPosition.InsertTextInRun(s);
I intend for the string s to be the string to be added.
However, the RichTextBox in System.Windows.Forms does NOT contain a CaretPosition. I found one post from 2010 suggesting you use System.Windows.Control, however, that is no longer accessible in .Net Core, it depends on presentation framework.
So, is there any way I could get my goal (inserting a string after the mouse cursor, in a rich text box), in .net core?
Updated2:
Use the following code to fully satisfy the richtextbox of the text text environment.:
richTextBox1.Select(richTextBox1.SelectionStart, richTextBox1.TextLength);//Select everything after the cursor
string tmp = richTextBox1.SelectedText;//Copy them
richTextBox1.SelectedText = "";//Set to null
richTextBox1.AppendText("Hello world"+tmp);//Add the target string and add the original text
Updated1:
// Determine if there is any text in the Clipboard to paste into the text box.
if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) == true)
{
IDataObject dataObject = Clipboard.GetDataObject();
Clipboard.SetDataObject("Hello World");
richTextBox1.Paste();
Clipboard.SetDataObject(dataObject);
}
else
{
Clipboard.SetDataObject("Hello World");
richTextBox1.Paste();
}
This action preserves the contents of the original pasteboard.
Only works if the clipboard is data. I will continue to update after I think about it.
Original:
You only need to use the clipboard and paste method to insert the specified string after the specified cursor.
Clipboard.SetDataObject("Hello World");
richTextBox1.Paste();
Clipboard.Clear();
Change it yourself according to your needs.
So, the problem is there I already have the formatted text in RTF format but when I save the file it gets "wrong", the header disappears.
I'm using the RichTextBox Class to create the file, where finalText is the formatted RTF text, making the code look something like this:
System.Windows.Forms.RichTextBox RichTextBox = new System.Windows.Forms.RichTextBox();
string finalText = "{\rtf1\deff0{\fonttbl{\f0 Calibri;}{\f1 Arial;}{\f2 ..." //Formatted RTF here
RichTextBox.Rtf = finalText;
RichTextBox.SaveFile(_RtfPath_);
When I do this the final version of the generated file is almost complete, but the header disappears.
Editing the file in notepad++ I noticed that it removes the header and the information contained in it. After this I decided to manually create an RTF file. I opened the almost complete RTF file in notepad++, erased everything and pasted the finalText.
When I reopened this file the final version was the way I wanted it.
Is there any way I can save the text as RTF without having to use the RichTextBox Class to format the output file?
I am creating a C# UWP application and I have noticed that the line feed (\n) character is missing from the output text when I enter it into a Textbox. When I press enter into my Textbox it produces CR+LF character (\r\n). what can I do to bring the textbox behavior to notice both CR+LF & LF. I have set AcceptReturn = "true" and I have even tried replacing \n with \r\n but that doesn't work either.
As #lindexi said the new TextBox used \r as line feed character in Windows 10 build 15063. If you want to bring the textbox behavior to notice both CR+LF & LF. You may handle it programmatically on KeyUp event. However the \n & \n\r will turn to \r automatically.
For example :
// original
MyTextBox.Text = "Nico Zhu \nzhuminghao\nwanglaoshi\r\n\rzhuzhuz\n";
// converted
MyTextBox.Text = "Nico Zhu \rzhuminghao\rwanglaoshi\r\rzhuzhuz\r"
For more please refer to UWP TextBox control giving unexpected results.
I've used WindowsApiCodePack C# wrapper of windows TaskDialogs.
When I tried to show long text with paths, I got all my paths shortened by ellipsis instead of true word-wrap. This makes filenames in paths non-readable. Like here:
Same behavior when settings this text in spolier text or in main text.
Is the way to disable this feature? I want my paths to be shown completely, wrapped or somehow else.
This is what I expect from text. How MessageBox work with text: