前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
/****************************************/
/*★ クリップボードの基礎 前田 稔 ★*/
/****************************************/
using System;
using System.Drawing;
using System.Windows.Forms;
public class MyForm : Form
{
int cnt = 0;
public MyForm()
{
Paint += new PaintEventHandler(MyHandler);
MouseDown += new MouseEventHandler(OnMyMouseDown);
}
private void MyHandler(object sender, PaintEventArgs e)
{
if (Clipboard.ContainsText())
{
Graphics g = e.Graphics;
Font f = new Font("MS 明朝", 24);
g.DrawString(Clipboard.GetText(), f, Brushes.Red, new PointF(10F, 50F));
}
}
private void OnMyMouseDown(object sender, MouseEventArgs e)
{
cnt++;
//アプリケーション終了後、クリップボードからデータは削除される
Clipboard.SetDataObject("カウント=" + cnt.ToString());
Invalidate();
}
}
class form01
{
[STAThread]
public static void Main()
{
MyForm mf = new MyForm();
Application.Run(mf);
}
}
|
cnt++;
//アプリケーション終了後、クリップボードからデータは削除される
Clipboard.SetDataObject("カウント=" + cnt.ToString());
|
Clipboard.SetDataObject("カウント=" + cnt.ToString(), true);
|
if (Clipboard.ContainsText())
{
Graphics g = e.Graphics;
Font f = new Font("MS 明朝", 24);
g.DrawString(Clipboard.GetText(), f, Brushes.Red, new PointF(10F, 50F));
}
|
![]()
/************************************************/
/*★ クリップボードの文字列を取得 前田 稔 ★*/
/************************************************/
using System;
using System.Windows.Forms;
class ClipbordClass
{
[STAThread]
public static int Main()
{
//クリップボードに文字列データがあるか確認
if (Clipboard.ContainsText())
{
//文字列データがあるときはこれを取得する
//取得できないときは空の文字列(String.Empty)を返す
Console.WriteLine(Clipboard.GetText());
}
return 0;
}
}
|
![]()
/***********************************************************/
/*★ クリップボードの形式は IDataObject です 前田 稔 ★*/
/***********************************************************/
using System;
using System.Windows.Forms;
class ClipbordClass
{
[STAThread]
public static int Main()
{
//クリップボードを取得
IDataObject data = Clipboard.GetDataObject() ;
//文字列のとき、印字する
if (data.GetDataPresent(DataFormats.Text))
{
Console.WriteLine((string)data.GetData(DataFormats.Text));
}
return 0;
}
}
|
![]()