It looks like you're using an Ad Blocker.

Please white-list or disable AboveTopSecret.com in your ad-blocking tool.

Thank you.

 

Some features of ATS will be disabled while you continue to use an ad-blocker.

 

C# Programming Question.

page: 1
0

log in

join
share:

posted on Dec, 23 2013 @ 05:48 AM
link   
So, this should be very simple and straightforward, but unfortunately it's not.
Basically, I'm trying to create a "Multi-Notepad" that displays multiple "NotePads" on a form.

It's something I'm using for work, where we have to keep track of 4-5 different sets of notes at a time.
So I have the form created using rich text boxes, no problem. The problem lies here :

Every time I copy from any external source, and paste into one of the Rich TextBoxes, it keeps the formatting from the external source. Ideally, in these notepads, I want the font and size to be the same. It really messes up the look of the notes when I paste in other info from other places.

Basically, ON PASTE, (I use CTRL+V exclusively for the pasting) I want to strip all formatting from the external source, and have it paste as the default font/size for the richtextboxes.

I've been searching and trying different pieces of code for hours now and nothing is working!!!



posted on Dec, 23 2013 @ 06:23 AM
link   
reply to post by graphuto
 





String txt = MyRichTextBox.Text
File.WriteAllText(filepath, txt);



posted on Dec, 23 2013 @ 06:38 AM
link   
reply to post by scottlpool2003
 


I appreciate your response. I'm not sure that this would work though, as I'm not pasting from a file, it's pasting from clip board, I'm copying things from other web pages and pasting into the rich text boxes using control c and control v.

Edit to add :

I don't know if this is relevant but the boxes must retain the info already typed into them, we can't just set textbox1.text = anything
edit on 23-12-2013 by graphuto because: (no reason given)



posted on Dec, 23 2013 @ 07:18 AM
link   
I got it!
For anyone curious :

You'll need to set the following event for each texbox :
this.richTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.RichTextBoxKeyDown);

Then, you'll need to create a paste key event.

private void RichTextBoxKeyDown(object sender, KeyEventArgs e)
[
if (e.Control && e.KeyCode == Keys.V)
[
try
[
Clipboard.SetText(Clipboard.GetText());
]
catch (Exception)
[
]
]
]


And that's it! Awesome!

edit on 23-12-2013 by graphuto because: (no reason given)



posted on Dec, 23 2013 @ 07:25 AM
link   
use a text box



posted on Dec, 23 2013 @ 07:56 AM
link   

acacko
use a text box


i'd agree too.. why load more resources to your application when you weren't going to use their features?

but anyway, instead of using the key down event, better to use text changed event.. it will also cover paste thru other methods than ctrl+v..



posted on Dec, 24 2013 @ 04:49 AM
link   
A text changed event wouldn't work, as I'm always typing into these boxes as well as pasting info in.
Or am I misunderstanding how that works? My understanding is that "when the text is changed" the action happens. I wouldn't want to paste from clipboard anytime the text in the box changed.

Also, using richtext because it auto adds a scroll bar and can hold more characters.

As far as pasting through other methods, I made this program specifically for myself, and never paste using other methods... Also, For some reason, right clicking in a richtextbox doesn't automatically bring up a context window ... Maybe I need to hard code one?
edit on 24-12-2013 by graphuto because: (no reason given)



posted on Dec, 24 2013 @ 08:08 AM
link   

graphuto
Also, using richtext because it auto adds a scroll bar and can hold more characters.

The maximum number of characters allowed in a textbox is the same as the one allowed in a richtextbox, 2147483646. In a textbox the number of characters is also limited by available memory, but I don't think that should be a problem.



posted on Dec, 24 2013 @ 08:27 AM
link   

graphuto
Also, For some reason, right clicking in a richtextbox doesn't automatically bring up a context window ... Maybe I need to hard code one?

Yes, you need to add a context menu and to associate it with the richtextbox, then show it when you right click, it's not automatic.



posted on Jan, 7 2014 @ 08:09 PM
link   
textbox are good for just stringy stuffy.
but i like using richtextbox as they retain formatting and in your instances it sounds like you want to retain formatting from the clipboard.
But you solved your problem and thank you for sharing your solution. that snippet will come in handy.




top topics



 
0

log in

join