⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 markersymselect.cs

📁 一个可读取显示arigis下的severstyle文件的程序.
💻 CS
📖 第 1 页 / 共 2 页
字号:
		}
		#endregion
		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new ServerStyleViewer());
		}
		private void ServerStyleViewer_Load(object sender, System.EventArgs e)
		{
			this.pStyleGallery = new ESRI.ArcGIS.Display.ServerStyleGalleryClass();	
			string Xmlfile = Application.StartupPath + @"\files.Xml";
			try
			{
				if(System.IO.File.Exists(Xmlfile))
				{
					System.Data.DataSet Ds = new System.Data.DataSet();
					Ds.ReadXml(Xmlfile);
					foreach(System.Data.DataRow dr in Ds.Tables[0].Rows)
					{
						this.AddFile(dr[0].ToString());
					}
				}
			}
			catch(Exception ex)
			{
				Console.WriteLine(ex.Message);
			}
		}

		private void PreviewSymbols(string StyleFile,string StyleGalleryClass)
		{
			ESRI.ArcGIS.Display.IEnumStyleGalleryItem	mEnumStyleItem;
			ESRI.ArcGIS.Display.IStyleGalleryItem		mStyleItem;
			if(	StyleFile != this.CurrentStyleFile)
			{
				this.CurrentStyleFile = StyleFile;
				this.CurrentStyleGalleryClass = StyleGalleryClass;
				//this.pStyleGallery = new ESRI.ArcGIS.Display.ServerStyleGalleryClass();//.StyleGalleryClass();
				this.pStyleGalleryStorage = pStyleGallery  as ESRI.ArcGIS.Display.IStyleGalleryStorage;
				this.pStyleGalleryStorage.AddFile(this.CurrentStyleFile);				
				mEnumStyleItem = this.pStyleGallery.get_Items(this.CurrentStyleGalleryClass,this.CurrentStyleFile,"");	
				this.cbxCategory.Items.Clear();
				this.cbxCategory.Items.Add("<All>");
				ESRI.ArcGIS.esriSystem.IEnumBSTR pEnumBSTR = this.pStyleGallery.get_Categories(this.CurrentStyleGalleryClass);
				pEnumBSTR.Reset();
				string Category = "";
				Category = pEnumBSTR.Next();
				while(Category != null)
				{
					this.cbxCategory.Items.Add(Category);
					Category = pEnumBSTR.Next();
				}
				bControlEvent = true;
				this.cbxCategory.SelectedIndex = 0;
				bControlEvent = false;
			}
			else
			{
				if(CurrentStyleGalleryClass != StyleGalleryClass)
				{
					this.cbxCategory.Items.Clear();
					this.cbxCategory.Items.Add("<All>");
					ESRI.ArcGIS.esriSystem.IEnumBSTR pEnumBSTR = this.pStyleGallery.get_Categories(StyleGalleryClass);
					pEnumBSTR.Reset();
					string Category = "";
					Category = pEnumBSTR.Next();
					while(Category != null)
					{
						this.cbxCategory.Items.Add(Category);
						Category = pEnumBSTR.Next();
					}
					bControlEvent = true;
					this.cbxCategory.SelectedIndex = 0;
					bControlEvent = false;
				}
				CurrentStyleGalleryClass = StyleGalleryClass;
				mEnumStyleItem = this.pStyleGallery.get_Items(CurrentStyleGalleryClass,this.CurrentStyleFile,CurrentCategoryName);	
			}				
			ESRI.ArcGIS.Display.IStyleGalleryClass  mStyleClass = pStyleGallery.get_Class(CurrentStyleGalleryClassIndex);

			System.Windows.Forms.ImageList Largeimage = new ImageList();
			System.Windows.Forms.ImageList Smallimage = new ImageList();			
			Largeimage.ImageSize = new Size(32,32);
			Smallimage.ImageSize = new Size(16,16);
			System.Drawing.Bitmap bmpB,bmpS ;
			System.Windows.Forms.ListViewItem lvItem ;		
			this.lvSymbolView.Items.Clear();
			this.lvSymbolView.Columns.Clear();
			
			this.lvSymbolView.LargeImageList = Largeimage;
			this.lvSymbolView.SmallImageList = Smallimage;
			this.lvSymbolView.Columns.Add("Name",180,System.Windows.Forms.HorizontalAlignment.Left);
			this.lvSymbolView.Columns.Add("Index",50,System.Windows.Forms.HorizontalAlignment.Left);
			this.lvSymbolView.Columns.Add("Category",120,System.Windows.Forms.HorizontalAlignment.Left);

			mEnumStyleItem.Reset();
			mStyleItem = mEnumStyleItem.Next();
			int ImageIndex =0;
			while(mStyleItem != null)
			{				
				bmpB = StyleGalleryItemView.StyleGalleryItemToBmp(32,32,mStyleClass,mStyleItem);
				bmpS = StyleGalleryItemView.StyleGalleryItemToBmp(16,16,mStyleClass,mStyleItem);
				Largeimage.Images.Add(bmpB);
				Smallimage.Images.Add(bmpS);
				lvItem = new ListViewItem(new string[]{mStyleItem.Name,mStyleItem.ID.ToString(),mStyleItem.Category},ImageIndex);				
				this.lvSymbolView.Items.Add(lvItem);					
				mStyleItem = mEnumStyleItem.Next();
				ImageIndex++;
			}
			System.Runtime.InteropServices.Marshal.ReleaseComObject(mEnumStyleItem);				
		}
		private void tbViewStyle_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			this.tbtLargeIcon.Pushed = false;
			this.tbtSmallIcon.Pushed = false;
			this.tbtDetail.Pushed = false;
			if(e.Button == this.tbtLargeIcon)
			{
				this.lvSymbolView.View = System.Windows.Forms.View.LargeIcon;
				this.tbtLargeIcon.Pushed = true;
			}
			else if(e.Button == this.tbtSmallIcon)
			{
				this.lvSymbolView.View = System.Windows.Forms.View.SmallIcon;
				this.tbtSmallIcon.Pushed = true;
			}
			else if(e.Button == this.tbtDetail)
			{
				this.lvSymbolView.View = System.Windows.Forms.View.Details;
				this.tbtDetail.Pushed = true;
			}
			else
			{
				this.lvSymbolView.View = System.Windows.Forms.View.LargeIcon;
				this.tbtLargeIcon.Pushed = true;
			}
		}

		private void cbxCategory_SelectedIndexChanged(object sender, System.EventArgs e)
		{			
			if(!bControlEvent)
			{
				if(this.cbxCategory.SelectedItem.ToString() == "<All>")
				{
					this.CurrentCategoryName = "";
					this.PreviewSymbols(this.CurrentStyleFile,this.CurrentStyleGalleryClass);				
				}
				else
				{
					this.CurrentCategoryName = this.cbxCategory.SelectedItem.ToString() ;
					this.PreviewSymbols(this.CurrentStyleFile,CurrentStyleGalleryClass);
				
				}
			}
		}

		private void btOK_Click(object sender, System.EventArgs e)
		{
			this.DialogResult = DialogResult.OK;
			this.Close();
		}

		private void btClose_Click(object sender, System.EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
			this.Close();
		}

		private void ServerStyleViewer_Closed(object sender, System.EventArgs e)
		{
			try
			{
				System.Runtime.InteropServices.Marshal.ReleaseComObject(pStyleGalleryStorage);
				System.Runtime.InteropServices.Marshal.ReleaseComObject(pStyleGallery);
			}
			catch
			{}	
			ESRI.ArcGIS.Utility.COMSupport.AOUninitialize.Shutdown();
		}

		private void btOpen_Click(object sender, System.EventArgs e)
		{
			System.Windows.Forms.OpenFileDialog oDlg = new OpenFileDialog();
			oDlg.Filter = "ESRI ServerStyle(*.ServerStyle)|*.ServerStyle";
			if(oDlg.ShowDialog() == DialogResult.OK)
			{
				AddFile(oDlg.FileName);
			}
		}
		private void AddFile(string filename)
		{
			if(!System.IO.File.Exists(filename))
			{
				return;
			}
			bool IsExist = false;
			foreach(TreeNode tnode in this.tvStyleFileTree.Nodes)
			{
				if(tnode.Tag.ToString() == filename)
				{
					IsExist = true;
				}
			}
			if(!IsExist)
			{
				System.IO.FileInfo finfo = new System.IO.FileInfo(filename);				
				TreeNode RootNode = new TreeNode(finfo.Name);
				RootNode.Tag = finfo.FullName;
				this.tvStyleFileTree.Nodes.Add(RootNode);
					
				for(int i = 0;i<this.pStyleGallery.ClassCount;i++)
				{
					TreeNode tnode = new TreeNode(this.pStyleGallery.get_Class(i).Name);
					tnode.Tag = i;
					RootNode.Nodes.Add(tnode);						
				}
			}
		}

		private void tvStyleFileTree_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
			TreeNode tnode = this.tvStyleFileTree.SelectedNode;
			if(tnode != null && tnode.Parent != null)
			{
				this.CurrentStyleGalleryClassIndex = int.Parse(tnode.Tag.ToString());
				PreviewSymbols(tnode.Parent.Tag.ToString(),tnode.Text);
			}
		}

		private void ServerStyleViewer_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			System.Data.DataSet Ds = new System.Data.DataSet("FileCollection");
			System.Data.DataTable tb = new System.Data.DataTable("Files");
			tb.Columns.Add("FileName",System.Type.GetType("System.String"));
			System.Data.DataRow dr;
			foreach(TreeNode tnode in this.tvStyleFileTree.Nodes)
			{
				dr = tb.NewRow();
				dr[0] = tnode.Tag.ToString();
				tb.Rows.Add(dr);
			}
			Ds.Tables.Add(tb);
			Ds.WriteXml(Application.StartupPath + @"\files.Xml",System.Data.XmlWriteMode.IgnoreSchema);
		}
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -