<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Форум компьютерной помощи &mdash; Средства обмена данными между приложениями]]></title>
	<link rel="self" href="https://itpmr.ru/extern.php?action=feed&amp;tid=752&amp;type=atom" />
	<updated>2012-12-24T11:48:48Z</updated>
	<generator>PunBB</generator>
	<id>https://itpmr.ru/viewtopic.php?id=752</id>
		<entry>
			<title type="html"><![CDATA[Средства обмена данными между приложениями]]></title>
			<link rel="alternate" href="https://itpmr.ru/viewtopic.php?pid=123795#p123795" />
			<content type="html"><![CDATA[<p>Задание: написать приложение, выполняющее занесение текста и картинки в буфер обмена, а также получающее эти данные из буфера обмена.<br />Код программы:<br />using System;<br />using System.Collections.Generic;<br />using System.ComponentModel;<br />using System.Data;<br />using System.Drawing;<br />using System.Linq;<br />using System.Text;<br />using System.Windows.Forms;</p><p>namespace Laba5TVP<br />{<br />&nbsp; &nbsp; public partial class Form1 : Form<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; OpenFileDialog ofd = new OpenFileDialog();<br />&nbsp; &nbsp; &nbsp; &nbsp; public Form1()<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InitializeComponent();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CenterToScreen();<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private void button2_Click(object sender, EventArgs e)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Clipboard.SetText(textBox1.Text); // заносим в буфер обмена введенный текст<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private void button1_Click(object sender, EventArgs e)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ofd.Filter = &quot;Картинки (*.jpg)(*.png)|*.jpg&quot;;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ofd.ShowDialog();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (ofd.FileName != &quot;&quot;)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Bitmap image = new Bitmap(ofd.FileName);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pictureBox1.Image = image;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private void button3_Click(object sender, EventArgs e)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IDataObject iData = Clipboard.GetDataObject();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (iData.GetDataPresent(DataFormats.Text))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label2.Text = (String)iData.GetData(DataFormats.Text);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; catch (Exception ex) <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox.Show(ex.ToString()); <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private void button4_Click(object sender, EventArgs e)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Bitmap))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pictureBox2.Image = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private void button5_Click(object sender, EventArgs e)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Clipboard.SetDataObject(pictureBox1.Image, true); // заносим в буфер обмена выбранную картинку<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }<br />}</p>]]></content>
			<author>
				<name><![CDATA[admin]]></name>
				<uri>https://itpmr.ru/profile.php?id=2</uri>
			</author>
			<updated>2012-12-24T11:48:48Z</updated>
			<id>https://itpmr.ru/viewtopic.php?pid=123795#p123795</id>
		</entry>
</feed>
