Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 2 của 2
  1. #1
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    Lấy text từ ứng dụng khác ( kéo thả và clipboard) trong lập trình C#

    Cái này mình làm có thể lấy text bằng cách bôi đen nhấn Ctrl+C hoặc kéo thả , code cực ngắn và không đòi hỏi kiến thức api hook gì hết (đương nhiên chức năng bị hạn chế), nhưng bạn nào không có yêu cầu quá cao như mtd hay babylon, stardict thì dùng cũng được:
    Cho cái timer là 200(nhỏ hơn cảng tốt) và gán enable = true nhé.


    Mã:
    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices; namespace Lab{    public partial class Form1 : Form    {        String s;        public Form1()        {            InitializeComponent();        }         private void Form1_Load(object sender, EventArgs e)        {            if (Clipboard.ContainsText(TextDataFormat.UnicodeText))                s = Clipboard.GetText(TextDataFormat.UnicodeText);        }         private void timer1_Tick(object sender, EventArgs e)        {            if (Clipboard.ContainsText(TextDataFormat.UnicodeText) && s != Clipboard.GetText())                textBox1.Text = s = Clipboard.GetText(TextDataFormat.UnicodeText);        }         private void textBox1_DragEnter(object sender, DragEventArgs e)        {            if (e.Data.GetDataPresent(DataFormats.UnicodeText))                e.Effect=DragDropEffects.Copy;            else                 e.Effect =DragDropEffects.None;        }         private void textBox1_DragDrop(object sender, DragEventArgs e)        {            textBox1.Text = e.Data.GetData(DataFormats.UnicodeText).ToString();            Clipboard.SetText(s, TextDataFormat.UnicodeText);            //dòng này cần thiết, nếu bạn dùng office 2003 hỗ trợ nhiều clipboard, mà dùng chung 2 tính năng lẫn nhau thì sẽ bị lỗi đó        }         private void checkBox1_CheckedChanged(object sender, EventArgs e)        {            timer1.Enabled = !timer1.Enabled;        }    }}

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    e xin phép đào mộ một tí!
    thanks anh vì bài này rất hay[IMG]images/smilies/biggrin.png[/IMG]

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •