hytos / ID2.Manager / ID2.Manager / Controls / BriefAndImages.cs @ 70ed289d
이력 | 보기 | 이력해설 | 다운로드 (8.76 KB)
1 |
using ID2.Manager.Data.Models; |
---|---|
2 |
using System; |
3 |
using System.Collections.Generic; |
4 |
using System.ComponentModel; |
5 |
using System.Data; |
6 |
using System.Drawing; |
7 |
using System.IO; |
8 |
using System.Linq; |
9 |
using System.Text; |
10 |
using System.Threading.Tasks; |
11 |
using System.Windows.Forms; |
12 |
using Telerik.WinControls; |
13 |
using Telerik.WinControls.UI; |
14 |
|
15 |
namespace ID2.Manager.Controls |
16 |
{ |
17 |
|
18 |
public partial class BriefAndImages : UserControl |
19 |
{ |
20 |
const int TextMinHeight = 30; |
21 |
public event EventHandler<AttImageInfo> RemoveImage; |
22 |
|
23 |
public BriefAndImages() |
24 |
{ |
25 |
InitializeComponent(); |
26 |
|
27 |
txtBriefDoftech.DataBindings.Add(new Binding("Text", this, "BriefDoftech",false,DataSourceUpdateMode.OnPropertyChanged)); |
28 |
txtBriefSec.DataBindings.Add(new Binding("Text", this, "BriefSec", false, DataSourceUpdateMode.OnPropertyChanged)); |
29 |
txtBriefDoftech.TextBoxElement.TextBoxItem.MouseDown += TextBoxItemDoftech_MouseDown; |
30 |
txtBriefDoftech.TextBoxElement.TextBoxItem.LostFocus += TextBoxItemDoftech_LostFocus; |
31 |
|
32 |
txtBriefSec.TextBoxElement.TextBoxItem.MouseDown += TextBoxItemSec_MouseDown; |
33 |
txtBriefSec.TextBoxElement.TextBoxItem.LostFocus += TextBoxItemSec_LostFocus; |
34 |
|
35 |
lstToImages.ListViewElement.ViewElement.Orientation = Orientation.Horizontal; |
36 |
lstFrImages.ListViewElement.ViewElement.Orientation = Orientation.Horizontal; |
37 |
|
38 |
selectImage.ContextMenuOpened += SelectImage_ContextMenuOpened; |
39 |
selectImage.MouseWheel += SelectImage_MouseWheel; |
40 |
|
41 |
lstToImages.SelectedItemChanged += LstImages_SelectedItemChanged; |
42 |
lstToImages.ItemRemoved += LstToImages_ItemRemoved; |
43 |
lstToImages.VisualItemFormatting += LstImages_VisualItemFormatting; |
44 |
lstToImages.EditorInitialized += LstToImages_EditorInitialized; |
45 |
lstFrImages.SelectedItemChanged += LstImages_SelectedItemChanged; |
46 |
lstFrImages.ItemRemoved += LstFrImages_ItemRemoved; |
47 |
lstFrImages.VisualItemFormatting += LstImages_VisualItemFormatting; |
48 |
lstFrImages.EditorInitialized += LstFrImages_EditorInitialized; |
49 |
} |
50 |
|
51 |
private void LstToImages_EditorInitialized(object sender, ListViewItemEditorInitializedEventArgs e) |
52 |
{ |
53 |
} |
54 |
|
55 |
private void LstFrImages_EditorInitialized(object sender, ListViewItemEditorInitializedEventArgs e) |
56 |
{ |
57 |
} |
58 |
|
59 |
private void LstToImages_ItemRemoved(object sender, ListViewItemEventArgs e) |
60 |
{ |
61 |
if (RemoveImage != null) |
62 |
{ |
63 |
RemoveImage(this, e.Item.DataBoundItem as AttImageInfo); |
64 |
} |
65 |
} |
66 |
private void LstFrImages_ItemRemoved(object sender, ListViewItemEventArgs e) |
67 |
{ |
68 |
if (RemoveImage != null) |
69 |
{ |
70 |
RemoveImage(this, e.Item.DataBoundItem as AttImageInfo); |
71 |
} |
72 |
} |
73 |
|
74 |
private void TextBoxItemDoftech_LostFocus(object sender, EventArgs e) |
75 |
{ |
76 |
txtBriefDoftech.MinimumSize = new Size(0, TextMinHeight); |
77 |
|
78 |
LayoutDoftech.RowStyles[1].Height = 100; |
79 |
LayoutDoftech.RowStyles[1].SizeType = SizeType.Percent; |
80 |
} |
81 |
|
82 |
private void TextBoxItemDoftech_MouseDown(object sender, MouseEventArgs e) |
83 |
{ |
84 |
txtBriefDoftech.MinimumSize = new Size(0, 100); |
85 |
|
86 |
LayoutDoftech.RowStyles[1].Height = 100; |
87 |
LayoutDoftech.RowStyles[1].SizeType = SizeType.Absolute; |
88 |
} |
89 |
|
90 |
private void TextBoxItemSec_LostFocus(object sender, EventArgs e) |
91 |
{ |
92 |
|
93 |
txtBriefSec.MinimumSize = new Size(0, TextMinHeight); |
94 |
|
95 |
LayoutSec.RowStyles[1].Height = 100; |
96 |
LayoutSec.RowStyles[1].SizeType = SizeType.Percent; |
97 |
} |
98 |
|
99 |
private void TextBoxItemSec_MouseDown(object sender, MouseEventArgs e) |
100 |
{ |
101 |
txtBriefSec.MinimumSize = new Size(0, 100); |
102 |
|
103 |
LayoutSec.RowStyles[1].Height = 100; |
104 |
LayoutSec.RowStyles[1].SizeType = SizeType.Absolute; |
105 |
} |
106 |
|
107 |
public event PropertyChangedEventHandler PropertyChanged; |
108 |
|
109 |
private void LstImages_VisualItemFormatting(object sender, ListViewVisualItemEventArgs e) |
110 |
{ |
111 |
e.VisualItem.ImageLayout = ImageLayout.Stretch; |
112 |
} |
113 |
|
114 |
private void LstImages_SelectedItemChanged(object sender, EventArgs e) |
115 |
{ |
116 |
var lstImages = sender as RadListViewElement; |
117 |
|
118 |
if (lstImages.SelectedItem?.Image != null) |
119 |
{ |
120 |
selectImage.Image = lstImages.SelectedItem.Image; |
121 |
} |
122 |
} |
123 |
|
124 |
private void SelectImage_MouseWheel(object sender, MouseEventArgs e) |
125 |
{ |
126 |
if (e.Delta < 0) |
127 |
{ |
128 |
selectImage.ZoomProperties.ZoomOut(); |
129 |
} |
130 |
else |
131 |
{ |
132 |
selectImage.ZoomProperties.ZoomIn(); |
133 |
} |
134 |
|
135 |
} |
136 |
|
137 |
private void SelectImage_ContextMenuOpened(object sender, EventArgs e) |
138 |
{ |
139 |
selectImage.ContextMenuProperties.OpenItem.Visibility = ElementVisibility.Collapsed; |
140 |
selectImage.ContextMenuProperties.RemoveItem.Visibility = ElementVisibility.Collapsed; |
141 |
selectImage.ContextMenuProperties.CutItem.Visibility = ElementVisibility.Collapsed; |
142 |
selectImage.ContextMenuProperties.PasteItem.Visibility = ElementVisibility.Collapsed; |
143 |
|
144 |
//selectImage.ContextMenuProperties.EditItem.Visibility = ElementVisibility.Collapsed; |
145 |
} |
146 |
|
147 |
public void SetToImages(List<AttImageInfo> images) |
148 |
{ |
149 |
foreach (var image in images) |
150 |
{ |
151 |
AddToImage(image); |
152 |
} |
153 |
|
154 |
if (images?.Count() > 0) |
155 |
{ |
156 |
lstToImages.SelectedIndex = 0; |
157 |
} |
158 |
} |
159 |
|
160 |
public void AddToImage(AttImageInfo image,bool SelectItem = false) |
161 |
{ |
162 |
ListViewDataItem item = new ListViewDataItem(""); |
163 |
item.DataBoundItem = image; |
164 |
item.ImageAlignment = ContentAlignment.MiddleCenter; |
165 |
item.Image = GetImage(image.Data); |
166 |
item.TextImageRelation = TextImageRelation.ImageBeforeText; |
167 |
lstToImages.Items.Add(item); |
168 |
|
169 |
if (SelectItem) |
170 |
{ |
171 |
lstToImages.SelectedItem = item; |
172 |
} |
173 |
} |
174 |
|
175 |
public void SetFrImages(List<AttImageInfo> images) |
176 |
{ |
177 |
foreach (var image in images) |
178 |
{ |
179 |
AddFrImage(image); |
180 |
} |
181 |
|
182 |
if (images?.Count() > 0) |
183 |
{ |
184 |
lstFrImages.SelectedIndex = 0; |
185 |
} |
186 |
} |
187 |
|
188 |
|
189 |
public void AddFrImage(AttImageInfo image, bool SelectItem = false) |
190 |
{ |
191 |
ListViewDataItem item = new ListViewDataItem(image); |
192 |
item.ImageAlignment = ContentAlignment.MiddleCenter; |
193 |
item.Text = ""; |
194 |
item.Image = GetImage(image.Data); |
195 |
item.TextImageRelation = TextImageRelation.Overlay; |
196 |
lstFrImages.Items.Add(item); |
197 |
|
198 |
if (SelectItem) |
199 |
{ |
200 |
lstFrImages.SelectedItem = item; |
201 |
} |
202 |
} |
203 |
|
204 |
|
205 |
public void Clear() |
206 |
{ |
207 |
this.DataBindings.Clear(); |
208 |
lstFrImages.Items.Clear(); |
209 |
lstToImages.Items.Clear(); |
210 |
selectImage.Image = null; |
211 |
briefDoftech = ""; |
212 |
BriefSec = ""; |
213 |
} |
214 |
|
215 |
private string briefDoftech; |
216 |
public string BriefDoftech |
217 |
{ |
218 |
get { return briefDoftech; } |
219 |
set |
220 |
{ |
221 |
if (briefDoftech != value) |
222 |
{ |
223 |
briefDoftech = value; |
224 |
var propArg = new PropertyChangedEventArgs(nameof(BriefDoftech)); |
225 |
PropertyChanged?.Invoke(this, propArg); |
226 |
} |
227 |
} |
228 |
} |
229 |
|
230 |
private string briefSec; |
231 |
public string BriefSec |
232 |
{ |
233 |
get { return briefSec; } |
234 |
set |
235 |
{ |
236 |
if (briefSec != value) |
237 |
{ |
238 |
briefSec = value; |
239 |
var propArg = new PropertyChangedEventArgs(nameof(BriefSec)); |
240 |
PropertyChanged?.Invoke(this, propArg); |
241 |
} |
242 |
} |
243 |
} |
244 |
|
245 |
private System.Drawing.Image GetImage(byte[] data) |
246 |
{ |
247 |
System.Drawing.Image result = null; |
248 |
|
249 |
using (MemoryStream ms = new MemoryStream(data)) |
250 |
{ |
251 |
result = System.Drawing.Image.FromStream(ms); |
252 |
} |
253 |
|
254 |
return result; |
255 |
} |
256 |
|
257 |
private void txtBrief_TextChanged(object sender, EventArgs e) |
258 |
{ |
259 |
BriefDoftech = txtBriefDoftech.Text; |
260 |
} |
261 |
|
262 |
private void txtBriefSec_TextChanged(object sender, EventArgs e) |
263 |
{ |
264 |
BriefSec = txtBriefSec.Text; |
265 |
} |
266 |
|
267 |
} |
268 |
|
269 |
} |
270 |
|
271 |
public class AttImageInfo |
272 |
{ |
273 |
public string ID { get; set; } |
274 |
public byte[] Data { get; set; } |
275 |
} |