
前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
/******************************************************/
/*★ クリップボードに文字列と画像を格納 前田 稔 ★*/
/******************************************************/
using System;
using System.Drawing;
using System.Drawing.Text;
using System.Windows.Forms;
public class SetClipboard
{
[STAThread]
public static int Main()
{
DataObject data = new DataObject();
string text = "こんにちは C#";
data.SetData(text);
Bitmap bmp = new Bitmap(320, 100);
Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(new SolidBrush(Color.DarkGreen), 0, 0, 200, 60);
g.DrawString(text, new Font("Times New Roman", 20), new SolidBrush(Color.Gold), 20, 10);
data.SetData(bmp);
Clipboard.SetDataObject(data, true);
return 0;
}
}
|
![]()
/************************************************************/
/*★ クリップボードの Text と Image を表示する 前田 稔 ★*/
/************************************************************/
using System;
using System.Drawing;
using System.Windows.Forms;
public class MyForm : Form
{
private TextBox textBox1;
private PictureBox pictureBox1;
private Button button1;
public MyForm()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
// button1
this.button1.Location = new System.Drawing.Point(3, 3);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(100, 22);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
// textBox1
this.textBox1.Location = new System.Drawing.Point(3, 31);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(200, 25);
this.textBox1.TabIndex = 1;
// pictureBox1
this.pictureBox1.Location = new System.Drawing.Point(3, 62);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(200, 60);
this.pictureBox1.TabIndex = 2;
this.pictureBox1.TabStop = false;
// MyForm
this.ClientSize = new System.Drawing.Size(220, 140);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "MyForm";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "";
pictureBox1.Image = null;
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(DataFormats.Text))
{ textBox1.Text = (string)data.GetData(DataFormats.Text);
}
if (data.GetDataPresent(DataFormats.Bitmap))
{ pictureBox1.Image = (Image)data.GetData(DataFormats.Bitmap);
}
}
}
class form01
{
[STAThread]
public static void Main()
{
MyForm mf = new MyForm();
Application.Run(mf);
}
}
|
![]()