當前位置: 首頁>>代碼示例>>C#>>正文


C# TextBox.Copy方法代碼示例

本文整理匯總了C#中System.Windows.Forms.TextBox.Copy方法的典型用法代碼示例。如果您正苦於以下問題:C# TextBox.Copy方法的具體用法?C# TextBox.Copy怎麽用?C# TextBox.Copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Forms.TextBox的用法示例。


在下文中一共展示了TextBox.Copy方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ProcessRecord

        protected override void ProcessRecord()
        {
            var files = Directory.GetFiles(SessionState.Path.CurrentLocation.Path, SearchPattern);

            if (files.Length > 0)
            {
                StringBuilder builder = new StringBuilder();

                foreach (var file in files)
                {
                    builder.AppendLine(file);
                }

                TextBox clipStore = new TextBox();
                clipStore.Text = builder.ToString();
                clipStore.Multiline = true;
                clipStore.SelectAll();
                clipStore.Copy();

                WriteObject(string.Format("({0}) files copied.", files.Length));
            }
            else
            {
                WriteError(new ErrorRecord(new NullReferenceException("No Files to copy"), "0301", ErrorCategory.InvalidArgument, files));
            }
        }
開發者ID:krozen20,項目名稱:redshells,代碼行數:26,代碼來源:WriteClipboardCommand.cs

示例2: copyUrlToolStripMenuItem_Click

 /// <summary>
 /// Copy url
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void copyUrlToolStripMenuItem_Click(object sender, EventArgs e)
 {
     string str = "";
     TextBox tb = new TextBox();
     try
     {
         tb.Text = Target.Text + Tree.SelectedNode.Text;
         tb.SelectAll();
         tb.Copy();
     }
     catch
     {
         //ignored
     }
 }
開發者ID:AlaaBenFatma,項目名稱:SQLic,代碼行數:20,代碼來源:Main.cs

示例3: Main


//.........這裏部分代碼省略.........
                textBoxOutput.Text = "";

                var commonUse = new List<string>();
                commonUse.Add(Encoding.Unicode.WebName);
                commonUse.Add(Encoding.UTF8.WebName);
                commonUse.Add(Encoding.Default.WebName);
                commonUse.Add(Encoding.UTF7.WebName);
                commonUse.Add(Encoding.UTF32.WebName);

                var fullList = Encoding.GetEncodings().Select(i=>i.GetEncoding().WebName);

                comboBox.DataSource = commonUse.Concat(fullList.Except(commonUse)).ToArray();
            };

            radioButtonNumber.Click += (o, e) =>
            {
                textBoxInput.Text = "";
                textBoxOutput.Text = "";

                comboBox.DataSource = new string[] { "unsigned oct", "signed oct", "hex", };
            };

            radioButtonText.PerformClick();

            Func<byte[], string> formatBytes = bytes =>
            {
                if (bytes == null || bytes.Length == 0) return string.Empty;

                var buf = new StringBuilder();
                foreach (byte b in bytes) buf.AppendFormat("{0:x2} ", b);
                buf.Remove(buf.Length - 1, 1);
                return buf.ToString();
            };

            EventHandler intput2output = (o, e) =>
            {
                textBoxOutput.Text = string.Empty;
                if (string.IsNullOrEmpty(textBoxInput.Text)) return;

                if (radioButtonText.Checked)
                {
                    try
                    {
                        Encoding encoding = Encoding.GetEncoding(comboBox.Text);
                        textBoxOutput.Text = formatBytes(encoding.GetBytes(textBoxInput.Text));
                    }
                    catch (Exception _e)
                    {
                        statusLabel.Text = _e.Message.Replace("\r\n", "\t");
                    }
                }
                else
                {
                    try
                    {
                        if (comboBox.Text == "hex")
                        {
                            uint i = uint.Parse(textBoxInput.Text, System.Globalization.NumberStyles.HexNumber);
                            textBoxOutput.Text = formatBytes(ToByteArray(i));
                        }
                        else if (comboBox.Text == "signed oct")
                        {
                            int i = int.Parse(textBoxInput.Text);
                            textBoxOutput.Text = formatBytes(ToByteArray(i));
                        }
                        else if (comboBox.Text == "unsigned oct")
                        {
                            uint i = uint.Parse(textBoxInput.Text);
                            textBoxOutput.Text = formatBytes(ToByteArray(i));
                        }
                        else
                        {
                            statusLabel.Text = "未知的格式。";
                        }
                    }
                    catch (Exception _e)
                    {
                        statusLabel.Text = _e.Message.Replace("\r\n", "\t");
                    }
                }
            };

            textBoxInput.TextChanged += intput2output;
            comboBox.SelectedValueChanged += intput2output;

            textBoxOutput.DoubleClick += (o, e) =>
            {
                if (string.IsNullOrEmpty(textBoxOutput.Text)) return;
                textBoxOutput.SelectAll();
                textBoxOutput.Copy();
                statusLabel.Text = "複製到剪貼板。";
            };

            Timer timerCleanStatus = new Timer();
            timerCleanStatus.Interval = 3000;
            timerCleanStatus.Tick += (o, e) => { statusLabel.Text = ""; };
            timerCleanStatus.Start();

            Application.Run(form);
        }
開發者ID:GHScan,項目名稱:DailyProjects,代碼行數:101,代碼來源:Program.cs


注:本文中的System.Windows.Forms.TextBox.Copy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。