using System; using System.Windows.Forms; using DevComponents.DotNetBar; using GeoScene.Data; namespace Cyberpipe.Forms { public partial class FrmProject : Office2007Form { public FrmProject() { InitializeComponent(); } /// <summary> /// 经纬度坐标转换为平面坐标 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLatlon2Coord_Click(object sender, EventArgs e) { int id = GSOProjectManager.AddProject(Utility.projectStr); // GeoScene.Data.GSOProjectManager.SetCurProject(id); if (txtLong.Text == "" || txtLat.Text == "") { MessageBox.Show("请输入要转化的经纬度坐标!"); return; } double x = Convert.ToDouble(txtLong.Text); double y = Convert.ToDouble(txtLat.Text); if (x > 180) { MessageBox.Show("经度不能超过180!!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning); } if (y > 90) { MessageBox.Show("纬度不能超过90!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } GSOPoint2d pt2d = new GSOPoint2d(x, y); GSOPoint2d result = GSOProjectManager.Forward(pt2d, id); txtX.Text = result.X.ToString(); txtY.Text = result.Y.ToString(); } /// <summary> /// 平面坐标转换为经纬度坐标 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCoord2Latlon_Click(object sender, EventArgs e) { int id = GSOProjectManager.AddProject(Utility.projectStr); // GeoScene.Data.GSOProjectManager.SetCurProject(id); if (txtX.Text == "" || txtY.Text == "") { MessageBox.Show("请输入要转化的横轴和竖轴的值!"); return; } double x = Convert.ToDouble(txtX.Text); double y = Convert.ToDouble(txtY.Text); GSOPoint2d pt2d = new GSOPoint2d(x, y); GSOPoint2d result = GSOProjectManager.Inverse(pt2d, id); txtLong.Text = result.X.ToString(); txtLat.Text = result.Y.ToString(); } /// <summary> /// 键盘按钮按下事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void txtLong_KeyPress(object sender, KeyPressEventArgs e) { TextBox text = sender as TextBox; if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && e.KeyChar != 46) { e.Handled = true; } if (e.KeyChar == 46) //小数点 { if (text.Text.Length <= 0) e.Handled = true; //小数点不能在第一位 else //处理不规则的小数点 { float f; float oldf; bool b1 = false, b2 = false; b1 = float.TryParse(text.Text, out oldf); b2 = float.TryParse(text.Text + e.KeyChar, out f); if (b2 == false) { if (b1) e.Handled = true; else e.Handled = false; } } } } } }