forked from ahyahy/OneScriptForms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClipboard.cs
More file actions
125 lines (113 loc) · 4 KB
/
Clipboard.cs
File metadata and controls
125 lines (113 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using ScriptEngine.Machine.Contexts;
using System.Windows.Forms;
using System.Threading;
namespace osf
{
[ContextClass ("КлБуферОбмена", "ClClipboard")]
public class ClClipboard : AutoContext<ClClipboard>
{
[ContextMethod("Очистить", "Clear")]
public void Clear()
{
var thread = new Thread(() => Clipboard.Clear());
thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
[ContextMethod("ПолучитьИзображение", "GetImage")]
public ClBitmap GetImage()
{
ClBitmap ClBitmap1 = null;
var thread = new Thread(() =>
{
if (Clipboard.ContainsImage())
{
Bitmap Bitmap1 = new Bitmap((System.Drawing.Image)Clipboard.GetImage());
ClBitmap1 = new ClBitmap(Bitmap1);
}
}
);
thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
return ClBitmap1;
}
[ContextMethod("ПолучитьТекст", "GetText")]
public string GetText()
{
string str1 = null;
var thread = new Thread(() =>
{
IDataObject dataObject = Clipboard.GetDataObject();
if (dataObject.GetDataPresent(DataFormats.UnicodeText))
{
str1 = (String)dataObject.GetData(DataFormats.UnicodeText);
}
}
);
thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
return str1;
}
[ContextMethod("СодержитДанные", "ContainsData")]
public bool ContainsData()
{
bool res = false;
var thread = new Thread(() =>
{
IDataObject dataObject = Clipboard.GetDataObject();
if (dataObject != null)
{
res = true;
}
}
);
thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
return res;
}
[ContextMethod("СодержитЮникод", "ContainsUnicode")]
public bool ContainsUnicode()
{
bool res = false;
var thread = new Thread(() =>
{
res = Clipboard.ContainsText(TextDataFormat.UnicodeText);
}
);
thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
return res;
}
[ContextMethod("УстановитьИзображение", "SetImage")]
public void SetImage(ClBitmap bitmap)
{
var data = new DataObject();
data.SetData(DataFormats.Bitmap, true, ((System.Drawing.Image)(bitmap.Base_obj.M_Image)));
var thread = new Thread(() => Clipboard.SetDataObject(data, true));
thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
}
[ContextMethod("УстановитьТекст", "SetText")]
public void SetText(string text)
{
var data = new DataObject();
data.SetData(DataFormats.UnicodeText, true, text);
var thread = new Thread(() => Clipboard.SetDataObject(data, true));
thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
}
}
}