I have a single line textbox, when I copy some text from lets say notepad that is on multiple lines and paste them in to my text box, only the first line of text appears (thats obvious) but how can I change this so that the lines are joined automatically upon pasting them and separated by a space. I see that I would need to modify the textbox_changed event but this would affect everything that goes on in that textbox not only the paste event. Could you provide me with some code to handle a paste event and ignore all other events.. thanks :)
winforms
mouse paste event
is this what you're looking for?
Clipboard Events
A Textbox in C# has a number of useful events to indicate when certain actions have been taken. For example, .NET textboxes have an event to indicate when the text has changed or when the user has pressed a key. These events allow C# developers to write clean code that interacts with textboxes.
Following the same principles, we can manually implement events that are triggered by clipboard actions, i.e. text is cut, copied, or pasted in the textbox. The .NET Framework does not come with these events, but they are not difficult to implement.
7/5/11 Update: Added support to suppress copy, cut, and paste events.
Custom Textbox
To implement custom events, we are going to have to create our own textbox user control. The user control will inherit the Textbox class since we want all the default behaviors of a .NET textbox.
Creating a custom user control will also let us override the WndProc function, which processes messages passed to the control. By overriding the function, we can detect messages such as when text is cut, copied, or pasted, before allowing the control to process them.
if you are using .asp webforms you need to change the text mode in your textbox
to SOMETHING LIKE THIS TextMode="MultiLine" Columns="50" Rows="5"
in Winforms
textBox1.Multiline = true;
Related
I'm attempting to make a command prompt clone in C# so I can get familiar with using IO. However, instead of just one text body, I created two text boxes (one for the command and another for the "parameters") and a rich text box to view the result of the commands. It may sound confusing and the title may be misleading, but I didn't know how else to word it. Anyway, my question is- how do you make only the current line editable and the rest read-only? And how would I be able to combine the commands and parameters in the two text boxes so I wouldn't need two separate text boxes? I have spent 6 days trying to figure out the logic to implement this but I got nothing.
Here's a picture of the form:
And here's what I want to make it similar to:
I'm not sure if you can do that, but if it was me, and this was a "get it done now" situation (and this is just off the top of my head), I would create a user control to contain the "screen". This user control would have the RTF or list box as the top, and a textbox flush under it.
I would remove the borders and wrap both these controls in a panel that has borders. This would simulate a single control.
The textbox would check for the enter key in one of the key-press events, and the control itself would have events that could be handled by the parent control.
This may be hacky, but it would probably be what I'd do in a last minute situation.
Oh as far as the command and parameter stuff, if you read the textbox as a single value, then split the string into an List or array, you could then define a switch or some other conditional code that would know what to do with parameters (index 1+), based on the value of the first item/index.
Once I successfully validate user data in a TextBox (using TextChanged EventHandler), I'd like to programmatically tab to the next input control. I know I could hard code the name and do
Score2.Focus(Windows.UI.Xaml.FocusState.Keyboard);
but I've got 20 TextBox controls on the page page and I'd like to use the same EventHandler for all of them.
While it may be possible (iterate through the page's control inspecting their tab order and selecting the appopriate next control), I would recommend against it. It will irritate your user if they leave a text box to go back and correct a previous field but your app decides it knows better and gives focus to another field.
I'm looking for a Textbox control that works similar to the email recipient textboxes in Outlook (the To, Cc and Bcc inputs). It shall have below characteristics.
Allow user text inputs with auto complete based on history
Word/Phrase identification, separation, underlining (like links)
Keep a list of objects represented by these words/phrases
Once click on a work/phrase fire an event to show the corresponding object related to that entry.
If nothing is out there, I may look to develop one by my own. Any help to direct me either on existing controls or how to do it, is highly appreciated.
Tks,
- Eranga
I don't know of products out there but i'd approach this problem by having a look at the code in the richtextbox WPF Extended toolkit (you can nuget it but i'd download the code)
In there is a formatter which will allow you to markup flowdocuments in the rtb. if each address is stored as a run in the rtb you have your list of separate items which you can process as you like. there also a bunch of events you can hook into as well.
All this assumes you are using WPF.
I have a WPF Window that was created dynamically by loading a XAML script, which is part of a bigger script(Proprietary) that we support.
This Script contains supports for user actions like text box lost focus / Check box checked / Button clicked etc..
Say I have a pre written C# class meant to support functionalities of the class.
Since the windows is dynamic it might contain any number of basic UI element like button, radio button check box edit box etc.
How do I link XAML to every possible action on the dialog box, like text box lost focus / Check box checked / Button clicked etc.
Ideally if I can get Name of the UI Element Action and a string from XAML into C# class that is perfect.
example Button1, "Clicked" "Button1_Clicked" here Button1_Clicked is a string that has been passed from XAML which helps me call the function “Button1_Clicked” in my scripting
language. Similarly for a text Box it could be Text1, "LostFocus" "Text1_LostFocus" etc..
How can I write my supporting class and the XAML script to achieve the above mentioned scenario..
just have a look at this post
Loading XAML XML through runtime?
This is my first tryst with C#. The form that i have in mind consists
A textfield which will be supplied with the path of an executable.
A "Run" button which will call the executable(cosole app)
The executable console output should be displayed in the rich textbox.
Now when i click on a line in richtext box, i select and get the text in the line. This text maps to some other text info. I need to display this text info as a tooltip over the line.
More explanation:
The output of the exe is displayed in the text box as
Address1=Value
Address2=Value
Now when i click the line "Address1=Value", i map this text to find some info regarding what bits are set like
enable : 1
select : 0 ..etc
this info i need to display as tooltip over the line. Is such a thing possible? Is there better alternative to RTB/tooltip for this problem?
Thanks
Vivek
I would recommend using a ListBox for each string of data returned and then if you use a tooltip it makes alot more sense because you are hovering over a list item specifically not the whole text field.
Using the ListBox and items should make it alot easier to work with overall since it will be separating them into defined items instead of just appending lines to a text box.
Also I think you might have alot of work in store for you for trying to make the text box behave the way you want it to for it to treat each line differently dependent on the text of the line.
If you're using the textbox because later you want to be able to select all the output to copy and paste it I would have the textbox hidden by default and have a button that says like "Toggle Raw Output" that will show/hide the text field so users can get the text easily. While using the ListBox as the primary display for information.
What I understand from your question is that when you click on the line in the RTB, your code scans the text on that line, identifies the extra data associated with that line and then inserts it into the tooltip for the RTB.
Technically I believe that this is possible to do - although I am not 100% sure of the mechanics of inserting tooltip text. However as a user interface feature I would personally not do that as the tooltip text is displayed whenever the mouse pointer is anywhere over the RTB. Thus if a user clicks on line #1, (and sees the data associated from line #1) but hovers the mouse of line #3, they might think that the tooltip is associated with line #3.
You could alleviate my concerns with a strongly worded tooltip, but I feel that what you are doing is misusing the tooltip for something other than what it was intended to be used for. IMHO it may be that you are better off displaying your data with a tree control rather than with a RTB, as the tree control more naturally expresses the functionality that you desire (click on a node, expand it to see details etc).