我正在Controls
中创建一组UserControl
。但是第二个UserControl
的边界也会围绕第一个绘制的UserControl
绘制。
这里有一段视频来说明我的意思:https://vid.me/e/rZ3N如何才能使边框仅围绕UserControl
本身绘制?
这是我将UserControl
添加到
Controls
类
public class GroupUserControl : UserControl
{
private Point mDown { get; set; }
private Point conLoc { get; set; }
public GroupUserControl()
{
AutoSize = true;
BorderStyle = BorderStyle.FixedSingle;
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
mDown = e.Location;
conLoc = this.Location;
}
protected override void OnMouseMove(MouseEventArgs e)
{
// Call MyBase.OnMouseMove to activate the delegate.
base.OnMouseMove(e);
if (e.Button == MouseButtons.Left)
{
Location = new Point(e.X + Left - mDown.X, e.Y + Top - mDown.Y);
}
}
}
TreeView
拖放方法
private void shapeTreeView_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", true))
{
// node exists in drag data payload
Point pt = this.shapeTreeView.PointToClient(new Point(e.X, e.Y));
// Get a handle to the destination node. This will become the parent of our new node.
TreeNode DestinationNode = this.shapeTreeView.GetNodeAt(pt);
// Create the new node based on the dragged node
TreeNode newNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
// Check destination mode
if (!(DestinationNode == newNode) && DestinationNode.Text=="Group")
{
TreeNode newNodeClone = (TreeNode)newNode.Clone();//add
// add a clone
//DestinationNode.Nodes.Add((TreeNode)newNode.Clone());
DestinationNode.Nodes.Add(newNodeClone);
// expand the new node
DestinationNode.Expand();
// remove the original node
newNode.Remove();
//add - create groups of controls drag under construction
if (newNodeClone.PrevNode != null)
{
Control prevControl = (Control)newNodeClone.PrevNode.Tag;
Control control = (Control)newNodeClone.Tag;
var compositeGraphic = (CompositeGraphic)DestinationNode.Tag;
if (!compositeGraphic.uc.Contains(prevControl))
{
compositeGraphic.uc.Controls.Add(prevControl);
}
if (!compositeGraphic.uc.Controls.Contains(control))
{
compositeGraphic.uc.Controls.Add(control);
}
if (!panel.Controls.Contains(compositeGraphic.uc))
{
panel.Controls.Add(compositeGraphic.uc);
}
}
var parent = newNodeClone.Parent;
if (parent == null)
{
return;
}
else
{
var compositeGraphic = (CompositeGraphic)DestinationNode.Tag/*newNodeClone.Parent.Tag*/; //Kan ook veranderd naar destination node >?
string shapeType = newNodeClone.Text;
switch (shapeType)
{
case "Ellipse":
Ellipse el = (Ellipse)newNodeClone.Tag;
compositeGraphic.Add(el);
break;
case "Box":
Box b = (Box)newNodeClone.Tag;
compositeGraphic.Add(b);
break;
}
//compositeGraphic.Print();
}
}