I am making a program in c sharp/xaml. I have a save button, and figured the easiest way to make it effective was when pressed if I could send the "control s" signal. What is the command (and any includes VS wouldn't add as standard) to do so?
A completely different question to cut down on thread count, how would I make a textblock (or textbox if easier) automatically n开发者_C百科ewline when you reach the end rather than continuing to send text offscreen.
There are better patterns that I would suggest looking into before coupling your UI to keypresses (such as Commands) but if you really want to do this, you can use the SendKeys class from windows forms. This will allow you to send key presses to the application as if the user pressed those keys.
As for the second question, if you're using WPF just create a textbox element and set AcceptsReturn="True"
and TextWrapping="Wrap"
. Here's an example:
<TextBox
Name="tbMultiLine"
TextWrapping="Wrap"
AcceptsReturn="True"
VerticalScrollBarVisibility="Visible"
>
This TextBox will allow the user to enter multiple lines of text. When the RETURN key is pressed,
or when typed text reaches the edge of the text box, a new line is automatically inserted.
</TextBox>
You can use the SaveFileDialog() .
private void button1_Click(object sender, EventArgs e)
{
// When user clicks button, show the dialog.
saveFileDialog1.ShowDialog();
}
private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
{
// Get file name.
string name = saveFileDialog1.FileName;
// Write to the file name selected.
// ... You can write the text from a TextBox instead of a string literal.
File.WriteAllText(name, "test");
}
If you're using XAML I'll assume you're using WPF. So you should be able to bind the Command
property of the Button to ApplicationCommands.Save
.
精彩评论