-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetSymbol.cs
125 lines (113 loc) · 4.48 KB
/
GetSymbol.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
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 System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Controls;
namespace SpatialDataManagement
{
public partial class GetSymbol : Form
{
public IStyleGalleryItem m_styleGalleryItem;
string stylesPath = string.Empty;
esriSymbologyStyleClass styleClass;
public GetSymbol(esriSymbologyStyleClass symStyleClass)
{
InitializeComponent();
styleClass = symStyleClass;
}
private void GetSmybol_Load(object sender, EventArgs e)
{
LoadStyles();
}
private void LoadStyles()
{
//Get the ArcGIS install location
string sInstall = ESRI.ArcGIS.RuntimeManager.ActiveRuntime.Path;
string defaultStyle = System.IO.Path.Combine(sInstall, "Styles\\ESRI.ServerStyle");
if (System.IO.File.Exists(defaultStyle))
{
//Load the ESRI.ServerStyle file into the SymbologyControl
axSymbologyControl1.LoadStyleFile(defaultStyle);
axSymbologyControl1.StyleClass = styleClass;
axSymbologyControl1.GetStyleClass(axSymbologyControl1.StyleClass).SelectItem(0);
cbxStyles.Text = defaultStyle;
}
stylesPath = sInstall + "\\Styles";
cbxStyles.Items.Clear();
cbxStylesAddItems(stylesPath);
}
private void cbxStylesAddItems(string path)
{
string[] serverstyleFiles = System.IO.Directory.GetFiles(stylesPath, "*.serverstyle", System.IO.SearchOption .AllDirectories );
string[] styleFiles = System.IO.Directory.GetFiles(stylesPath, "*.style", System.IO.SearchOption.AllDirectories);
cbxStylesAddItems(serverstyleFiles);
cbxStylesAddItems(styleFiles);
}
private void cbxStylesAddItems(string[] files)
{
if (files.GetLength(0) == 0) return;
foreach (string file in files)
{
cbxStyles.Items.Add(file);
}
}
private void cmdCancel_Click(object sender, EventArgs e)
{
m_styleGalleryItem = null;
this.Hide();
}
private void cmdOK_Click(object sender, EventArgs e)
{
this.Hide();
}
private void axSymbologyControl1_OnItemSelected(object sender, ISymbologyControlEvents_OnItemSelectedEvent e)
{
m_styleGalleryItem = (IStyleGalleryItem)e.styleGalleryItem;
PreviewImage();
}
private void PreviewImage()
{
//Get and set the style class
ISymbologyStyleClass symbologyStyleClass = axSymbologyControl1.GetStyleClass(axSymbologyControl1.StyleClass);
//Preview an image of the symbol
stdole.IPictureDisp picture = symbologyStyleClass.PreviewItem(m_styleGalleryItem, pictureBox1.Width, pictureBox1.Height);
System.Drawing.Image image = System.Drawing.Image.FromHbitmap(new System.IntPtr(picture.Handle));
pictureBox1.Image = image;
}
public IStyleGalleryItem GetItem(ESRI.ArcGIS.Controls.esriSymbologyStyleClass styleClass)
{
//Set the style class
axSymbologyControl1.StyleClass = styleClass;
axSymbologyControl1.Update();
//Show the modal form
this.ShowDialog();
//Return the selected label style
return m_styleGalleryItem;
}
private void cbxStyles_SelectedIndexChanged(object sender, EventArgs e)
{
if (cbxStyles.SelectedItem == null) return;
axSymbologyControl1.Clear();
stylesPath = cbxStyles.SelectedItem.ToString();
string ext = System.IO.Path.GetExtension(stylesPath).ToLower();
if (ext == ".serverstyle")
axSymbologyControl1.LoadStyleFile(stylesPath);
if (ext == ".style")
axSymbologyControl1.LoadDesktopStyleFile(stylesPath);
axSymbologyControl1.StyleClass = styleClass;
}
private void btnOtherStyles_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
stylesPath = folderBrowserDialog1.SelectedPath;
cbxStylesAddItems(stylesPath);
}
}
}
}