当前位置: 首页>>代码示例>>C#>>正文


C# DataFormats.Text字段代码示例

本文整理汇总了C#中System.Windows.Forms.DataFormats.Text字段的典型用法代码示例。如果您正苦于以下问题:C# DataFormats.Text字段的具体用法?C# DataFormats.Text怎么用?C# DataFormats.Text使用的例子?那么, 这里精选的字段代码示例或许可以为您提供帮助。您也可以进一步了解该字段所在System.Windows.Forms.DataFormats的用法示例。


在下文中一共展示了DataFormats.Text字段的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: if

try
  {

      String myString = "This is a String from the ClipBoard";

      // Sets the data into the Clipboard.
      Clipboard.SetDataObject(myString);
      IDataObject myDataObject = Clipboard.GetDataObject();
      // Checks whether the format of the data is 'UnicodeText' or not.
      if(myDataObject.GetDataPresent(DataFormats.UnicodeText)) 
      {
          Console.WriteLine("Data in 'UnicodeText' format:"+myDataObject.GetData(DataFormats.UnicodeText));
      } 
      else 
      {
          Console.WriteLine("No String information was contained in the clipboard.");
      }

      // Checks whether the format of the data is 'Text' or not.
      if(myDataObject.GetDataPresent(DataFormats.Text)) 
      {
          String clipString = (String)myDataObject.GetData(DataFormats.StringFormat);
          Console.WriteLine("Data in 'Text' format:"+clipString);
      }
  }
  catch(Exception e)
  {
      Console.WriteLine(e.Message);
  }
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:29,代码来源:DataFormats.Text

示例2: TextBoxDragDropDemo

//引入命名空间
using System;
using System.Windows.Forms;

public class TextBoxDragDropDemo : Form
{
    public TextBoxDragDropDemo()
    {
        InitializeComponent();
    }

    private void TextBox_MouseDown(object sender, MouseEventArgs e)
    {
        TextBox txt = (TextBox)sender;
        txt.SelectAll();
        txt.DoDragDrop(txt.Text, DragDropEffects.Copy);
    }

    private void TextBox_DragEnter(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.Text))
        {
            e.Effect = DragDropEffects.Copy;
        }
        else
        {
            e.Effect = DragDropEffects.None;
        }
    }

    private void TextBox_DragDrop(object sender, DragEventArgs e)
    {
        TextBox txt = (TextBox)sender;
        txt.Text = (string)e.Data.GetData(DataFormats.Text);
    }

    [STAThread]
    public static void Main(string[] args)
    {
        Application.Run(new TextBoxDragDropDemo());
    }
    private System.Windows.Forms.TextBox TextBox2;
    private System.Windows.Forms.TextBox TextBox1;

    private void InitializeComponent()
    {
        this.TextBox2 = new System.Windows.Forms.TextBox();
        this.TextBox1 = new System.Windows.Forms.TextBox();
        this.SuspendLayout();

        this.TextBox2.AllowDrop = true;
        this.TextBox2.Location = new System.Drawing.Point(28, 129);
        this.TextBox2.Multiline = true;
        this.TextBox2.Size = new System.Drawing.Size(196, 77);
        this.TextBox2.DragDrop += new System.Windows.Forms.DragEventHandler(this.TextBox_DragDrop);
        this.TextBox2.DragEnter += new System.Windows.Forms.DragEventHandler(this.TextBox_DragEnter);
        this.TextBox2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.TextBox_MouseDown);

        this.TextBox1.AllowDrop = true;
        this.TextBox1.Location = new System.Drawing.Point(28, 36);
        this.TextBox1.Multiline = true;
        this.TextBox1.Size = new System.Drawing.Size(196, 77);
        this.TextBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.TextBox_DragDrop);
        this.TextBox1.DragEnter += new System.Windows.Forms.DragEventHandler(this.TextBox_DragEnter);
        this.TextBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.TextBox_MouseDown);

        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(292, 266);
        this.Controls.Add(this.TextBox2);
        this.Controls.Add(this.TextBox1);
        this.ResumeLayout(false);
        this.PerformLayout();

    }
}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:76,代码来源:DataFormats.Text


注:本文中的System.Windows.Forms.DataFormats.Text字段示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。