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

📄 styleform.cs

📁 实现SHP
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(32, 16);
			this.label6.TabIndex = 0;
			this.label6.Text = "Size";
			// 
			// StyleForm
			// 
			this.AcceptButton = this.StyleButtonApply;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.StyleButtonCancel;
			this.ClientSize = new System.Drawing.Size(154, 192);
			this.Controls.Add(this.StyleTab);
			this.Controls.Add(this.panel1);
			this.DockPadding.All = 2;
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.MaximizeBox = false;
			this.Name = "StyleForm";
			this.Text = "Style";
			//this.Load += new System.EventHandler(this.StyleForm_Load);
			this.panel1.ResumeLayout(false);
			this.StyleTab.ResumeLayout(false);
			this.StyleTabPen.ResumeLayout(false);
			this.StyleTabBrush.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.StyleBrushOpacity)).EndInit();
			this.StyleTabPoint.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void StyleForm_Load(object sender, System.EventArgs e)
		{
			System.Drawing.Point loc = new Point();
			loc.X = this.Owner.DesktopLocation.X+this.Owner.DesktopBounds.Width-this.DesktopBounds.Width/2;
			loc.Y = this.Owner.DesktopLocation.Y+(this.Owner.DesktopBounds.Height-this.DesktopBounds.Height)/2;
			this.DesktopLocation=loc;

			Activated+=new EventHandler(StyleForm_Activated); 
			StylePenStyle.SelectedIndexChanged+=new EventHandler(StylePenStyle_SelectedIndexChanged); 
		}

		private void StyleForm_Activated(object sender, EventArgs e)
		{
			this.bin=(Bin)CurrencyMgr.Current;
			initTabs();
			initBrush();
			initPen();
			initPoint();
		}

		#region of tab, cancel and apply
		/// <summary>
		/// Init style tabs according to the type of symbol being edited.
		/// </summary>
		private void initTabs()
		{
			switch (bin.Symbol.Type)
			{
				case SymbolTypeEnum.Point :
					SetControlsEnabled(StyleTabBrush,true);
					SetControlsEnabled(StyleTabPoint,true);
					break;
				case SymbolTypeEnum.Line:
					SetControlsEnabled(StyleTabBrush,false);
					SetControlsEnabled(StyleTabPoint,false); 
					if(StyleTab.SelectedIndex>0) StyleTab.SelectedIndex=0;
					break;
				case SymbolTypeEnum.Polygon :
					SetControlsEnabled(StyleTabBrush,true);
					SetControlsEnabled(StyleTabPoint,false); 
					if(StyleTab.SelectedIndex>1) StyleTab.SelectedIndex=1;
					break;
				default:
					break;
			}
		}
		/// <summary>
		/// Set enabled state of controls in each tab.
		/// </summary>
		/// <param name="tpage">tab page</param>
		/// <param name="isEnabled">value indicatin enabled state</param>
		private static void SetControlsEnabled(TabPage tpage,bool isEnabled)
		{
			foreach (Control c in tpage.Controls)
			{
				//c.Enabled=isEnabled;
				c.Visible=isEnabled;
			}
		}
		/// <summary>
		/// handles user click on Cancel button.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void StyleButtonCancel_Click(object sender, System.EventArgs e)
		{
			this.Close();
			CurrencyMgr.CancelCurrentEdit();
		}
		/// <summary>
		/// handles user click on Apply button
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void StyleButtonApply_Click(object sender, System.EventArgs e)
		{
			try
			{
				setPen();
				switch (bin.Symbol.Type)
				{
					case SymbolTypeEnum.Point :
						setBrush();
						setPoint();
						break;
					case SymbolTypeEnum.Line :
						//setPen();
						break;
					case SymbolTypeEnum.Polygon :
						setBrush();
						break;
					default:
						break;
				}
				CurrencyMgr.EndCurrentEdit();
				CurrencyMgr.Refresh();

				ViewForm vf = ((MainForm)this.Owner).vForm;
				if(!vf.IsDisposed ) vf.Refresh();
			}
			catch (System.FormatException fexc)
			{
				System.Windows.Forms.MessageBox.Show("Error parsing value :\r"+fexc.Message);
			}
			catch (System.Exception exc)
			{
				System.Windows.Forms.MessageBox.Show("Error applying style :\r"+exc.Message);
			}
		}
		#endregion

		#region point related stuff
		/// <summary>
		/// set point text box value
		/// </summary>
		private void initPoint()
		{
			this.StylePointSize.Text = bin.Symbol.PointRadiusMap.ToString();
		}
		/// <summary>
		/// set Symbol Point properties
		/// </summary>
		private void setPoint()
		{
			this.bin.Symbol.PointRadiusMap=float.Parse(this.StylePointSize.Text);
		}
		#endregion

		#region pen related stuff
		private void initPen()
		{
			StylePenColor.BackColor = bin.Symbol.Pen.Color;
			//StylePenWidth.Text = bin.Symbol.Pen.Width.ToString();
			StylePenWidth.Text = bin.Symbol.LineWidthMap.ToString(); 
			switch (bin.Symbol.Pen.DashStyle)
			{
				case DashStyle.Solid :
					StylePenStyle.SelectedIndex = 0; 
					break;
				case DashStyle.Dash  :
					StylePenStyle.SelectedIndex = 1;
					break;
				case DashStyle.DashDot :
					StylePenStyle.SelectedIndex = 2;
					break;
				case DashStyle.DashDotDot :
					StylePenStyle.SelectedIndex = 3;
					break;
				case DashStyle.Dot :
					StylePenStyle.SelectedIndex = 4;
					break;
				case DashStyle.Custom :
					StylePenStyle.SelectedIndex = 5;
					break;
				default:
					StylePenStyle.SelectedIndex = 0;
					break;
			}
			if(Convert.ToInt16(bin.Symbol.Pen.Color.A)==0) StylePenStyle.SelectedIndex = 6;
		}

		private void StylePenStyle_SelectedIndexChanged(object sender, EventArgs e)
		{
			ComboBox cb = (ComboBox)sender;
			if(cb.SelectedIndex!=5)
			{
				StyleCustomDash.Text="";
				StyleCustomDash.ReadOnly=true;
			}
			else
			{
				StyleCustomDash.ReadOnly=false;
				DashStyle oldds=bin.Symbol.Pen.DashStyle;

				//we need to set the dashstyle to custom, otherwise out of memory exception occurs.
				bin.Symbol.Pen.DashStyle=DashStyle.Custom;
				System.Text.StringBuilder customdash= new System.Text.StringBuilder();
				for (int i=0;i<bin.Symbol.Pen.DashPattern.Length;i++)
				{
					customdash.Append(bin.Symbol.Pen.DashPattern[i].ToString()+" ");
				}
				StyleCustomDash.Text=customdash.ToString().Trim();

				//switch back to old dashstyle
				bin.Symbol.Pen.DashStyle=oldds;
			}
		}

		private void StylePenColor_Click(object sender, System.EventArgs e)
		{
			if(StylePenStyle.SelectedIndex==6) return; //style 'none' in effect
			Button butt=(Button)sender;
			//colordialog.Color=butt.BackColor;
			colordialog.AllowFullOpen=true;
			colordialog.AnyColor=true;
			colordialog.ShowDialog();
			butt.BackColor=colordialog.Color;
		}
		private void setPen()
		{
			if(StylePenStyle.SelectedIndex==6) //color 'none'
			{
				this.bin.Symbol.Pen.Color = Color.FromArgb(0,this.StylePenColor.BackColor);
				return;
			}
			else
			{
				this.bin.Symbol.Pen.Color = this.StylePenColor.BackColor;
			}
			this.bin.Symbol.LineWidthMap = float.Parse(this.StylePenWidth.Text);

			DashStyle[] dsa=new DashStyle[6]{DashStyle.Solid,DashStyle.Dash,DashStyle.DashDot,DashStyle.DashDotDot,DashStyle.Dot,DashStyle.Custom};
			this.bin.Symbol.Pen.DashStyle =dsa[this.StylePenStyle.SelectedIndex];
			if(this.bin.Symbol.Pen.DashStyle==DashStyle.Custom)
			{
				try
				{
					string[] dss = this.StyleCustomDash.Text.Trim().Split(' ');
					if(dss.Length<=1) 
					{
						bin.Symbol.Pen.DashStyle=DashStyle.Solid;
						return;
					}

					float[] dsf = new float[dss.Length];
					for(int i=0;i<dsf.Length;i++)
					{
						dsf[i]=float.Parse(dss[i]);
					}
					this.bin.Symbol.Pen.DashPattern = dsf;
				}
				catch
				{
					bin.Symbol.Pen.DashStyle=DashStyle.Solid;
				}
			}
		}
		#endregion

		#region brush related stuff
		private void initBrush()
		{
			StyleBrushColor.BackColor = bin.Symbol.Brush.Color;
			StyleBrushOpacity.Value = 100*Convert.ToInt16(bin.Symbol.Brush.Color.A)/255;
		}
		private void StyleBrushColor_Click(object sender, System.EventArgs e)
		{
			Button butt=(Button)sender;
			//colordialog.Color=butt.BackColor;
			colordialog.AllowFullOpen=true;
			colordialog.AnyColor=true;
			colordialog.ShowDialog();
			setButtonBrushBackColor(colordialog.Color);
		}
		private void setButtonBrushBackColor(Color basecolor)
		{
			int alpha = (int)((float)this.StyleBrushOpacity.Value*255F/100F);
			this.StyleBrushColor.BackColor=Color.FromArgb(alpha,basecolor);
		}
		private void StyleBrushOpacity_ValueChanged(object sender, System.EventArgs e)
		{
			setButtonBrushBackColor(this.StyleBrushColor.BackColor); 
		}
		private void StyleBrushOpacity_Validated(object sender, EventArgs e)
		{
			setButtonBrushBackColor(this.StyleBrushColor.BackColor); 
		}
		private void setBrush()
		{
			this.bin.Symbol.Brush.Color = this.StyleBrushColor.BackColor;
		}
		#endregion

	}
}

⌨️ 快捷键说明

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