クリップボードにデータを設定する

ClipboardクラスのSet~関数群を利用します。
下の例はFormにTextBoxとButtonを貼り付けて
Buttonが押されたらTextBoxのテキストをクリップボードに設定しています。


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // TextBoxのテキストをクリップボードに設定します。いずれの方法でもOK
            Clipboard.SetText(textBox1.Text);
            Clipboard.SetData(DataFormats.Text, textBox1.Text);
            Clipboard.SetDataObject(textBox1.Text);
        }
    }
}

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)