C#从windows剪贴板获取并显示文本内容的方法

作者:work24 时间:2022-06-03 01:56:47 

本文实例讲述了C#从windows剪贴板获取并显示文本内容的方法。分享给大家供大家参考。具体如下:


using System;
using System.Windows.Forms;
namespace RobvanderWoude
{
class Paste
{
 [STAThread]
 static int Main( string[] args )
 {
  if ( args.Length == 0 )
  {
   try
   {
    if ( Clipboard.ContainsText( ) )
    {
     string clipText = Clipboard.GetText( );
     Console.Write( clipText );
     return 0;
    }
    else
    {
     return 1;
    }
   }
   catch ( Exception e )
   {
    Console.Error.WriteLine( e.Message );
    return 2;
   }
  }
  else
  {
   Console.Error.WriteLine( );
   Console.Error.WriteLine( "Paste.exe, Version 1.01" );
   Console.Error.WriteLine( "Read and display text from the clipboard" );
   Console.Error.WriteLine( );
   Console.Error.WriteLine( "Usage: PASTE" );
   Console.Error.WriteLine( );
   Console.Error.WriteLine( "Note:  The program returns the following 'errorlevels':" );
   Console.Error.WriteLine( " 0 success" );
   Console.Error.WriteLine( " 1 no text available in clipboard" );
   Console.Error.WriteLine( " 2 command line or unknown error" );
   Console.Error.WriteLine( );
   Console.Error.WriteLine( "Written by Rob van der Woude" );
   return 2;
  }
 }
}
}

希望本文所述对大家的C#程序设计有所帮助。

标签:C#,windows,剪贴板
0
投稿

猜你喜欢

  • C# Chart 简单使用教程

    2021-05-29 07:41:34
  • java 发送http和https请求的实例

    2023-11-29 12:46:52
  • 详解C语言求两个数的最大公约数及最小公倍数的方法

    2022-02-28 01:17:25
  • Spring Core动态代理的实现代码

    2021-12-11 03:40:54
  • Java实现非阻塞式服务器的示例代码

    2022-01-29 19:29:11
  • Unity3D运行报DllNotFoundException错误的解决方案

    2021-09-13 00:22:35
  • Android 开发中layout下的子文件夹

    2021-10-03 16:10:44
  • redis redisson 集合的使用案例(RList、Rset、RMap)

    2023-11-13 13:50:21
  • Android实现局部图片滑动指引效果示例

    2022-10-16 03:05:53
  • java并发编程之ThreadLocal详解

    2023-03-15 11:44:33
  • 简单的一次springMVC路由跳转实现

    2023-01-09 10:05:11
  • SpringBoot中的main方法注入service

    2021-10-31 15:33:33
  • IDEA利用自带Axis工具和wsdl文件反向生成服务端客户端代码图文详解

    2021-12-06 20:02:12
  • spring mvc4中相关注解的详细讲解教程

    2021-10-11 23:21:17
  • 图文并茂讲解RocketMQ消息类别

    2023-06-11 07:59:41
  • 使用IDEA异常断点来定位java.lang.ArrayStoreException的问题

    2022-06-14 00:43:18
  • Java 超详细讲解ThreadLocal类的使用

    2021-11-13 05:58:29
  • Java单例模式的几种常见写法

    2023-10-23 18:27:45
  • 解决Spring Cloud feign GET请求无法用实体传参的问题

    2023-11-17 14:14:05
  • Java截取字符串的几种方法示例

    2023-11-29 12:36:32
  • asp之家 软件编程 m.aspxhome.com