| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1756 人关注过本帖
标题:请教如何将C#中画好的图形使其在"画图剪贴板"中显示?
只看楼主 加入收藏
howard_cjh
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-2-2
收藏
 问题点数:0 回复次数:6 
请教如何将C#中画好的图形使其在"画图剪贴板"中显示?
请教如何将C#中画好的图形使其在"画图剪贴板"中显示?谢谢
搜索更多相关主题的帖子: 画图 图形 中画 剪贴 
2008-02-19 16:50
howard_cjh
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-2-2
收藏
得分:0 
请教如何将C#中画好的图形使其在"画图剪贴板"中显示?
这是我的图形代码;不知道要使其出现在"剪贴板"中要加什么代码?
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 全跳动
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics a = this.CreateGraphics();
            Pen pen1 = new Pen(Color.Black);
            Pen pen2 = new Pen(Color.Black);
            pen1.Width = 2;
            pen2.Width = 2;
            System.Drawing.Drawing2D.AdjustableArrowCap aac;
            aac = new System.Drawing.Drawing2D.AdjustableArrowCap(3, 20);

            pen1.CustomStartCap = aac;
            //pen1.CustomEndCap = aac;

            a.DrawLine(pen1, 68, 20, 34, 80);
            a.DrawLine(pen1, 88, 20, 54, 80);
            a.DrawLine(pen2, 34, 80, 54, 80);

        }
    }
}
帮帮忙啊~~
2008-02-20 11:02
野比
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:24
帖 子:1627
专家分:516
注 册:2007-5-24
收藏
得分:0 
使用 Clipboard 类的 SetXXX 方法,比较简单的是 SetDataObject 方法

女侠,约吗?
2008-02-20 13:05
howard_cjh
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-2-2
收藏
得分:0 
不是很清楚~诶[bc02] ~~关调用这个方法就行了?
2008-02-20 14:05
howard_cjh
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-2-2
收藏
得分:0 
ding
2008-02-21 10:35
野比
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:24
帖 子:1627
专家分:516
注 册:2007-5-24
收藏
得分:0 
MSDN 中有简单实例,你看看吧,很容易看懂的

以下内容摘自 MSDN2005
Clipboard 类提供了可以用来与 Windows 操作系统剪贴板功能交互的方法。许多应用程序都将剪贴板用作一个临时数据储存库。例如,字处理器在剪切和粘贴操作期间使用剪贴板。剪贴板还可用于从一个应用程序向另一个应用程序传输数据。

向剪贴板添加数据时,可以指示数据格式,以便在其他应用程序能够使用该格式时可以识别该数据。还可以按多种不同的格式将数据添加到剪贴板,这样增加了有可能使用该数据的其他应用程序的数量。

剪贴板格式是一个字符串,用于标识格式,以便使用该格式的应用程序可以检索关联的数据。DataFormats 类提供了预定义的格式名称以方便您使用。您也可以使用您自己的格式名称,或将对象的类型用作其格式名称。

若要以一种或多种格式将数据添加到剪贴板,请使用 SetDataObject 方法。可以将任意对象传递给此方法,但若要以多种格式添加数据,必须首先将数据添加到一个专门用于多种格式的单独对象中。通常,应当将数据添加到 DataObject 中,但可以使用任何实现了 IDataObject 接口的类型。

在 Microsoft .NET Framework 2.0 版 中,可以使用为使基本的剪贴板任务更容易执行而设计的新方法,将数据直接添加到剪贴板中。以单一的常用格式(如文本)处理数据时,可以使用这些方法。

注意
所有基于 Windows 的应用程序都共享剪贴板。因此,当您切换到另一个应用程序时,其内容也会发生更改。

Clipboard 类只能在设置为单线程单元 (STA) 模式的线程中使用。若要使用此类,请确保您的 Main 方法已用 STAThreadAttribute 属性标记。

对象必须是可序列化的,才能将它放在剪贴板上。若要使类型可序列化,请用 SerializableAttribute 属性标记它。如果将非可序列化对象传递给剪贴板方法,则该方法将失败,而且不会引发异常。有关序列化的更多信息,请参见序列化。
 

将数据以单一常用格式添加到剪贴板上
使用 SetAudio、SetFileDropList、SetImage 或 SetText 方法。这些方法只在 Microsoft .NET Framework 2.0 版 中可用。

Visual Basic  复制代码
' Demonstrates SetAudio, ContainsAudio, and GetAudioStream.
Public Function SwapClipboardAudio( _
    ByVal replacementAudioStream As ) _
    As

    Dim returnAudioStream As = Nothing

    If (Clipboard.ContainsAudio()) Then
        returnAudioStream = Clipboard.GetAudioStream()
        Clipboard.SetAudio(replacementAudioStream)
    End If

    Return returnAudioStream

End Function

' Demonstrates SetFileDropList, ContainsFileDroList, and GetFileDropList
Public Function SwapClipboardFileDropList(ByVal replacementList _
    As System.Collections.Specialized.StringCollection) _
    As System.Collections.Specialized.StringCollection

    Dim returnList As System.Collections.Specialized.StringCollection _
        = Nothing

    If Clipboard.ContainsFileDropList() Then

        returnList = Clipboard.GetFileDropList()
        Clipboard.SetFileDropList(replacementList)
    End If

    Return returnList

End Function

' Demonstrates SetImage, ContainsImage, and GetImage.
Public Function SwapClipboardImage( _
    ByVal replacementImage As System.Drawing.Image) _
    As System.Drawing.Image

    Dim returnImage As System.Drawing.Image = Nothing

    If Clipboard.ContainsImage() Then
        returnImage = Clipboard.GetImage()
        Clipboard.SetImage(replacementImage)
    End If

    Return returnImage
End Function

' Demonstrates SetText, ContainsText, and GetText.
Public Function SwapClipboardHtmlText( _
    ByVal replacementHtmlText As String) As String

    Dim returnHtmlText As String = Nothing

    If (Clipboard.ContainsText(TextDataFormat.Html)) Then
        returnHtmlText = Clipboard.GetText(TextDataFormat.Html)
        Clipboard.SetText(replacementHtmlText, TextDataFormat.Html)
    End If

    Return returnHtmlText

End Function

 
C#  复制代码
// Demonstrates SetAudio, ContainsAudio, and GetAudioStream.
public SwapClipboardAudio(
    replacementAudioStream)
{
    returnAudioStream = null;
    if (Clipboard.ContainsAudio())
    {
        returnAudioStream = Clipboard.GetAudioStream();
        Clipboard.SetAudio(replacementAudioStream);
    }
    return returnAudioStream;
}

// Demonstrates SetFileDropList, ContainsFileDroList, and GetFileDropList
public System.Collections.Specialized.StringCollection
    SwapClipboardFileDropList(
    System.Collections.Specialized.StringCollection replacementList)
{
    System.Collections.Specialized.StringCollection returnList = null;
    if (Clipboard.ContainsFileDropList())
    {
        returnList = Clipboard.GetFileDropList();
        Clipboard.SetFileDropList(replacementList);
    }
    return returnList;
}

// Demonstrates SetImage, ContainsImage, and GetImage.
public System.Drawing.Image SwapClipboardImage(
    System.Drawing.Image replacementImage)
{
    System.Drawing.Image returnImage = null;
    if (Clipboard.ContainsImage())
    {
        returnImage = Clipboard.GetImage();
        Clipboard.SetImage(replacementImage);
    }
    return returnImage;
}

// Demonstrates SetText, ContainsText, and GetText.
public String SwapClipboardHtmlText(String replacementHtmlText)
{
    String returnHtmlText = null;
    if (Clipboard.ContainsText(TextDataFormat.Html))
    {
        returnHtmlText = Clipboard.GetText(TextDataFormat.Html);
        Clipboard.SetText(replacementHtmlText, TextDataFormat.Html);
    }
    return returnHtmlText;
}

 


将数据以自定义格式添加到剪贴板中
使用具有自定义格式名称的 SetData 方法。此方法只在 Microsoft .NET Framework 2.0 版 中可用。

您还可以在使用 SetData 方法时使用预定义的格式名称。有关更多信息,请参见 DataFormats。

Visual Basic  复制代码
    ' Demonstrates SetData, ContainsData, and GetData
    ' using a custom format name and a business object.
    Public ReadOnly Property TestCustomFormat() As Customer
        Get
            Clipboard.SetData("CustomerFormat", New Customer("Customer Name"))

            If Clipboard.ContainsData("CustomerFormat") Then
                Return CType(Clipboard.GetData("CustomerFormat"), Customer)
            End If

            Return Nothing
        End Get
    End Property
...    <Serializable()> Public Class Customer

        Private nameValue As String = String.Empty

        Public Sub New(ByVal name As String)
            nameValue = name
        End Sub

        Public Property Name() As String
            Get
                Return nameValue
            End Get
            Set(ByVal value As String)
                nameValue = value
            End Set
        End Property

    End Class

 
C#  复制代码
    // Demonstrates SetData, ContainsData, and GetData
    // using a custom format name and a business object.
    public Customer TestCustomFormat
    {
        get
        {
            Clipboard.SetData("CustomerFormat", new Customer("Customer Name"));
            if (Clipboard.ContainsData("CustomerFormat"))
            {
                return Clipboard.GetData("CustomerFormat") as Customer;
            }
            return null;
        }
    }
...    [Serializable]
    public class Customer
    {
        private string nameValue = string.Empty;
        public Customer(String name)
        {
            nameValue = name;
        }
        public string Name
        {
            get { return nameValue; }
            set { nameValue = value; }
        }
    }

 


将数据以多种格式添加到剪贴板上
使用 SetDataObject 方法,并传入包含数据的 DataObject。在 .NET Framework 2.0 的早期版本中,必须使用此方法才能向剪贴板添加数据。

Visual Basic  复制代码
    ' Demonstrates how to use a DataObject to add
    ' data to the Clipboard in multiple formats.
    Public Sub TestClipboardMultipleFormats()

        Dim data As New DataObject()

        ' Add a Customer object using the type as the format.
        data.SetData(New Customer("Customer as Customer object"))

        ' Add a ListViewItem object using a custom format name.
        data.SetData("CustomFormat", _
            New ListViewItem("Customer as ListViewItem"))

        Clipboard.SetDataObject(data)
        Dim retrievedData As DataObject = _
            CType(Clipboard.GetDataObject(), DataObject)

        If (retrievedData.GetDataPresent("CustomFormat")) Then

            Dim item As ListViewItem = _
                TryCast(retrievedData.GetData("CustomFormat"), ListViewItem)

            If item IsNot Nothing Then
                MessageBox.Show(item.Text)
            End If

        End If

        If retrievedData.GetDataPresent(GetType(Customer)) Then

            Dim customer As Customer = _
                CType(retrievedData.GetData(GetType(Customer)), Customer)

            If customer IsNot Nothing Then

                MessageBox.Show(customer.Name)
            End If

        End If

    End Sub
...    <Serializable()> Public Class Customer

        Private nameValue As String = String.Empty

        Public Sub New(ByVal name As String)
            nameValue = name
        End Sub

        Public Property Name() As String
            Get
                Return nameValue
            End Get
            Set(ByVal value As String)
                nameValue = value
            End Set
        End Property

    End Class

 
C#  复制代码
    // Demonstrates how to use a DataObject to add
    // data to the Clipboard in multiple formats.
    public void TestClipboardMultipleFormats()
    {
        DataObject data = new DataObject();

        // Add a Customer object using the type as the format.
        data.SetData(new Customer("Customer as Customer object"));

        // Add a ListViewItem object using a custom format name.
        data.SetData("CustomFormat",
            new ListViewItem("Customer as ListViewItem"));

        Clipboard.SetDataObject(data);
        DataObject retrievedData = (DataObject)Clipboard.GetDataObject();

        if (retrievedData.GetDataPresent("CustomFormat"))
        {
            ListViewItem item =
                retrievedData.GetData("CustomFormat") as ListViewItem;
            if (item != null)
            {
                MessageBox.Show(item.Text);
            }
        }

        if (retrievedData.GetDataPresent(typeof(Customer)))
        {
            Customer customer =
                retrievedData.GetData(typeof(Customer)) as Customer;
            if (customer != null)
            {
                MessageBox.Show(customer.Name);
            }
        }
    }
...    [Serializable]
    public class Customer
    {
        private string nameValue = string.Empty;
        public Customer(String name)
        {
            nameValue = name;
        }
        public string Name
        {
            get { return nameValue; }
            set { nameValue = value; }
        }
    }

 

女侠,约吗?
2008-02-21 22:25
howard_cjh
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-2-2
收藏
得分:0 
万分感激LS
2008-02-22 09:37
快速回复:请教如何将C#中画好的图形使其在"画图剪贴板"中显示?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014516 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved