This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
/
Form1.cs
45 lines (38 loc) · 1.54 KB
/
Form1.cs
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
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using DevExpress.XtraCharts;
namespace ImageLegendItems {
public partial class Form1 : Form {
Dictionary<string, Image> photos = new Dictionary<string, Image>();
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
this.employeesTableAdapter.Fill(this.nwindDataSet.Employees);
InitializePhotos();
}
void InitializePhotos() {
foreach (DataRow row in nwindDataSet.Employees.Rows) {
string lastName = row.ItemArray[1].ToString();
if (!photos.ContainsKey(lastName)) {
using (MemoryStream stream = new MemoryStream((byte[])row.ItemArray[14])) {
using (Image sourceImage = Image.FromStream(stream)) {
Bitmap image = new Bitmap(74, 79);
using (Graphics graphics = Graphics.FromImage(image))
graphics.DrawImage(sourceImage,
new Rectangle(new Point(5, 5), new Size(75, 75)));
photos.Add(lastName, image);
}
}
}
}
}
private void chartControl1_CustomDrawSeries(object sender, CustomDrawSeriesEventArgs e) {
e.LegendMarkerImage = photos[e.Series.Name];
}
}
}