ToolStripMenuItem

本文介绍了MenuStrip控件,它是System.Windows.Forms命名空间中的一个顶级容器,用于替代之前的MainMenu控件,并保持了向后兼容性。MenuStrip提供了菜单系统,适用于Windows窗体应用程序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

MenuStrip 类

为窗体提供菜单系统。

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
         System.Windows.Forms.ScrollableControl
           System.Windows.Forms.ToolStrip
             System.Windows.Forms.MenuStrip

命名空间:  System.Windows.Forms
程序集:  System.Windows.Forms(在 System.Windows.Forms.dll 中)

备注

MenuStrip 是取代 MainMenu 的顶级容器。(MenuStrip is the top-level container that supersedes MainMenu.

虽然 MenuStrip 对以前版本的 MainMenu 控件的功能进行了替换和添加,但是考虑到向后兼容性和将来的使用(如果您选择),仍然保留了 MainMenu

 

ToolStripMenuItem菜单上的条目

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; // 添加必要的命名空间 using System.Data.SqlClient; // 添加数据库支持 namespace _2 { public partial class 主界面 : Form { // 声明所有控件 private SplitContainer splitContainer1; private TreeView treeViewNotes; private ListView listViewNotes; private ColumnHeader columnHeader1; private ColumnHeader columnHeader2; private ColumnHeader columnHeader3; private ColumnHeader columnHeader4; private Panel panel1; private Label lblLastModified; private Label lblNoteTitle; private SplitContainer splitContainer2; private ListView listViewVersions; private ColumnHeader columnHeader5; private ColumnHeader columnHeader6; private ColumnHeader columnHeader7; private MenuStrip menuStrip1; private ToolStripMenuItem 文件ToolStripMenuItem; private ToolStripMenuItem 上传文件ToolStripMenuItem; private ToolStripMenuItem 打开ToolStripMenuItem1; private ToolStripMenuItem 退出登录ToolStripMenuItem; private ToolStripMenuItem 注销账号ToolStripMenuItem; private ToolStripMenuItem 编辑ToolStripMenuItem; private ToolStripMenuItem 修改ToolStripMenuItem; private ToolStripMenuItem 修改密码ToolStripMenuItem; private ToolStripMenuItem 删除ToolStripMenuItem; private ToolStripMenuItem 笔记ToolStripMenuItem; private ToolStripMenuItem 上传文件ToolStripMenuItem1; private ToolStripMenuItem 修改ToolStripMenuItem1; private ToolStripMenuItem 删除ToolStripMenuItem1; private ToolStripMenuItem 分类ToolStripMenuItem; private ToolStripMenuItem 版本历史ToolStripMenuItem; private ImageList imageList1; private WebBrowser webBrowser1; // 添加缺失的WebBrowser声明 public 主界面() { InitializeComponent(); } private void InitializeComponent() { // 初始化所有控件 this.splitContainer1 = new SplitContainer(); this.treeViewNotes = new TreeView(); this.listViewNotes = new ListView(); this.columnHeader1 = new ColumnHeader(); this.columnHeader2 = new ColumnHeader(); this.columnHeader3 = new ColumnHeader(); this.columnHeader4 = new ColumnHeader(); this.panel1 = new Panel(); this.lblLastModified = new Label(); this.lblNoteTitle = new Label(); this.splitContainer2 = new SplitContainer(); this.webBrowser1 = new WebBrowser(); // 初始化WebBrowser this.listViewVersions = new ListView(); this.columnHeader5 = new ColumnHeader(); this.columnHeader6 = new ColumnHeader(); this.columnHeader7 = new ColumnHeader(); this.menuStrip1 = new MenuStrip(); this.文件ToolStripMenuItem = new ToolStripMenuItem(); this.上传文件ToolStripMenuItem = new ToolStripMenuItem(); this.打开ToolStripMenuItem1 = new ToolStripMenuItem(); this.退出登录ToolStripMenuItem = new ToolStripMenuItem(); this.注销账号ToolStripMenuItem = new ToolStripMenuItem(); this.编辑ToolStripMenuItem = new ToolStripMenuItem(); this.修改ToolStripMenuItem = new ToolStripMenuItem(); this.修改密码ToolStripMenuItem = new ToolStripMenuItem(); this.删除ToolStripMenuItem = new ToolStripMenuItem(); this.笔记ToolStripMenuItem = new ToolStripMenuItem(); this.上传文件ToolStripMenuItem1 = new ToolStripMenuItem(); this.修改ToolStripMenuItem1 = new ToolStripMenuItem(); this.删除ToolStripMenuItem1 = new ToolStripMenuItem(); this.分类ToolStripMenuItem = new ToolStripMenuItem(); this.版本历史ToolStripMenuItem = new ToolStripMenuItem(); this.imageList1 = new ImageList(); // 设置控件属性 this.SuspendLayout(); // splitContainer1 this.splitContainer1 = new SplitContainer(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.SuspendLayout(); this.splitContainer1.Dock = DockStyle.Fill; this.splitContainer1.Location = new Point(0, 24); this.splitContainer1.Name = "splitContainer1"; // // splitContainer1.Panel1 // this.splitContainer1.Panel1.Controls.Add(this.treeViewNotes); this.splitContainer1.Panel1.Controls.Add(this.listViewNotes); // // splitContainer1.Panel2 // this.splitContainer1.Panel2.Controls.Add(this.panel1); this.splitContainer1.Size = new Size(1000, 576); this.splitContainer1.SplitterDistance = 300; this.splitContainer1.TabIndex = 0; // treeViewNotes this.treeViewNotes.Dock = DockStyle.Top; this.treeViewNotes.Location = new Point(0, 0); this.treeViewNotes.Name = "treeViewNotes"; this.treeViewNotes.Size = new Size(300, 300); this.treeViewNotes.TabIndex = 0; this.treeViewNotes.ImageList = imageList1; this.treeViewNotes.AfterSelect += new TreeViewEventHandler(this.treeViewNotes_AfterSelect); this.treeViewNotes.NodeMouseDoubleClick += new TreeNodeMouseClickEventHandler(this.treeViewNotes_NodeMouseDoubleClick); // 初始化图像列表 this.imageList1.Images.Add(SystemIcons.Folder); this.imageList1.Images.Add(SystemIcons.Document); // listViewNotes this.listViewNotes.Dock = DockStyle.Fill; this.listViewNotes.View = View.Details; this.listViewNotes.Columns.AddRange(new ColumnHeader[] { this.columnHeader1, this.columnHeader2, this.columnHeader3, this.columnHeader4 }); this.listViewNotes.Location = new Point(0, 300); this.listViewNotes.Name = "listViewNotes"; this.listViewNotes.Size = new Size(300, 276); this.listViewNotes.TabIndex = 1; this.listViewNotes.UseCompatibleStateImageBehavior = false; this.listViewNotes.FullRowSelect = true; this.listViewNotes.MultiSelect = false; this.listViewNotes.SelectedIndexChanged += new EventHandler(this.listViewNotes_SelectedIndexChanged); // 设置列宽 this.columnHeader1.Text = "标题"; this.columnHeader1.Width = 120; this.columnHeader2.Text = "分类"; this.columnHeader2.Width = 80; this.columnHeader3.Text = "创建时间"; this.columnHeader3.Width = 120; this.columnHeader4.Text = "最后修改"; this.columnHeader4.Width = 120; // panel1 this.panel1.Controls.Add(this.splitContainer2); this.panel1.Controls.Add(this.lblLastModified); this.panel1.Controls.Add(this.lblNoteTitle); this.panel1.Dock = DockStyle.Fill; this.panel1.Location = new Point(0, 0); this.panel1.Name = "panel1"; this.panel1.Size = new Size(696, 576); this.panel1.TabIndex = 0; // lblNoteTitle this.lblNoteTitle.AutoSize = true; this.lblNoteTitle.Font = new Font("微软雅黑", 12F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(134))); this.lblNoteTitle.Location = new Point(10, 10); this.lblNoteTitle.Name = "lblNoteTitle"; this.lblNoteTitle.Size = new Size(100, 21); this.lblNoteTitle.TabIndex = 1; this.lblNoteTitle.Text = "未选择笔记"; // lblLastModified this.lblLastModified.AutoSize = true; this.lblLastModified.Location = new Point(10, 40); this.lblLastModified.Name = "lblLastModified"; this.lblLastModified.Size = new Size(0, 12); this.lblLastModified.TabIndex = 2; // splitContainer2 this.splitContainer2 = new SplitContainer(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); this.splitContainer2.SuspendLayout(); this.splitContainer2.Dock = DockStyle.Fill; this.splitContainer2.Location = new Point(0, 60); this.splitContainer2.Name = "splitContainer2"; this.splitContainer2.Orientation = Orientation.Horizontal; // // splitContainer2.Panel1 // this.splitContainer2.Panel1.Controls.Add(this.webBrowser1); // // splitContainer2.Panel2 // this.splitContainer2.Panel2.Controls.Add(this.listViewVersions); this.splitContainer2.Size = new Size(696, 516); this.splitContainer2.SplitterDistance = 350; this.splitContainer2.TabIndex = 3; // webBrowser1 this.webBrowser1.Dock = DockStyle.Fill; this.webBrowser1.Location = new Point(0, 0); this.webBrowser1.MinimumSize = new Size(20, 20); this.webBrowser1.Name = "webBrowser1"; this.webBrowser1.Size = new Size(696, 350); this.webBrowser1.TabIndex = 0; // listViewVersions this.listViewVersions.Dock = DockStyle.Fill; this.listViewVersions.View = View.Details; this.listViewVersions.Columns.AddRange(new ColumnHeader[] { this.columnHeader5, this.columnHeader6, this.columnHeader7 }); this.listViewVersions.Location = new Point(0, 0); this.listViewVersions.Name = "listViewVersions"; this.listViewVersions.Size = new Size(696, 162); this.listViewVersions.TabIndex = 0; this.listViewVersions.UseCompatibleStateImageBehavior = false; this.listViewVersions.FullRowSelect = true; this.listViewVersions.MultiSelect = false; this.listViewVersions.DoubleClick += new EventHandler(this.listViewVersions_DoubleClick); // 设置列宽 this.columnHeader5.Text = "版本"; this.columnHeader5.Width = 80; this.columnHeader6.Text = "创建时间"; this.columnHeader6.Width = 120; this.columnHeader7.Text = "描述"; this.columnHeader7.Width = 400; // menuStrip1 this.menuStrip1.Items.AddRange(new ToolStripItem[] { this.文件ToolStripMenuItem, this.编辑ToolStripMenuItem, this.笔记ToolStripMenuItem }); this.menuStrip1.Location = new Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new Size(1000, 25); this.menuStrip1.TabIndex = 1; this.menuStrip1.Text = "menuStrip1"; // 文件ToolStripMenuItem this.文件ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { this.上传文件ToolStripMenuItem, this.打开ToolStripMenuItem1, this.退出登录ToolStripMenuItem, this.注销账号ToolStripMenuItem }); this.文件ToolStripMenuItem.Name = "文件ToolStripMenuItem"; this.文件ToolStripMenuItem.Size = new Size(44, 21); this.文件ToolStripMenuItem.Text = "文件"; // 上传文件ToolStripMenuItem this.上传文件ToolStripMenuItem.Name = "上传文件ToolStripMenuItem"; this.上传文件ToolStripMenuItem.Size = new Size(152, 22); this.上传文件ToolStripMenuItem.Text = "上传文件"; this.上传文件ToolStripMenuItem.Click += new EventHandler(this.上传文件ToolStripMenuItem_Click); // 打开ToolStripMenuItem1 this.打开ToolStripMenuItem1.Name = "打开ToolStripMenuItem1"; this.打开ToolStripMenuItem1.Size = new Size(152, 22); this.打开ToolStripMenuItem1.Text = "打开"; this.打开ToolStripMenuItem1.Click += new EventHandler(this.打开ToolStripMenuItem1_Click); // 退出登录ToolStripMenuItem this.退出登录ToolStripMenuItem.Name = "退出登录ToolStripMenuItem"; this.退出登录ToolStripMenuItem.Size = new Size(152, 22); this.退出登录ToolStripMenuItem.Text = "退出登录"; this.退出登录ToolStripMenuItem.Click += new EventHandler(this.退出登录ToolStripMenuItem_Click); // 注销账号ToolStripMenuItem this.注销账号ToolStripMenuItem.Name = "注销账号ToolStripMenuItem"; this.注销账号ToolStripMenuItem.Size = new Size(152, 22); this.注销账号ToolStripMenuItem.Text = "注销账号"; this.注销账号ToolStripMenuItem.Click += new EventHandler(this.注销账号ToolStripMenuItem_Click); // 编辑ToolStripMenuItem this.编辑ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { this.修改ToolStripMenuItem, this.修改密码ToolStripMenuItem, this.删除ToolStripMenuItem }); this.编辑ToolStripMenuItem.Name = "编辑ToolStripMenuItem"; this.编辑ToolStripMenuItem.Size = new Size(44, 21); this.编辑ToolStripMenuItem.Text = "编辑"; // 修改ToolStripMenuItem this.修改ToolStripMenuItem.Name = "修改ToolStripMenuItem"; this.修改ToolStripMenuItem.Size = new Size(152, 22); this.修改ToolStripMenuItem.Text = "修改"; // 修改密码ToolStripMenuItem this.修改密码ToolStripMenuItem.Name = "修改密码ToolStripMenuItem"; this.修改密码ToolStripMenuItem.Size = new Size(152, 22); this.修改密码ToolStripMenuItem.Text = "修改密码"; this.修改密码ToolStripMenuItem.Click += new EventHandler(this.修改密码ToolStripMenuItem_Click); // 删除ToolStripMenuItem this.删除ToolStripMenuItem.Name = "删除ToolStripMenuItem"; this.删除ToolStripMenuItem.Size = new Size(152, 22); this.删除ToolStripMenuItem.Text = "删除"; // 笔记ToolStripMenuItem this.笔记ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { this.上传文件ToolStripMenuItem1, this.修改ToolStripMenuItem1, this.删除ToolStripMenuItem1, this.分类ToolStripMenuItem, this.版本历史ToolStripMenuItem }); this.笔记ToolStripMenuItem.Name = "笔记ToolStripMenuItem"; this.笔记ToolStripMenuItem.Size = new Size(44, 21); this.笔记ToolStripMenuItem.Text = "笔记"; // 上传文件ToolStripMenuItem1 this.上传文件ToolStripMenuItem1.Name = "上传文件ToolStripMenuItem1"; this.上传文件ToolStripMenuItem1.Size = new Size(152, 22); this.上传文件ToolStripMenuItem1.Text = "上传笔记"; this.上传文件ToolStripMenuItem1.Click += new EventHandler(this.上传文件ToolStripMenuItem_Click); // 修改ToolStripMenuItem1 this.修改ToolStripMenuItem1.Name = "修改ToolStripMenuItem1"; this.修改ToolStripMenuItem1.Size = new Size(152, 22); this.修改ToolStripMenuItem1.Text = "修改"; this.修改ToolStripMenuItem1.Click += new EventHandler(this.修改ToolStripMenuItem_Click); // 删除ToolStripMenuItem1 this.删除ToolStripMenuItem1.Name = "删除ToolStripMenuItem1"; this.删除ToolStripMenuItem1.Size = new Size(152, 22); this.删除ToolStripMenuItem1.Text = "删除"; this.删除ToolStripMenuItem1.Click += new EventHandler(this.删除ToolStripMenuItem1_Click); // 分类ToolStripMenuItem this.分类ToolStripMenuItem.Name = "分类ToolStripMenuItem"; this.分类ToolStripMenuItem.Size = new Size(152, 22); this.分类ToolStripMenuItem.Text = "分类"; this.分类ToolStripMenuItem.Click += new EventHandler(this.分类ToolStripMenuItem_Click); // 版本历史ToolStripMenuItem this.版本历史ToolStripMenuItem.Name = "版本历史ToolStripMenuItem"; this.版本历史ToolStripMenuItem.Size = new Size(152, 22); this.版本历史ToolStripMenuItem.Text = "版本历史"; this.版本历史ToolStripMenuItem.Click += new EventHandler(this.版本历史ToolStripMenuItem_Click); // 窗体设置 this.AutoScaleDimensions = new SizeF(6F, 12F); this.AutoScaleMode = AutoScaleMode.Font; this.ClientSize = new Size(1000, 600); this.Controls.Add(this.splitContainer1); this.Controls.Add(this.menuStrip1); this.MainMenuStrip = this.menuStrip1; this.Name = "主界面"; this.Text = "学习管理助手"; this.FormClosing += new FormClosingEventHandler(this.主界面_FormClosing); this.Load += new EventHandler(this.主界面_Load); // 恢复布局 this.splitContainer1.Panel1.ResumeLayout(false); this.splitContainer1.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); this.splitContainer2.Panel1.ResumeLayout(false); this.splitContainer2.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); this.splitContainer2.ResumeLayout(false); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } // 事件处理方法(放在类中,不在InitializeComponent内) private void 主界面_Load(object sender, EventArgs e) { // 初始化代码 } private void 主界面_FormClosing(object sender, FormClosingEventArgs e) { // 关闭窗体处理 } // 添加所有事件处理方法的空实现 private void treeViewNotes_AfterSelect(object sender, TreeViewEventArgs e) { } private void treeViewNotes_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { } private void listViewNotes_SelectedIndexChanged(object sender, EventArgs e) { } private void listViewVersions_DoubleClick(object sender, EventArgs e) { } private void 上传文件ToolStripMenuItem_Click(object sender, EventArgs e) { } private void 打开ToolStripMenuItem1_Click(object sender, EventArgs e) { } private void 退出登录ToolStripMenuItem_Click(object sender, EventArgs e) { } private void 注销账号ToolStripMenuItem_Click(object sender, EventArgs e) { } private void 修改密码ToolStripMenuItem_Click(object sender, EventArgs e) { } private void 修改ToolStripMenuItem_Click(object sender, EventArgs e) { } private void 删除ToolStripMenuItem1_Click(object sender, EventArgs e) { } private void 分类ToolStripMenuItem_Click(object sender, EventArgs e) { } private void 版本历史ToolStripMenuItem_Click(object sender, EventArgs e) { } } } 怎么改
07-03
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace _2 { public partial class 主界面 : Form { public 主界面() { InitializeComponent(); } private void InitializeComponent() { // 主容器和布局 this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.treeViewNotes = new System.Windows.Forms.TreeView(); this.listViewNotes = new System.Windows.Forms.ListView(); this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.panel1 = new System.Windows.Forms.Panel(); this.lblLastModified = new System.Windows.Forms.Label(); this.lblNoteTitle = new System.Windows.Forms.Label(); this.splitContainer2 = new System.Windows.Forms.SplitContainer(); this.listViewVersions = new System.Windows.Forms.ListView(); this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader7 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.文件ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.上传文件ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.打开ToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.退出登录ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.注销账号ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.编辑ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.修改ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.修改密码ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.删除ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.笔记ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.上传文件ToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.修改ToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.删除ToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.分类ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.版本历史ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.imageList1 = new System.Windows.Forms.ImageList(); // 设置控件属性 this.SuspendLayout(); // // splitContainer1 // this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer1.Location = new System.Drawing.Point(0, 24); this.splitContainer1.Name = "splitContainer1"; // // splitContainer1.Panel1 (左侧面板) // this.splitContainer1.Panel1.Controls.Add(this.treeViewNotes); this.splitContainer1.Panel1.Controls.Add(this.listViewNotes); // // splitContainer1.Panel2 (右侧面板) // this.splitContainer1.Panel2.Controls.Add(this.panel1); this.splitContainer1.Size = new System.Drawing.Size(1000, 576); this.splitContainer1.SplitterDistance = 300; this.splitContainer1.TabIndex = 0; // // treeViewNotes (笔记分类树) // this.treeViewNotes.Dock = System.Windows.Forms.DockStyle.Top; this.treeViewNotes.Location = new System.Drawing.Point(0, 0); this.treeViewNotes.Name = "treeViewNotes"; this.treeViewNotes.Size = new System.Drawing.Size(300, 300); this.treeViewNotes.TabIndex = 0; this.treeViewNotes.ImageList = imageList1; this.treeViewNotes.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViewNotes_AfterSelect); this.treeViewNotes.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeViewNotes_NodeMouseDoubleClick); // 设置图像列表 imageList1.Images.Add(SystemIcons.Folder); // 文件夹图标用于分类 imageList1.Images.Add(SystemIcons.Document); // 文档图标用于笔记 // // listViewNotes (笔记列表) // this.listViewNotes.Dock = System.Windows.Forms.DockStyle.Fill; this.listViewNotes.View = System.Windows.Forms.View.Details; this.listViewNotes.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.columnHeader1, // 标题 this.columnHeader2, // 分类 this.columnHeader3, // 创建时间 this.columnHeader4 // 最后修改 }); this.listViewNotes.Location = new System.Drawing.Point(0, 300); this.listViewNotes.Name = "listViewNotes"; this.listViewNotes.Size = new System.Drawing.Size(300, 276); this.listViewNotes.TabIndex = 1; this.listViewNotes.UseCompatibleStateImageBehavior = false; this.listViewNotes.FullRowSelect = true; this.listViewNotes.MultiSelect = false; this.listViewNotes.SelectedIndexChanged += new System.EventHandler(this.listViewNotes_SelectedIndexChanged); // 设置列宽 this.columnHeader1.Text = "标题"; this.columnHeader1.Width = 120; this.columnHeader2.Text = "分类"; this.columnHeader2.Width = 80; this.columnHeader3.Text = "创建时间"; this.columnHeader3.Width = 120; this.columnHeader4.Text = "最后修改"; this.columnHeader4.Width = 120; // // panel1 (主内容面板) // this.panel1.Controls.Add(this.splitContainer2); this.panel1.Controls.Add(this.lblLastModified); this.panel1.Controls.Add(this.lblNoteTitle); this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(696, 576); this.panel1.TabIndex = 0; // // lblNoteTitle (笔记标题标签) // this.lblNoteTitle.AutoSize = true; this.lblNoteTitle.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.lblNoteTitle.Location = new System.Drawing.Point(10, 10); this.lblNoteTitle.Name = "lblNoteTitle"; this.lblNoteTitle.Size = new System.Drawing.Size(100, 21); this.lblNoteTitle.TabIndex = 1; this.lblNoteTitle.Text = "未选择笔记"; // // lblLastModified (最后修改标签) // this.lblLastModified.AutoSize = true; this.lblLastModified.Location = new System.Drawing.Point(10, 40); this.lblLastModified.Name = "lblLastModified"; this.lblLastModified.Size = new System.Drawing.Size(0, 12); this.lblLastModified.TabIndex = 2; // // splitContainer2 (右侧分割容器) // this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer2.Location = new System.Drawing.Point(0, 60); this.splitContainer2.Name = "splitContainer2"; this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal; // // splitContainer2.Panel1 (上部分 - 笔记内容) // this.splitContainer2.Panel1.Controls.Add(this.webBrowser1); // // splitContainer2.Panel2 (下部分 - 版本历史) // this.splitContainer2.Panel2.Controls.Add(this.listViewVersions); this.splitContainer2.Size = new System.Drawing.Size(696, 516); this.splitContainer2.SplitterDistance = 350; this.splitContainer2.TabIndex = 3; // // webBrowser1 (笔记内容浏览器) // this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill; this.webBrowser1.Location = new System.Drawing.Point(0, 0); this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20); this.webBrowser1.Name = "webBrowser1"; this.webBrowser1.Size = new System.Drawing.Size(696, 350); this.webBrowser1.TabIndex = 0; // // listViewVersions (版本历史列表) // this.listViewVersions.Dock = System.Windows.Forms.DockStyle.Fill; this.listViewVersions.View = System.Windows.Forms.View.Details; this.listViewVersions.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.columnHeader5, // 版本 this.columnHeader6, // 创建时间 this.columnHeader7 // 描述 }); this.listViewVersions.Location = new System.Drawing.Point(0, 0); this.listViewVersions.Name = "listViewVersions"; this.listViewVersions.Size = new System.Drawing.Size(696, 162); this.listViewVersions.TabIndex = 0; this.listViewVersions.UseCompatibleStateImageBehavior = false; this.listViewVersions.FullRowSelect = true; this.listViewVersions.MultiSelect = false; this.listViewVersions.DoubleClick += new System.EventHandler(this.listViewVersions_DoubleClick); // 设置列宽 this.columnHeader5.Text = "版本"; this.columnHeader5.Width = 80; this.columnHeader6.Text = "创建时间"; this.columnHeader6.Width = 120; this.columnHeader7.Text = "描述"; this.columnHeader7.Width = 400; // // menuStrip1 (主菜单) // this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.文件ToolStripMenuItem, this.编辑ToolStripMenuItem, this.笔记ToolStripMenuItem }); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(1000, 25); this.menuStrip1.TabIndex = 1; this.menuStrip1.Text = "menuStrip1"; // // 文件ToolStripMenuItem (文件菜单) // this.文件ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.上传文件ToolStripMenuItem, this.打开ToolStripMenuItem1, this.退出登录ToolStripMenuItem, this.注销账号ToolStripMenuItem }); this.文件ToolStripMenuItem.Name = "文件ToolStripMenuItem"; this.文件ToolStripMenuItem.Size = new System.Drawing.Size(44, 21); this.文件ToolStripMenuItem.Text = "文件"; // // 上传文件ToolStripMenuItem (上传文件菜单项) // this.上传文件ToolStripMenuItem.Name = "上传文件ToolStripMenuItem"; this.上传文件ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.上传文件ToolStripMenuItem.Text = "上传文件"; this.上传文件ToolStripMenuItem.Click += new System.EventHandler(this.上传文件ToolStripMenuItem_Click); // // 打开ToolStripMenuItem1 (打开文件菜单项) // this.打开ToolStripMenuItem1.Name = "打开ToolStripMenuItem1"; this.打开ToolStripMenuItem1.Size = new System.Drawing.Size(152, 22); this.打开ToolStripMenuItem1.Text = "打开"; this.打开ToolStripMenuItem1.Click += new System.EventHandler(this.打开ToolStripMenuItem1_Click); // // 退出登录ToolStripMenuItem (退出登录菜单项) // this.退出登录ToolStripMenuItem.Name = "退出登录ToolStripMenuItem"; this.退出登录ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.退出登录ToolStripMenuItem.Text = "退出登录"; this.退出登录ToolStripMenuItem.Click += new System.EventHandler(this.退出登录ToolStripMenuItem_Click); // // 注销账号ToolStripMenuItem (注销账号菜单项) // this.注销账号ToolStripMenuItem.Name = "注销账号ToolStripMenuItem"; this.注销账号ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.注销账号ToolStripMenuItem.Text = "注销账号"; this.注销账号ToolStripMenuItem.Click += new System.EventHandler(this.注销账号ToolStripMenuItem_Click); // // 编辑ToolStripMenuItem (编辑菜单) // this.编辑ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.修改ToolStripMenuItem, this.修改密码ToolStripMenuItem, this.删除ToolStripMenuItem }); this.编辑ToolStripMenuItem.Name = "编辑ToolStripMenuItem"; this.编辑ToolStripMenuItem.Size = new System.Drawing.Size(44, 21); this.编辑ToolStripMenuItem.Text = "编辑"; // // 修改ToolStripMenuItem (修改菜单项) // this.修改ToolStripMenuItem.Name = "修改ToolStripMenuItem"; this.修改ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.修改ToolStripMenuItem.Text = "修改"; // // 修改密码ToolStripMenuItem (修改密码菜单项) // this.修改密码ToolStripMenuItem.Name = "修改密码ToolStripMenuItem"; this.修改密码ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.修改密码ToolStripMenuItem.Text = "修改密码"; this.修改密码ToolStripMenuItem.Click += new System.EventHandler(this.修改密码ToolStripMenuItem_Click); // // 删除ToolStripMenuItem (删除菜单项) // this.删除ToolStripMenuItem.Name = "删除ToolStripMenuItem"; this.删除ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.删除ToolStripMenuItem.Text = "删除"; // // 笔记ToolStripMenuItem (笔记菜单) // this.笔记ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.上传文件ToolStripMenuItem1, this.修改ToolStripMenuItem1, this.删除ToolStripMenuItem1, this.分类ToolStripMenuItem, this.版本历史ToolStripMenuItem }); this.笔记ToolStripMenuItem.Name = "笔记ToolStripMenuItem"; this.笔记ToolStripMenuItem.Size = new System.Drawing.Size(44, 21); this.笔记ToolStripMenuItem.Text = "笔记"; // // 上传文件ToolStripMenuItem1 (上传笔记菜单项) // this.上传文件ToolStripMenuItem1.Name = "上传文件ToolStripMenuItem1"; this.上传文件ToolStripMenuItem1.Size = new System.Drawing.Size(152, 22); this.上传文件ToolStripMenuItem1.Text = "上传笔记"; this.上传文件ToolStripMenuItem1.Click += new System.EventHandler(this.上传文件ToolStripMenuItem_Click); // // 修改ToolStripMenuItem1 (修改笔记菜单项) // this.修改ToolStripMenuItem1.Name = "修改ToolStripMenuItem1"; this.修改ToolStripMenuItem1.Size = new System.Drawing.Size(152, 22); this.修改ToolStripMenuItem1.Text = "修改"; this.修改ToolStripMenuItem1.Click += new System.EventHandler(this.修改ToolStripMenuItem_Click); // // 删除ToolStripMenuItem1 (删除笔记菜单项) // this.删除ToolStripMenuItem1.Name = "删除ToolStripMenuItem1"; this.删除ToolStripMenuItem1.Size = new System.Drawing.Size(152, 22); this.删除ToolStripMenuItem1.Text = "删除"; this.删除ToolStripMenuItem1.Click += new System.EventHandler(this.删除ToolStripMenuItem1_Click); // // 分类ToolStripMenuItem (分类菜单项) // this.分类ToolStripMenuItem.Name = "分类ToolStripMenuItem"; this.分类ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.分类ToolStripMenuItem.Text = "分类"; this.分类ToolStripMenuItem.Click += new System.EventHandler(this.分类ToolStripMenuItem_Click); // // 版本历史ToolStripMenuItem (版本历史菜单项) // this.版本历史ToolStripMenuItem.Name = "版本历史ToolStripMenuItem"; this.版本历史ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.版本历史ToolStripMenuItem.Text = "版本历史"; this.版本历史ToolStripMenuItem.Click += new System.EventHandler(this.版本历史ToolStripMenuItem_Click); // 窗体设置 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1000, 600); this.Controls.Add(this.splitContainer1); this.Controls.Add(this.menuStrip1); this.MainMenuStrip = this.menuStrip1; this.Name = "Form2"; this.Text = "学习管理助手"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form2_FormClosing); this.Load += new System.EventHandler(this.Form2_Load); this.splitContainer1.Panel1.ResumeLayout(false); this.splitContainer1.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); this.splitContainer2.Panel1.ResumeLayout(false); this.splitContainer2.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); this.splitContainer2.ResumeLayout(false); this.menuStrip1.ResumeLayout(false); private void 主界面_Load(object sender, EventArgs e) { } } } 为什么报错怎么改
07-03
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.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Display; namespace WaterPipelineGIS2 { public partial class main : Form { private IFeatureLayer _selectedFeatureLayer; private System.Drawing.Point _lastRightClickPosition; private SelectionMode currentMode = SelectionMode.None; private IGraphicsContainer _spatialSelectionGraphics; private IGraphicsContainer _attributeHighlightGraphics; private ToolStripStatusLabel lblStatus; // 添加量测模式枚举 public enum MeasureMode { None, PolygonArea, PolygonPerimeter, PolylineLength, PointCoordinate } // 添加量测相关变量 private MeasureMode currentMeasureMode = MeasureMode.None; private List<IPoint> measurePoints = new List<IPoint>(); private IElement tempMeasureElement; private List<IElement> measurementElements = new List<IElement>(); private bool isMeasuring = false; // 修改后的SelectionMode枚举 public enum SelectionMode { None, Rectangle, Circle, Polygon, Polyline } private void InitializeGraphicsContainers() { try { // 确保地图控件已初始化 if (axMapControl1 == null) return; // 确保ActiveView已初始化 if (axMapControl1.ActiveView == null) { // 尝试刷新视图 axMapControl1.ActiveView.Refresh(); } if (axMapControl1.ActiveView != null) { _spatialSelectionGraphics = axMapControl1.ActiveView.GraphicsContainer; _attributeHighlightGraphics = axMapControl1.ActiveView.GraphicsContainer; } } catch (Exception ex) { MessageBox.Show("初始化图形容器失败: " + ex.Message); } } private void Form1_Load(object sender, EventArgs e) { // 强制创建地图控件 if (!axMapControl1.Created) axMapControl1.CreateControl(); // 延迟初始化图形容器 axMapControl1.ActiveView.Refresh(); InitializeGraphicsContainers(); } public main() { InitializeComponent(); // 确保设计器初始化完成 if (statusStrip1 != null) { lblStatus = new ToolStripStatusLabel(); statusStrip1.Items.Add(lblStatus); lblStatus.Text = "就绪"; } // 添加窗体加载事件处理程序 this.Load += Form1_LoadHandler; // === 修改结束 === // 事件绑定保持不变 axMapControl1.OnMouseMove += axMapControl1_OnMouseMove; axMapControl1.OnMouseDown += axMapControl1_OnMouseDown; axMapControl1.OnDoubleClick += new IMapControlEvents2_Ax_OnDoubleClickEventHandler(axMapControl1_OnDoubleClick); } // === 新增方法 === private void Form1_LoadHandler(object sender, EventArgs e) { // 确保地图控件已创建 if (axMapControl1 != null && !axMapControl1.Created) { axMapControl1.CreateControl(); } // 初始化图形容器 InitializeGraphicsContainers(); // 确保 ActiveView 有效 if (axMapControl1.ActiveView != null) { // 刷新视图以确保图形容器可用 axMapControl1.ActiveView.Refresh(); } } private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) { try { // 公共坐标显示 double mapX = e.mapX; double mapY = e.mapY; lblCoordinate.Text = "X: {mapX:F3} Y: {mapY:F3}"; // 量测模式预览 if (isMeasuring && measurePoints.Count > 0) { switch (currentMeasureMode) { case MeasureMode.PolygonArea: case MeasureMode.PolygonPerimeter: DrawTempPolygonMeasure(e.x, e.y); break; case MeasureMode.PolylineLength: DrawTempPolylineMeasure(e.x, e.y); break; } } } catch (Exception ex) { Console.WriteLine("鼠标移动错误: " + ex.Message); } } private void toolStripMenuItem2_Click(object sender, EventArgs e) { using (var rotateForm = new RotateForm()) { if (rotateForm.ShowDialog() == DialogResult.OK) { try { axMapControl1.Rotation = rotateForm.RotationAngle; axMapControl1.ActiveView.Refresh(); lblCoordinate.Text += " 旋转角度:" + rotateForm.RotationAngle + "°"; } catch (Exception ex) { MessageBox.Show("旋转失败:" + ex.Message); } } } } private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e) { if (e.button == 2) // 右键 { _lastRightClickPosition = new System.Drawing.Point(e.x, e.y); ITOCControl2 tocControl = (ITOCControl2)axTOCControl1.Object; IBasicMap basicMap = null; ILayer layer = null; object other = Type.Missing; object index = Type.Missing; esriTOCControlItem itemType = esriTOCControlItem.esriTOCControlItemNone; tocControl.HitTest(e.x, e.y, ref itemType, ref basicMap, ref layer, ref other, ref index); if (itemType == esriTOCControlItem.esriTOCControlItemLayer && layer != null) { contextMenuStripTOC.Show(axTOCControl1, e.x, e.y); } } } private void openAttributeTableToolStripMenuItem_Click(object sender, EventArgs e) { ITOCControl2 tocControl = (ITOCControl2)axTOCControl1.Object; IBasicMap basicMap = null; ILayer layer = null; object other = Type.Missing; object index = Type.Missing; esriTOCControlItem itemType = esriTOCControlItem.esriTOCControlItemNone; System.Drawing.Point screenPos = contextMenuStripTOC.PointToClient(Control.MousePosition); System.Drawing.Point controlPos = axTOCControl1.PointToClient(Control.MousePosition); tocControl.HitTest( controlPos.X, controlPos.Y, ref itemType, ref basicMap, ref layer, ref other, ref index ); IFeatureLayer featureLayer = layer as IFeatureLayer; if (featureLayer != null) { _selectedFeatureLayer = featureLayer; AttributeTableForm attrForm = new AttributeTableForm( _selectedFeatureLayer, this ); attrForm.Show(); } } private void SetSelectionSymbol() { ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = GetRgbColor(255, 0, 0); fillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = GetRgbColor(255, 255, 0); lineSymbol.Width = 2; fillSymbol.Outline = lineSymbol; if (_selectedFeatureLayer != null) { IGeoFeatureLayer geoLayer = (IGeoFeatureLayer)_selectedFeatureLayer; ISimpleRenderer renderer = new SimpleRendererClass(); renderer.Symbol = (ISymbol)fillSymbol; geoLayer.Renderer = (IFeatureRenderer)renderer; axMapControl1.ActiveView.Refresh(); } } private IRgbColor GetRgbColor(int r, int g, int b) { IRgbColor color = new RgbColorClass(); color.Red = r; color.Green = g; color.Blue = b; return color; } private IRgbColor GetRgbColor(int r, int g, int b, int alpha) { IRgbColor color = new RgbColorClass(); color.Red = r; color.Green = g; color.Blue = b; color.Transparency = (byte)(255 - alpha); return color; } public void ActivateFeatureLayer(IFeatureLayer featureLayer) { if (featureLayer == null) return; _selectedFeatureLayer = featureLayer; axMapControl1.ActiveView.Refresh(); axTOCControl1.Update(); } public void HighlightAndZoomToFeature(IFeatureLayer featureLayer, int oid) { try { if (featureLayer == null || featureLayer.FeatureClass == null) { MessageBox.Show("图层或要素类无效!"); return; } IFeature feature = featureLayer.FeatureClass.GetFeature(oid); if (feature == null || feature.Shape == null) { MessageBox.Show("要素 OID " + oid + " 不存在或无几何!"); return; } IGeometry geometry = feature.Shape; IEnvelope envelope = geometry.Envelope; if (envelope.IsEmpty || envelope.Width == 0 || envelope.Height == 0) { envelope.Expand(10, 10, true); } else { envelope.Expand(1.5, 1.5, true); } axMapControl1.Extent = envelope; axMapControl1.ActiveView.ScreenDisplay.UpdateWindow(); HighlightGeometry(geometry); } catch (Exception ex) { MessageBox.Show("高亮要素失败: " + ex.Message); } } private void btnRectSelect_Click(object sender, EventArgs e) { currentMeasureMode = MeasureMode.None; // 互斥 currentMode = SelectionMode.Rectangle; axMapControl1.CurrentTool = null; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; lblStatus.Text = "矩形选择模式"; } private void btnCircleSelect_Click(object sender, EventArgs e) { currentMeasureMode = MeasureMode.None; // 互斥 currentMode = SelectionMode.Circle; axMapControl1.CurrentTool = null; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; lblStatus.Text = "圆形选择模式"; } private void btnPolygonSelect_Click(object sender, EventArgs e) { currentMeasureMode = MeasureMode.None; // 互斥 currentMode = SelectionMode.Polygon; axMapControl1.CurrentTool = null; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; lblStatus.Text = "多边形选择模式"; } private void btnLineSelect_Click(object sender, EventArgs e) { currentMeasureMode = MeasureMode.None; // 互斥 currentMode = SelectionMode.Polyline; axMapControl1.CurrentTool = null; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; lblStatus.Text = "折线选择模式"; } private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { try { // 量测模式处理 if (isMeasuring) { HandleMeasureMode(e); return; } // 左键点击 if (e.button == 1) { if (currentMode != SelectionMode.None) { HandleSpatialSelection(e); } } } catch (Exception ex) { MessageBox.Show("操作错误: " + ex.Message); } } private void PerformSpatialSelection(IGeometry geometry) { try { IMap map = axMapControl1.Map; if (map == null) return; map.ClearSelection(); for (int i = 0; i < map.LayerCount; i++) { IFeatureLayer featureLayer = map.get_Layer(i) as IFeatureLayer; if (featureLayer == null || !featureLayer.Valid || featureLayer.FeatureClass == null) continue; ISpatialFilter filter = new SpatialFilterClass(); filter.Geometry = geometry; filter.GeometryField = featureLayer.FeatureClass.ShapeFieldName; filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureSelection selection = (IFeatureSelection)featureLayer; selection.SelectFeatures(filter, esriSelectionResultEnum.esriSelectionResultNew, false); } axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); axMapControl1.ActiveView.Refresh(); } catch (Exception ex) { MessageBox.Show("空间询失败: " + ex.Message); } } private void HighlightGeometry(IGeometry geometry) { try { if (_spatialSelectionGraphics != null) { _spatialSelectionGraphics.DeleteAllElements(); } IElement element = null; switch (geometry.GeometryType) { case esriGeometryType.esriGeometryPolygon: { ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = GetRgbColor(255, 0, 0, 80); ISimpleLineSymbol outline = new SimpleLineSymbolClass(); outline.Color = GetRgbColor(255, 0, 0); outline.Width = 2; fillSymbol.Outline = outline; element = new PolygonElementClass(); element.Geometry = geometry; ((IFillShapeElement)element).Symbol = fillSymbol; } break; case esriGeometryType.esriGeometryPolyline: { ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = GetRgbColor(255, 0, 0); lineSymbol.Width = 3; element = new LineElementClass(); element.Geometry = geometry; ((ILineElement)element).Symbol = lineSymbol; } break; case esriGeometryType.esriGeometryPoint: { ISimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbolClass(); markerSymbol.Color = GetRgbColor(255, 0, 0); markerSymbol.Size = 12; element = new MarkerElementClass(); element.Geometry = geometry; ((IMarkerElement)element).Symbol = markerSymbol; } break; } if (element != null && _spatialSelectionGraphics != null) { _spatialSelectionGraphics.AddElement(element, 0); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } } catch (Exception ex) { MessageBox.Show("高亮显示失败: " + ex.Message); } } private void btnClearSelection_Click(object sender, EventArgs e) { try { if (axMapControl1.Map != null) { axMapControl1.Map.ClearSelection(); } if (_spatialSelectionGraphics != null) { _spatialSelectionGraphics.DeleteAllElements(); } axMapControl1.ActiveView.PartialRefresh( esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGraphics, null, null ); axMapControl1.ActiveView.Refresh(); currentMode = SelectionMode.None; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; lblStatus.Text = "就绪"; } catch (Exception ex) { MessageBox.Show("清除选择失败: " + ex.Message); } } private void axMapControl1_OnDoubleClick(object sender, IMapControlEvents2_OnDoubleClickEvent e) { if (currentMode != SelectionMode.None) { currentMode = SelectionMode.None; axMapControl1.CurrentTool = null; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; lblStatus.Text = "就绪"; } } private void HandleSpatialSelection(IMapControlEvents2_OnMouseDownEvent e) { IGeometry geometry = null; switch (currentMode) { case SelectionMode.Rectangle: IEnvelope rectEnv = axMapControl1.TrackRectangle(); if (rectEnv != null) { IPolygon polygon = new PolygonClass(); polygon.SpatialReference = axMapControl1.SpatialReference; ISegmentCollection segColl = (ISegmentCollection)polygon; segColl.SetRectangle(rectEnv); geometry = (IGeometry)polygon; } break; case SelectionMode.Circle: IEnvelope envelope = axMapControl1.TrackRectangle(); if (envelope.Width <= 0 || envelope.Height <= 0) { MessageBox.Show("请拖拽有效的矩形范围以创建圆形!"); return; } IPoint center = new PointClass(); center.PutCoords( (envelope.XMin + envelope.XMax) / 2, (envelope.YMin + envelope.YMax) / 2 ); double radius = Math.Max(envelope.Width, envelope.Height) / 2; ICircularArc circularArc = new CircularArcClass(); IConstructCircularArc constructArc = (IConstructCircularArc)circularArc; constructArc.ConstructCircle(center, radius, true); ISegmentCollection circleSegColl = new PolygonClass(); circleSegColl.AddSegment((ISegment)circularArc); geometry = (IGeometry)circleSegColl; geometry.SpatialReference = axMapControl1.SpatialReference; break; case SelectionMode.Polygon: geometry = axMapControl1.TrackPolygon(); break; case SelectionMode.Polyline: geometry = axMapControl1.TrackLine(); break; } if (geometry != null) { PerformSpatialSelection(geometry); HighlightGeometry(geometry); } } // 创建折线几何 private IPolyline CreatePolyline(List<IPoint> points, IPoint currentPoint = null) { try { // 创建点集合 IPointCollection pointCollection = new PolylineClass(); // 添加所有点 foreach (IPoint point in points) { if (point != null) { pointCollection.AddPoint(point); } } // 添加当前鼠标位置 if (currentPoint != null) { pointCollection.AddPoint(currentPoint); } // 转换为折线 IPolyline polyline = pointCollection as IPolyline; if (polyline == null) return null; // 设置空间参考(关键!) if (axMapControl1.SpatialReference != null) { polyline.SpatialReference = axMapControl1.SpatialReference; } // 简化几何 ITopologicalOperator topoOp = polyline as ITopologicalOperator; if (topoOp != null) { topoOp.Simplify(); } return polyline; } catch (Exception ex) { MessageBox.Show("创建折线时出错: " + ex.Message); return null; } } // 创建多边形几何 private IPolygon CreatePolygon(List<IPoint> points, IPoint currentPoint = null) { try { // 创建点集合 IPointCollection pointCollection = new PolygonClass(); // 添加所有点 foreach (IPoint point in points) { if (point != null) { pointCollection.AddPoint(point); } } // 添加当前鼠标位置 if (currentPoint != null) { pointCollection.AddPoint(currentPoint); } // 转换为多边形 IPolygon polygon = pointCollection as IPolygon; if (polygon == null) return null; // 设置空间参考(关键!) if (axMapControl1.SpatialReference != null) { polygon.SpatialReference = axMapControl1.SpatialReference; } // 简化几何 ITopologicalOperator topoOp = polygon as ITopologicalOperator; if (topoOp != null) { topoOp.Simplify(); } return polygon; } catch (Exception ex) { MessageBox.Show("创建多边形时出错: " + ex.Message); return null; } } // 量测菜单项点击事件处理 private void 面积量测ToolStripMenuItem_Click(object sender, EventArgs e) { StartMeasureMode(MeasureMode.PolygonArea); } private void 周长量测ToolStripMenuItem_Click(object sender, EventArgs e) { StartMeasureMode(MeasureMode.PolygonPerimeter); } private void 折线周长量测ToolStripMenuItem_Click(object sender, EventArgs e) { StartMeasureMode(MeasureMode.PolylineLength); } private void 点坐标量测ToolStripMenuItem_Click(object sender, EventArgs e) { StartMeasureMode(MeasureMode.PointCoordinate); } // 开始量测模式 private void StartMeasureMode(MeasureMode mode) { currentMode = SelectionMode.None; // 互斥 // 清除之前的状态 EndMeasureMode(); currentMeasureMode = mode; isMeasuring = true; measurePoints.Clear(); // 设置鼠标指针 axMapControl1.MousePointer = esriControlsMousePointer.esriPointerCrosshair; // 设置状态栏提示 switch (mode) { case MeasureMode.PolygonArea: lblStatus.Text = "面积量测: 左键添加顶点,右键完成"; break; case MeasureMode.PolygonPerimeter: lblStatus.Text = "周长量测: 左键添加顶点,右键完成"; break; case MeasureMode.PolylineLength: lblStatus.Text = "长度量测: 左键添加顶点,右键完成"; break; case MeasureMode.PointCoordinate: lblStatus.Text = "点坐标量测: 左键点击地图获取坐标"; break; } } // 结束量测模式 private void EndMeasureMode() { ClearTempMeasureElement(); measurePoints.Clear(); isMeasuring = false; currentMeasureMode = MeasureMode.None; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; lblStatus.Text = "就绪"; } // 绘制临时多边形量测图形 private void DrawTempPolygonMeasure(int x, int y) { if (measurePoints.Count == 0) return; try { // 清除之前的临时图形 ClearTempMeasureElement(); // 获取当前鼠标位置 IPoint currentPoint = axMapControl1.ToMapPoint(x, y); // 创建临时多边形(包括当前鼠标位置) IPolygon polygon = CreatePolygon(measurePoints, currentPoint); // 创建符号(蓝色边框,半透明填充) ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = GetRgbColor(0, 0, 255); // 蓝色 lineSymbol.Width = 2; ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Outline = lineSymbol; fillSymbol.Color = GetRgbColor(0, 255, 255, 100); // 青色半透明 // 创建元素 tempMeasureElement = new PolygonElementClass(); tempMeasureElement.Geometry = polygon; ((IFillShapeElement)tempMeasureElement).Symbol = fillSymbol; // 添加到地图 IGraphicsContainer graphics = axMapControl1.Map as IGraphicsContainer; if (graphics != null) { graphics.AddElement(tempMeasureElement, 0); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } } catch (Exception ex) { Console.WriteLine("量测预览错误: " + ex.Message); } } // 绘制临时折线量测图形 private void DrawTempPolylineMeasure(int x, int y) { if (measurePoints.Count == 0) return; try { // 清除之前的临时图形 ClearTempMeasureElement(); // 获取当前鼠标位置 IPoint currentPoint = axMapControl1.ToMapPoint(x, y); // 创建临时折线(包括当前鼠标位置) IPolyline polyline = CreatePolyline(measurePoints, currentPoint); // 创建符号(红色粗线) ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = GetRgbColor(255, 0, 0); // 红色 lineSymbol.Width = 3; // 创建元素 tempMeasureElement = new LineElementClass(); tempMeasureElement.Geometry = polyline; ((ILineElement)tempMeasureElement).Symbol = lineSymbol; // 添加到地图 IGraphicsContainer graphics = axMapControl1.Map as IGraphicsContainer; if (graphics != null) { graphics.AddElement(tempMeasureElement, 0); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } } catch (Exception ex) { Console.WriteLine("量测预览错误: " + ex.Message); } } // 清除临时量测图形 private void ClearTempMeasureElement() { if (tempMeasureElement != null) { IGraphicsContainer graphics = axMapControl1.Map as IGraphicsContainer; if (graphics != null) { graphics.DeleteElement(tempMeasureElement); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } tempMeasureElement = null; } } // 处理量测模式 private void HandleMeasureMode(IMapControlEvents2_OnMouseDownEvent e) { try { // 获取当前鼠标位置 IPoint point = axMapControl1.ToMapPoint(e.x, e.y); // 左键添加点 if (e.button == 1) { switch (currentMeasureMode) { case MeasureMode.PolygonArea: case MeasureMode.PolygonPerimeter: case MeasureMode.PolylineLength: measurePoints.Add(point); break; case MeasureMode.PointCoordinate: CompletePointMeasure(point); break; } } // 右键完成量测 else if (e.button == 2) { switch (currentMeasureMode) { case MeasureMode.PolygonArea: CompletePolygonMeasure(true); break; case MeasureMode.PolygonPerimeter: CompletePolygonMeasure(false); break; case MeasureMode.PolylineLength: CompletePolylineMeasure(); break; } } } catch (Exception ex) { MessageBox.Show("量测错误: " + ex.Message); } } // 完成多边形量测 private void CompletePolygonMeasure(bool isArea) { if (measurePoints.Count < 3) { MessageBox.Show("多边形至少需要3个顶点"); return; } try { // 创建最终多边形 IPolygon polygon = CreatePolygon(measurePoints); if (polygon == null || polygon.IsEmpty) { MessageBox.Show("无法创建有效多边形"); return; } // 计算量测结果 IArea area = polygon as IArea; double result = 0; string unit = ""; string title = ""; if (isArea) { // 面积量测 result = area.Area; // 平方米 unit = "平方米"; title = "面积量测结果"; } else { // 周长量测 ICurve curve = polygon as ICurve; result = curve.Length; // 米 unit = "米"; title = "周长量测结果"; } // 构建结果消息 string message = string.Format("{0:0.##} {1}", result, unit); if (isArea) { double hectareArea = result / 10000; // 公顷 message += string.Format("\n{0:0.##} 公顷", hectareArea); } else { double kilometer = result / 1000; // 千米 message += string.Format("\n{0:0.##} 千米", kilometer); } // 使用自定义窗体显示结果 ShowMeasureResult(title, message); // 绘制最终量测图形 DrawFinalMeasureElement(polygon, isArea); } catch (Exception ex) { MessageBox.Show("量测出错: " + ex.Message); } finally { // 结束量测模式 EndMeasureMode(); } } // 完成折线量测 private void CompletePolylineMeasure() { if (measurePoints.Count < 2) { MessageBox.Show("折线至少需要2个顶点"); return; } try { // 创建最终折线 IPolyline polyline = CreatePolyline(measurePoints); if (polyline == null || polyline.IsEmpty) { MessageBox.Show("无法创建有效折线"); return; } // 计算长度 ICurve curve = polyline as ICurve; double length = curve.Length; // 米 double kilometer = length / 1000; // 千米 // 构建结果消息 string message = string.Format("{0:0.##} 米\n{1:0.##} 千米", length, kilometer); // 使用自定义窗体显示结果 ShowMeasureResult("长度量测结果", message); // 绘制最终量测图形 DrawFinalMeasureElement(polyline); } catch (Exception ex) { MessageBox.Show("量测出错: " + ex.Message); } finally { // 结束量测模式 EndMeasureMode(); } } // 完成点坐标量测 private void CompletePointMeasure(IPoint point) { try { // 获取坐标系信息 string coordSystem = "未知坐标系"; if (axMapControl1.SpatialReference != null) { coordSystem = axMapControl1.SpatialReference.Name; } // 构建结果消息 string message = string.Format("X: {0:0.###}\nY: {1:0.###}\n\n坐标系: {2}", point.X, point.Y, coordSystem); // 使用自定义窗体显示结果 ShowMeasureResult("坐标量测结果", message); // 绘制点标记 DrawPointMarker(point); } catch (Exception ex) { MessageBox.Show("量测出错: " + ex.Message); } finally { // 结束量测模式 EndMeasureMode(); } } // 绘制最终量测图形 private void DrawFinalMeasureElement(IGeometry geometry, bool isArea = true) { IGraphicsContainer graphics = axMapControl1.Map as IGraphicsContainer; if (graphics == null) return; IElement element = null; if (geometry is IPolygon) { // 创建符号(蓝色边框,半透明填充) ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = GetRgbColor(0, 0, 255); // 蓝色 lineSymbol.Width = 2; ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Outline = lineSymbol; fillSymbol.Color = GetRgbColor(0, 255, 255, 100); // 青色半透明 // 创建元素 element = new PolygonElementClass(); element.Geometry = geometry; ((IFillShapeElement)element).Symbol = fillSymbol; } else if (geometry is IPolyline) { // 创建符号(红色粗线) ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = GetRgbColor(255, 0, 0); // 红色 lineSymbol.Width = 3; // 创建元素 element = new LineElementClass(); element.Geometry = geometry; ((ILineElement)element).Symbol = lineSymbol; } if (element != null) { // 添加到地图 graphics.AddElement(element, 0); measurementElements.Add(element); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } } // 绘制点标记 private void DrawPointMarker(IPoint point) { IGraphicsContainer graphics = axMapControl1.Map as IGraphicsContainer; if (graphics == null) return; // 创建符号(绿色十字) ISimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbolClass(); markerSymbol.Style = esriSimpleMarkerStyle.esriSMSCross; markerSymbol.Color = GetRgbColor(0, 255, 0); // 绿色 markerSymbol.Size = 12; markerSymbol.Outline = true; markerSymbol.OutlineColor = GetRgbColor(0, 0, 0); // 黑色边框 markerSymbol.OutlineSize = 1; // 创建元素 IMarkerElement markerElement = new MarkerElementClass(); markerElement.Symbol = markerSymbol; ((IElement)markerElement).Geometry = point; // 添加到地图 graphics.AddElement((IElement)markerElement, 0); measurementElements.Add((IElement)markerElement); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } // 清除已绘制图形 private void 清除已绘制图形ToolStripMenuItem_Click(object sender, EventArgs e) { ClearMeasurementGraphics(); } // 清除量测图形 private void ClearMeasurementGraphics() { try { IActiveView activeView = axMapControl1.ActiveView; IGraphicsContainer graphics = activeView.GraphicsContainer; if (graphics == null) return; // 删除所有量测图形元素 foreach (IElement element in measurementElements) { graphics.DeleteElement(element); } // 清空列表 measurementElements.Clear(); // 强制刷新地图视图 activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); activeView.Refresh(); lblStatus.Text = "已清除所有量测图形"; } catch (Exception ex) { MessageBox.Show("清除图形时出错: " + ex.Message); } } // 在 Form1 类中添加新方法 private void ShowMeasureResult(string title, string message) { using (MeasureResultForm resultForm = new MeasureResultForm(title, message)) { resultForm.ShowDialog(this); } } } }namespace WaterPipelineGIS2 { partial class main { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(main)); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem5 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem6 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem7 = new System.Windows.Forms.ToolStripMenuItem(); this.清除选择ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.空间量测ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.面积量测ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.周长量测ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.点坐标量测ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.清除已绘制图形ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.panel1 = new System.Windows.Forms.Panel(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.groupBoxEagleEye = new System.Windows.Forms.GroupBox(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.lblCoordinate = new System.Windows.Forms.ToolStripStatusLabel(); this.lblResult = new System.Windows.Forms.ToolStripStatusLabel(); this.axLicenseControl1 = new ESRI.ArcGIS.Controls.AxLicenseControl(); this.txtRotateAngle = new System.Windows.Forms.ToolStripTextBox(); this.contextMenuStripTOC = new System.Windows.Forms.ContextMenuStrip(this.components); this.openAttributeTableToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.axMapControl2 = new ESRI.ArcGIS.Controls.AxMapControl(); this.axTOCControl1 = new ESRI.ArcGIS.Controls.AxTOCControl(); this.axMapControl1 = new ESRI.ArcGIS.Controls.AxMapControl(); this.axToolbarControl1 = new ESRI.ArcGIS.Controls.AxToolbarControl(); this.折线周长量测ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); this.menuStrip1.SuspendLayout(); this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); this.groupBoxEagleEye.SuspendLayout(); this.statusStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).BeginInit(); this.contextMenuStripTOC.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.axMapControl2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.axTOCControl1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.axMapControl1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.axToolbarControl1)).BeginInit(); this.SuspendLayout(); // // menuStrip1 // this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItem1}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(1042, 32); this.menuStrip1.TabIndex = 0; this.menuStrip1.Text = "menuStrip1"; // // toolStripMenuItem1 // this.toolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItem2, this.toolStripMenuItem3, this.空间量测ToolStripMenuItem}); this.toolStripMenuItem1.Name = "toolStripMenuItem1"; this.toolStripMenuItem1.Size = new System.Drawing.Size(58, 28); this.toolStripMenuItem1.Text = "功能"; // // toolStripMenuItem2 // this.toolStripMenuItem2.Name = "toolStripMenuItem2"; this.toolStripMenuItem2.Size = new System.Drawing.Size(152, 28); this.toolStripMenuItem2.Text = "地图旋转"; this.toolStripMenuItem2.Click += new System.EventHandler(this.toolStripMenuItem2_Click); // // toolStripMenuItem3 // this.toolStripMenuItem3.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItem4, this.toolStripMenuItem5, this.toolStripMenuItem6, this.toolStripMenuItem7, this.清除选择ToolStripMenuItem}); this.toolStripMenuItem3.Name = "toolStripMenuItem3"; this.toolStripMenuItem3.Size = new System.Drawing.Size(152, 28); this.toolStripMenuItem3.Text = "空间选择"; // // toolStripMenuItem4 // this.toolStripMenuItem4.Name = "toolStripMenuItem4"; this.toolStripMenuItem4.Size = new System.Drawing.Size(206, 28); this.toolStripMenuItem4.Text = "绘制矩形选择"; this.toolStripMenuItem4.Click += new System.EventHandler(this.btnRectSelect_Click); // // toolStripMenuItem5 // this.toolStripMenuItem5.Name = "toolStripMenuItem5"; this.toolStripMenuItem5.Size = new System.Drawing.Size(206, 28); this.toolStripMenuItem5.Text = "绘制圆形选择"; this.toolStripMenuItem5.Click += new System.EventHandler(this.btnCircleSelect_Click); // // toolStripMenuItem6 // this.toolStripMenuItem6.Name = "toolStripMenuItem6"; this.toolStripMenuItem6.Size = new System.Drawing.Size(206, 28); this.toolStripMenuItem6.Text = "绘制多边形选择"; this.toolStripMenuItem6.Click += new System.EventHandler(this.btnPolygonSelect_Click); // // toolStripMenuItem7 // this.toolStripMenuItem7.Name = "toolStripMenuItem7"; this.toolStripMenuItem7.Size = new System.Drawing.Size(206, 28); this.toolStripMenuItem7.Text = "绘制折线选择"; this.toolStripMenuItem7.Click += new System.EventHandler(this.btnLineSelect_Click); // // 清除选择ToolStripMenuItem // this.清除选择ToolStripMenuItem.Name = "清除选择ToolStripMenuItem"; this.清除选择ToolStripMenuItem.Size = new System.Drawing.Size(206, 28); this.清除选择ToolStripMenuItem.Text = "清除选择"; this.清除选择ToolStripMenuItem.Click += new System.EventHandler(this.btnClearSelection_Click); // // 空间量测ToolStripMenuItem // this.空间量测ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.面积量测ToolStripMenuItem, this.周长量测ToolStripMenuItem, this.折线周长量测ToolStripMenuItem, this.点坐标量测ToolStripMenuItem, this.清除已绘制图形ToolStripMenuItem}); this.空间量测ToolStripMenuItem.Name = "空间量测ToolStripMenuItem"; this.空间量测ToolStripMenuItem.Size = new System.Drawing.Size(152, 28); this.空间量测ToolStripMenuItem.Text = "空间量测"; // // 面积量测ToolStripMenuItem // this.面积量测ToolStripMenuItem.Name = "面积量测ToolStripMenuItem"; this.面积量测ToolStripMenuItem.Size = new System.Drawing.Size(206, 28); this.面积量测ToolStripMenuItem.Text = "面积量测"; this.面积量测ToolStripMenuItem.Click += new System.EventHandler(this.面积量测ToolStripMenuItem_Click); // // 周长量测ToolStripMenuItem // this.周长量测ToolStripMenuItem.Name = "周长量测ToolStripMenuItem"; this.周长量测ToolStripMenuItem.Size = new System.Drawing.Size(206, 28); this.周长量测ToolStripMenuItem.Text = "周长量测"; this.周长量测ToolStripMenuItem.Click += new System.EventHandler(this.周长量测ToolStripMenuItem_Click); // // 点坐标量测ToolStripMenuItem // this.点坐标量测ToolStripMenuItem.Name = "点坐标量测ToolStripMenuItem"; this.点坐标量测ToolStripMenuItem.Size = new System.Drawing.Size(206, 28); this.点坐标量测ToolStripMenuItem.Text = "点坐标量测"; this.点坐标量测ToolStripMenuItem.Click += new System.EventHandler(this.点坐标量测ToolStripMenuItem_Click); // // 清除已绘制图形ToolStripMenuItem // this.清除已绘制图形ToolStripMenuItem.Name = "清除已绘制图形ToolStripMenuItem"; this.清除已绘制图形ToolStripMenuItem.Size = new System.Drawing.Size(206, 28); this.清除已绘制图形ToolStripMenuItem.Text = "清除已绘制图形"; this.清除已绘制图形ToolStripMenuItem.Click += new System.EventHandler(this.清除已绘制图形ToolStripMenuItem_Click); // // panel1 // this.panel1.Controls.Add(this.splitContainer1); this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; this.panel1.Location = new System.Drawing.Point(0, 60); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(1042, 585); this.panel1.TabIndex = 2; // // splitContainer1 // this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer1.Location = new System.Drawing.Point(0, 0); this.splitContainer1.Name = "splitContainer1"; // // splitContainer1.Panel1 // this.splitContainer1.Panel1.Controls.Add(this.groupBoxEagleEye); this.splitContainer1.Panel1.Controls.Add(this.axTOCControl1); // // splitContainer1.Panel2 // this.splitContainer1.Panel2.Controls.Add(this.statusStrip1); this.splitContainer1.Panel2.Controls.Add(this.axLicenseControl1); this.splitContainer1.Panel2.Controls.Add(this.axMapControl1); this.splitContainer1.Size = new System.Drawing.Size(1042, 585); this.splitContainer1.SplitterDistance = 247; this.splitContainer1.TabIndex = 0; // // groupBoxEagleEye // this.groupBoxEagleEye.Controls.Add(this.axMapControl2); this.groupBoxEagleEye.Dock = System.Windows.Forms.DockStyle.Bottom; this.groupBoxEagleEye.Location = new System.Drawing.Point(0, 261); this.groupBoxEagleEye.Name = "groupBoxEagleEye"; this.groupBoxEagleEye.Size = new System.Drawing.Size(247, 324); this.groupBoxEagleEye.TabIndex = 2; this.groupBoxEagleEye.TabStop = false; this.groupBoxEagleEye.Text = "鹰眼导航"; // // statusStrip1 // this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.lblCoordinate, this.lblResult, this.toolStripStatusLabel1}); this.statusStrip1.Location = new System.Drawing.Point(0, 556); this.statusStrip1.Name = "statusStrip1"; this.statusStrip1.Padding = new System.Windows.Forms.Padding(2, 0, 14, 0); this.statusStrip1.Size = new System.Drawing.Size(791, 29); this.statusStrip1.TabIndex = 0; this.statusStrip1.Text = "statusStrip1"; // // lblCoordinate // this.lblCoordinate.Name = "lblCoordinate"; this.lblCoordinate.Size = new System.Drawing.Size(644, 24); this.lblCoordinate.Spring = true; this.lblCoordinate.Text = "lblCoordinate"; this.lblCoordinate.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // lblResult // this.lblResult.Name = "lblResult"; this.lblResult.Size = new System.Drawing.Size(85, 24); this.lblResult.Text = "lblResult"; // // axLicenseControl1 // this.axLicenseControl1.Enabled = true; this.axLicenseControl1.Location = new System.Drawing.Point(757, 528); this.axLicenseControl1.Name = "axLicenseControl1"; this.axLicenseControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axLicenseControl1.OcxState"))); this.axLicenseControl1.Size = new System.Drawing.Size(32, 32); this.axLicenseControl1.TabIndex = 1; // // txtRotateAngle // this.txtRotateAngle.Name = "txtRotateAngle"; this.txtRotateAngle.Size = new System.Drawing.Size(100, 23); // // contextMenuStripTOC // this.contextMenuStripTOC.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.openAttributeTableToolStripMenuItem}); this.contextMenuStripTOC.Name = "contextMenuStripTOC"; this.contextMenuStripTOC.Size = new System.Drawing.Size(171, 32); // // openAttributeTableToolStripMenuItem // this.openAttributeTableToolStripMenuItem.Name = "openAttributeTableToolStripMenuItem"; this.openAttributeTableToolStripMenuItem.Size = new System.Drawing.Size(170, 28); this.openAttributeTableToolStripMenuItem.Text = "打开属性表"; this.openAttributeTableToolStripMenuItem.Click += new System.EventHandler(this.openAttributeTableToolStripMenuItem_Click); // // axMapControl2 // this.axMapControl2.Dock = System.Windows.Forms.DockStyle.Fill; this.axMapControl2.Location = new System.Drawing.Point(3, 24); this.axMapControl2.Name = "axMapControl2"; this.axMapControl2.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMapControl2.OcxState"))); this.axMapControl2.Size = new System.Drawing.Size(241, 297); this.axMapControl2.TabIndex = 0; // // axTOCControl1 // this.axTOCControl1.Dock = System.Windows.Forms.DockStyle.Fill; this.axTOCControl1.Location = new System.Drawing.Point(0, 0); this.axTOCControl1.Name = "axTOCControl1"; this.axTOCControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axTOCControl1.OcxState"))); this.axTOCControl1.Size = new System.Drawing.Size(247, 585); this.axTOCControl1.TabIndex = 0; this.axTOCControl1.OnMouseDown += new ESRI.ArcGIS.Controls.ITOCControlEvents_Ax_OnMouseDownEventHandler(this.axTOCControl1_OnMouseDown); // // axMapControl1 // this.axMapControl1.Dock = System.Windows.Forms.DockStyle.Fill; this.axMapControl1.Location = new System.Drawing.Point(0, 0); this.axMapControl1.Name = "axMapControl1"; this.axMapControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMapControl1.OcxState"))); this.axMapControl1.Size = new System.Drawing.Size(791, 585); this.axMapControl1.TabIndex = 0; this.axMapControl1.OnMouseDown += new ESRI.ArcGIS.Controls.IMapControlEvents2_Ax_OnMouseDownEventHandler(this.axMapControl1_OnMouseDown); this.axMapControl1.OnMouseMove += new ESRI.ArcGIS.Controls.IMapControlEvents2_Ax_OnMouseMoveEventHandler(this.axMapControl1_OnMouseMove); this.axMapControl1.OnDoubleClick += new ESRI.ArcGIS.Controls.IMapControlEvents2_Ax_OnDoubleClickEventHandler(this.axMapControl1_OnDoubleClick); // // axToolbarControl1 // this.axToolbarControl1.Dock = System.Windows.Forms.DockStyle.Top; this.axToolbarControl1.Location = new System.Drawing.Point(0, 32); this.axToolbarControl1.Name = "axToolbarControl1"; this.axToolbarControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axToolbarControl1.OcxState"))); this.axToolbarControl1.Size = new System.Drawing.Size(1042, 28); this.axToolbarControl1.TabIndex = 1; // // 折线周长量测ToolStripMenuItem // this.折线周长量测ToolStripMenuItem.Name = "折线周长量测ToolStripMenuItem"; this.折线周长量测ToolStripMenuItem.Size = new System.Drawing.Size(206, 28); this.折线周长量测ToolStripMenuItem.Text = "折线周长量测"; this.折线周长量测ToolStripMenuItem.Click += new System.EventHandler(this.折线周长量测ToolStripMenuItem_Click); // // toolStripStatusLabel1 // this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; this.toolStripStatusLabel1.Size = new System.Drawing.Size(46, 24); this.toolStripStatusLabel1.Text = "就绪"; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1042, 645); this.Controls.Add(this.panel1); this.Controls.Add(this.axToolbarControl1); this.Controls.Add(this.menuStrip1); this.MainMenuStrip = this.menuStrip1; this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "供水管网地理信息系统"; this.WindowState = System.Windows.Forms.FormWindowState.Maximized; this.Load += new System.EventHandler(this.Form1_Load); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.panel1.ResumeLayout(false); this.splitContainer1.Panel1.ResumeLayout(false); this.splitContainer1.Panel2.ResumeLayout(false); this.splitContainer1.Panel2.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); this.groupBoxEagleEye.ResumeLayout(false); this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).EndInit(); this.contextMenuStripTOC.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.axMapControl2)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.axTOCControl1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.axMapControl1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.axToolbarControl1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.MenuStrip menuStrip1; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; private ESRI.ArcGIS.Controls.AxToolbarControl axToolbarControl1; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.SplitContainer splitContainer1; private ESRI.ArcGIS.Controls.AxMapControl axMapControl1; private System.Windows.Forms.StatusStrip statusStrip1; private ESRI.ArcGIS.Controls.AxLicenseControl axLicenseControl1; private ESRI.ArcGIS.Controls.AxTOCControl axTOCControl1; private System.Windows.Forms.ToolStripStatusLabel lblCoordinate; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2; private System.Windows.Forms.ToolStripTextBox txtRotateAngle; private System.Windows.Forms.GroupBox groupBoxEagleEye; private ESRI.ArcGIS.Controls.AxMapControl axMapControl2; private System.Windows.Forms.ContextMenuStrip contextMenuStripTOC; private System.Windows.Forms.ToolStripMenuItem openAttributeTableToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem3; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem4; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem5; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem6; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem7; private System.Windows.Forms.ToolStripMenuItem 清除选择ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 空间量测ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 面积量测ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 周长量测ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 点坐标量测ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 清除已绘制图形ToolStripMenuItem; private System.Windows.Forms.ToolStripStatusLabel lblResult; private System.Windows.Forms.ToolStripMenuItem 折线周长量测ToolStripMenuItem; private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; } } 此代码我想实现鹰眼导航(即在此代码中,mapcontrol控件(axMapControl1)中显示的是主地图,而左下角的mapcontrol控件(axMapControl2)进行鹰眼导航,axMapControl1中的视野范围在axMapControl2中用深蓝色边框进行框起来。无论是主视图大小缩放还是通过鼠标移动视角,在axMapControl2都要跟着框起来,他固定不动但是蓝色边框跟着移动)注意我的vs版本为2010,给出完整的修改代码,要细致的修改操作教程
最新发布
07-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值