Commit 12f74f46 HZH

组织结构图增加节点右键菜单

1 个父辈 bc45151d
......@@ -31,6 +31,14 @@ namespace HZH_Controls.Controls
/// <seealso cref="System.Windows.Forms.UserControl" />
internal class UCMindMapping : UserControl
{
private ContextMenuStrip itemContextMenuStrip;
[Description("节点关联的右键菜单"), Category("自定义")]
public ContextMenuStrip ItemContextMenuStrip
{
get { return itemContextMenuStrip; }
set { itemContextMenuStrip = value; }
}
private Color itemBackcolor = Color.FromArgb(255, 77, 59);
[Description("节点背景色,优先级小于数据源中设置的背景色"), Category("自定义")]
......@@ -84,6 +92,14 @@ namespace HZH_Controls.Controls
/// The data source
/// </summary>
private MindMappingItemEntity dataSource;
private MindMappingItemEntity selectEntity;
[Description("选中的数据源"), Category("自定义")]
public MindMappingItemEntity SelectEntity
{
get { return selectEntity; }
private set { selectEntity = value; }
}
/// <summary>
/// Gets or sets the data source.
/// </summary>
......@@ -114,8 +130,11 @@ namespace HZH_Controls.Controls
this.Click += UCMindMapping_Click;
this.DoubleClick += UCMindMapping_DoubleClick;
this.Load += UCMindMapping_Load;
this.MouseClick += UCMindMapping_MouseClick;
}
/// <summary>
/// Handles the Load event of the UCMindMapping control.
/// </summary>
......@@ -142,7 +161,7 @@ namespace HZH_Controls.Controls
{
var mouseLocation = this.PointToClient(Control.MousePosition);
bool bln = CheckExpansionDoubleClick(dataSource, mouseLocation);
bool bln = CheckDrawRectClick(dataSource, mouseLocation);
if (bln)
{
ResetSize();
......@@ -167,13 +186,25 @@ namespace HZH_Controls.Controls
}
}
void UCMindMapping_MouseClick(object sender, MouseEventArgs e)
{
if (itemContextMenuStrip != null && e.Button == System.Windows.Forms.MouseButtons.Right)
{
bool bln = CheckDrawRectClick(dataSource, e.Location, false);
if (bln)
{
itemContextMenuStrip.Show(this.PointToScreen(e.Location));
}
}
}
/// <summary>
/// 双击检查
/// </summary>
/// <param name="item">The item.</param>
/// <param name="mouseLocation">The mouse location.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
private bool CheckExpansionDoubleClick(MindMappingItemEntity item, Point mouseLocation)
private bool CheckDrawRectClick(MindMappingItemEntity item, Point mouseLocation, bool blnDoExpansion = true)
{
if (item == null)
return false;
......@@ -181,14 +212,15 @@ namespace HZH_Controls.Controls
{
if (item.DrawRectangle.Contains(mouseLocation))
{
item.IsExpansion = !item.IsExpansion;
if (blnDoExpansion)
item.IsExpansion = !item.IsExpansion;
return true;
}
if (item.Childrens != null && item.Childrens.Length > 0)
{
foreach (var child in item.Childrens)
{
var bln = CheckExpansionDoubleClick(child, mouseLocation);
var bln = CheckDrawRectClick(child, mouseLocation, blnDoExpansion);
if (bln)
return bln;
}
......@@ -209,10 +241,15 @@ namespace HZH_Controls.Controls
return false;
else
{
if (ItemClicked != null && item.DrawRectangle.Contains(mouseLocation))
if (item.DrawRectangle.Contains(mouseLocation))
{
ItemClicked(item, null);
selectEntity = item;
if (ItemClicked != null )
{
ItemClicked(item, null);
}
}
if (item.ExpansionRectangle.Contains(mouseLocation))
{
item.IsExpansion = !item.IsExpansion;
......
......@@ -29,9 +29,23 @@ namespace HZH_Controls.Controls
/// Implements the <see cref="System.Windows.Forms.UserControl" />
/// </summary>
/// <seealso cref="System.Windows.Forms.UserControl" />
[DefaultEvent("ItemClicked")]
public partial class UCMindMappingPanel : UserControl
{
private ContextMenuStrip itemContextMenuStrip;
[Description("节点关联的右键菜单"), Category("自定义")]
public ContextMenuStrip ItemContextMenuStrip
{
get { return itemContextMenuStrip; }
set
{
itemContextMenuStrip = value;
this.ucMindMapping1.ItemContextMenuStrip = value;
}
}
private Color itemBackcolor = Color.FromArgb(255, 77, 59);
[Description("节点背景色,优先级小于数据源中设置的背景色"), Category("自定义")]
......@@ -89,6 +103,14 @@ namespace HZH_Controls.Controls
this.ucMindMapping1.LineColor = value;
}
}
[Description("选中的数据源"), Category("自定义")]
public MindMappingItemEntity SelectEntity
{
get { return ucMindMapping1.SelectEntity; }
}
/// <summary>
/// Initializes a new instance of the <see cref="UCMindMappingPanel"/> class.
/// </summary>
......
......@@ -28,19 +28,41 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.aaaaaToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ucMindMappingPanel1 = new HZH_Controls.Controls.UCMindMappingPanel();
this.contextMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
// contextMenuStrip1
//
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.aaaaaToolStripMenuItem});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(153, 48);
//
// aaaaaToolStripMenuItem
//
this.aaaaaToolStripMenuItem.Name = "aaaaaToolStripMenuItem";
this.aaaaaToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.aaaaaToolStripMenuItem.Text = "更改随机文本";
this.aaaaaToolStripMenuItem.Click += new System.EventHandler(this.aaaaaToolStripMenuItem_Click);
//
// ucMindMappingPanel1
//
this.ucMindMappingPanel1.AutoScroll = true;
this.ucMindMappingPanel1.BackColor = System.Drawing.Color.White;
this.ucMindMappingPanel1.DataSource = null;
this.ucMindMappingPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.ucMindMappingPanel1.ItemBackcolor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
this.ucMindMappingPanel1.ItemContextMenuStrip = this.contextMenuStrip1;
this.ucMindMappingPanel1.LineColor = System.Drawing.Color.Black;
this.ucMindMappingPanel1.Location = new System.Drawing.Point(0, 0);
this.ucMindMappingPanel1.Name = "ucMindMappingPanel1";
this.ucMindMappingPanel1.Size = new System.Drawing.Size(654, 566);
this.ucMindMappingPanel1.TabIndex = 0;
this.ucMindMappingPanel1.ItemClicked += new System.EventHandler(this.ucMindMappingPanel1_ItemClicked);
//
// Form5
//
......@@ -51,6 +73,7 @@
this.Name = "Form5";
this.Text = "Form5";
this.Load += new System.EventHandler(this.Form5_Load);
this.contextMenuStrip1.ResumeLayout(false);
this.ResumeLayout(false);
}
......@@ -58,5 +81,7 @@
#endregion
private HZH_Controls.Controls.UCMindMappingPanel ucMindMappingPanel1;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem aaaaaToolStripMenuItem;
}
}
\ No newline at end of file
......@@ -60,5 +60,16 @@ namespace Test
MessageBox.Show(exc.ToString(), "错误");
}
}
private void ucMindMappingPanel1_ItemClicked(object sender, EventArgs e)
{
HZH_Controls.Forms.FrmTips.ShowTipsSuccess(this, ucMindMappingPanel1.SelectEntity.Text);
}
private void aaaaaToolStripMenuItem_Click(object sender, EventArgs e)
{
ucMindMappingPanel1.SelectEntity.Text = Guid.NewGuid().ToString();
ucMindMappingPanel1.Refresh();
}
}
}
......@@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
\ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!