本文整理汇总了C#中System.Windows.Forms.TextBox.Paste方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.Paste方法的具体用法?C# TextBox.Paste怎么用?C# TextBox.Paste使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.TextBox
的用法示例。
在下文中一共展示了TextBox.Paste方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRecord
protected override void ProcessRecord()
{
TextBox clipStore = new TextBox();
clipStore.Multiline = true;
clipStore.Paste();
var files = clipStore.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
foreach (var file in files)
{
WriteObject(string.Format("Copying {0}", file));
File.Copy(file, Path.Combine(SessionState.Path.CurrentLocation.Path, Path.GetFileName(file)), true);
}
}
示例2: OnKeyPress
public void OnKeyPress(object sender, KeyPressEventArgs e)
{
string hexChars = "0123456789ABCDEF";
if (textBoxString1.ContainsFocus | textBoxString2.ContainsFocus
| textBoxString3.ContainsFocus |textBoxString4.ContainsFocus)
{ // ignore typing in textboxes
return;
}
// check for copy/cut
if ((e.KeyChar == 3) || (e.KeyChar == 24))
{
textBoxDisplay.Copy();
return;
}
if (radioButtonDisconnect.Checked)
{ // don't do anything else if not connected
return;
}
textBoxDisplay.Focus();
if (radioButtonHex.Checked)
{ // hex mode
string charTyped = e.KeyChar.ToString(); // get typed char
charTyped = charTyped.ToUpper();
if (charTyped.IndexOfAny(hexChars.ToCharArray()) == 0)
{ // valid Hex character
if (labelTypeHex.Visible)
{ // first nibble already typed - send byte
string dataString = labelTypeHex.Text.Substring(11,1) + charTyped;
labelTypeHex.Text = "Type Hex : ";
labelTypeHex.Visible = false;
byte[] hexByte = new byte[1];
hexByte[0] = (byte)Utilities.Convert_Value_To_Int("0x" + dataString);
dataString = "TX: " + dataString + "\r\n";
textBoxDisplay.AppendText(dataString);
textBoxDisplay.SelectionStart = textBoxDisplay.Text.Length;
textBoxDisplay.ScrollToCaret();
if (logFile != null)
{
logFile.Write(dataString);
}
Pk2.DataDownload(hexByte, 0, hexByte.Length);
}
else
{ // show first nibble
labelTypeHex.Text = "Type Hex : " + charTyped + "_";
labelTypeHex.Visible = true;
}
}
else
{ // other char - clear typed hex
labelTypeHex.Text = "Type Hex : ";
labelTypeHex.Visible = false;
}
}
else
{ // ASCII mode
// check for paste
if (e.KeyChar == 22)
{
textBoxDisplay.SelectionStart = textBoxDisplay.Text.Length; //cursor at end
TextBox tempBox = new TextBox();
tempBox.Multiline = true;
tempBox.Paste();
do
{
int pasteLength = tempBox.Text.Length;
if (pasteLength > 60)
{
pasteLength = 60;
}
sendString(tempBox.Text.Substring(0, pasteLength), false);
tempBox.Text = tempBox.Text.Substring(pasteLength);
// wait according to the baud rate so we don't overflow the download buffer
float baud = float.Parse((comboBoxBaud.SelectedItem.ToString()));
baud = (1F / baud) * 12F * (float)pasteLength; // to ensure we don't overflow, give each byte 12 bits
baud *= 1000F; // baud is now in ms.
Thread.Sleep((int)baud);
} while (tempBox.Text.Length > 0);
tempBox.Dispose();
return;
}
string charTyped = e.KeyChar.ToString();
if (charTyped == "\r")
{
charTyped = "\r\n";
}
sendString(charTyped, false);
}
}
示例3: ModifiedTest
public void ModifiedTest ()
{
TextBox t = new TextBox ();
Assert.AreEqual (false, t.Modified, "modified-1");
t.Modified = true;
Assert.AreEqual (true, t.Modified, "modified-2");
t.Modified = false;
Assert.AreEqual (false, t.Modified, "modified-3");
// Changes in Text property don't change Modified,
// as opposed what the .net docs say
t.ModifiedChanged += new EventHandler (TextBox_ModifiedChanged);
modified_changed_fired = false;
t.Text = "TEXT";
Assert.AreEqual (false, t.Modified, "modified-4");
Assert.AreEqual (false, modified_changed_fired, "modified-4-1");
t.Modified = true;
modified_changed_fired = false;
t.Text = "hello";
Assert.AreEqual (true, t.Modified, "modified-5");
Assert.AreEqual (false, modified_changed_fired, "modified-5-1");
t.Modified = false;
modified_changed_fired = false;
t.Text = "hello mono";
Assert.AreEqual (false, t.Modified, "modified-6");
Assert.AreEqual (false, modified_changed_fired, "modified-6-1");
// The methods changing the text value, however,
// do change Modified
t.Modified = true;
modified_changed_fired = false;
t.AppendText ("a");
Assert.AreEqual (false, t.Modified, "modified-7");
Assert.AreEqual (true, modified_changed_fired, "modified-7-1");
t.Modified = true;
modified_changed_fired = false;
t.Clear ();
Assert.AreEqual (false, t.Modified, "modified-8");
Assert.AreEqual (true, modified_changed_fired, "modified-8-1");
t.Text = "a message";
t.SelectAll ();
t.Modified = false;
t.Cut ();
Assert.AreEqual (true, t.Modified, "modified-9");
t.Modified = false;
t.Paste ();
Assert.AreEqual (true, t.Modified, "modified-10");
t.Modified = false;
t.Undo ();
Assert.AreEqual (true, t.Modified, "modified-11");
}
示例4: ApplyControlBackspace
public static void ApplyControlBackspace(TextBox textBox)
{
if (textBox.SelectionLength == 0)
{
var text = textBox.Text;
var deleteUpTo = textBox.SelectionStart;
if (deleteUpTo > 0 && deleteUpTo <= text.Length)
{
text = text.Substring(0, deleteUpTo);
var textElementIndices = StringInfo.ParseCombiningCharacters(text);
var index = textElementIndices.Length;
var textIndex = deleteUpTo;
var deleteFrom = -1;
while (index > 0)
{
index--;
textIndex = textElementIndices[index];
if (!IsSpaceCategory(CharUnicodeInfo.GetUnicodeCategory(text, textIndex)))
break;
}
if (index > 0) // HTML tag?
{
if (text[textIndex] == '>')
{
var openingBracketIndex = text.LastIndexOf('<', textIndex - 1);
if (openingBracketIndex >= 0 && text.IndexOf('>', openingBracketIndex + 1) == textIndex)
deleteFrom = openingBracketIndex; // delete whole tag
}
else if (text[textIndex] == '}')
{
var startIdx = text.LastIndexOf(@"{\", textIndex - 1, StringComparison.Ordinal);
if (startIdx >= 0 && text.IndexOf('}', startIdx + 1) == textIndex)
{
deleteFrom = startIdx;
}
}
}
if (deleteFrom < 0)
{
if (BreakChars.Contains(text[textIndex]))
deleteFrom = -2;
while (index > 0)
{
index--;
textIndex = textElementIndices[index];
if (IsSpaceCategory(CharUnicodeInfo.GetUnicodeCategory(text, textIndex)))
{
if (deleteFrom > -2)
{
if (deleteFrom < 0)
deleteFrom = textElementIndices[index + 1];
break;
}
deleteFrom = textElementIndices[index + 1];
if (!":!?".Contains(text[deleteFrom]))
break;
}
else if (BreakChars.Contains(text[textIndex]))
{
if (deleteFrom > -2)
{
if (deleteFrom < 0)
deleteFrom = textElementIndices[index + 1];
break;
}
}
else
{
deleteFrom = -1;
}
}
}
if (deleteFrom < deleteUpTo)
{
if (deleteFrom < 0)
deleteFrom = 0;
textBox.Select(deleteFrom, deleteUpTo - deleteFrom);
textBox.Paste(string.Empty);
}
}
}
}
示例5: AdjustToUpperInvariant
private void AdjustToUpperInvariant(TextBox tb)
{
try
{
fInTextChanged = true;
//Adjusting needs to position the cursor at the end of the text. Therefore
//Paste() is a way to do this.
String tmp = tb.Text.Trim().ToUpperInvariant();
tb.Clear();
tb.Paste(tmp);
}
finally
{
fInTextChanged = false;
}
}
示例6: PasteString
private void PasteString(TextBox oTB, string sText)
{
StringBuilder oBuffer = new StringBuilder(sText);
if (sText == Environment.NewLine)
{
int iSelStart = oTB.SelectionStart;
int iLigne = oTB.GetLineFromCharIndex(iSelStart);
if (oTB.Lines.Length > iLigne)
{
string sLigne = oTB.Lines[iLigne];
foreach (char c in sLigne)
{
if (c == ' ' || c == '\t')
{
oBuffer.Append(c);
}
else
{
break;
}
}
}
}
oTB.Paste(oBuffer.ToString());
}