马甲贴 - - 类似于visio的工具栏的控件的开发
项目实现一个类似Visio工具栏的控件,线条和基本的图形已经弄出来了。就是可以拖出来调节等。但是我想知道visio中那些连接点都是很智能的连接的这种功能如何实现?
大家有思路没思路的都来说说啊,。 --------------------编程问答-------------------- 为每个图形添加连接点,捕获到连接线端点位置与图形重合就重绘连接线...
有多个连接点时,计算一下距离最近的连接点再重绘连接线... --------------------编程问答-------------------- 帮顶。。。 --------------------编程问答-------------------- 帮顶一下吧! --------------------编程问答-------------------- 像二楼说的,连接点进行判断 --------------------编程问答-------------------- 哥每天看贴无数,看多了,精神颓废了,自信消失了,尊严感也快殆尽了,从前自以为是特别爱国的人之一、是最关心民族命运的人之一,后来发现自己不过是小小的普通百姓,自己的命运都不能掌控,还在考虑国家大事,有一点可笑,是不是自己疯了,变成阿Q了。回帖也就发发牢骚而已,宛如疯子边走边唱,即使路人听到也是露出鄙夷的神色,于事无补。从此我就把这段文字保存在记事本里,每看一贴就复制粘贴一次,顺便留下自己沉重而又疲惫的影子.. --------------------编程问答--------------------
联想的真够远的 --------------------编程问答--------------------
--------------------编程问答-------------------- 顶顶顶 --------------------编程问答--------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace AutoDiagramer
{
#region AssociationDrawer CLASS
/// <summary>
/// This class simply draws a single association line between
/// a source <see cref="DrawableClass">class</see> and a
/// destination <see cref="DrawableClass">class</see>. The line
/// is drawn using the Graphics object of the
/// <see cref="ClassDrawerContainerPanel"> ClassDrawerContainerPanel
/// </see>, where all the classes are contained
/// </summary>
public class AssociationDrawer
{
#region Instance fields
//instance fields
private DrawableClass _ucdSrc = null;
private DrawableClass _ucdDest = null;
private int _XLeft=-1;
private int _XThis=-1;
private int _GenericSpace=0;
private Graphics _g = null;
public enum AssociationDirections { North,South,East,West,NorthNonDirect,
SouthNonDirect, EastNonDirect, WestNonDirect,
NorthEast,SouthEast,NorthWest,SouthWest,NOTRECOGNIZED };
// private AssociationDirections _CurrAssDirection = AssociationDirections.NOTRECOGNIZED;
private int _RandomLineOffSet = 10;
#endregion
#region Constructor
/// <summary>
/// Creates a new AssociationDrawer object using the parameters provided and
/// then calls the internal Draw() method
/// </summary>
/// <param name="g">The graphics object of the <see cref="ClassDrawerContainerPanel">
/// ClassDrawerContainerPanel</see>, so that this class can draw an association
/// line on the panel where the classes are held</param>
/// <param name="ucdSrc">The source <see cref="DrawableClass">class</see></param>
/// <param name="ucdDest">The destination <see cref="DrawableClass">class</see></param>
/// <param name="genericSpace">The generic space between classes used by the
/// <see cref="ClassDrawerContainerPanel">ClassDrawerContainerPanel</see>
/// when laying out the controls</param>
/// <param name="_XLeft">The X-Pos of the widest control in the column to the left of the ucdSrc control</param>
/// <param name="_XThis">The X-Pos of the widest control in the column of the ucdSrc control</param>
public AssociationDrawer(Graphics g, DrawableClass ucdSrc, DrawableClass ucdDest,int genericSpace,int _XLeft,int _XThis)
{
this._ucdSrc = ucdSrc;
this._ucdDest = ucdDest;
this._GenericSpace = genericSpace;
this._g = g;
this._XLeft = _XLeft;
this._XThis = _XThis;
//do the draw
GetDirectionAndDraw();
}
#endregion
#region Private Methods
/// <summary>
/// Works out which direction the association line should be based
/// on the source <see cref="DrawableClass">class</see> ContainerRow/
/// ContainerColumn and the destination <see cref="DrawableClass">class</see>
/// ContainerRow/ ContainerColumn. When the direction is found, one of the Draw
/// direction methods is called, for example DrawNorth(), DrawSouth()
/// </summary>
--------------------编程问答--------------------
/// <summary>
/// Draws a NorthWest OR SouthWest association line and arrow
/// </summary>
private void DrawNorthWest_DrawSouthWest()
{
int xStart = _ucdSrc.Left;
int yStart = _ucdSrc.Top + 40;
int xEnd = _ucdSrc.Left - (_GenericSpace - (_RandomLineOffSet + Program.GetRandom(_RandomLineOffSet)));
int yEnd = _ucdSrc.Top + 40;
//create a dasked line
Pen p = new Pen(new SolidBrush(Color.Black));
p.DashStyle = DashStyle.Dash;
//line across
_g.DrawLine(p, new Point(xStart, yStart), new Point(xEnd, yEnd));
//see if we need to draw up and along then up again for NorthWest
// <----
// |
// |
// |_____
// |
//
// OR see if we need to draw down and along then down again for SouthWest
//
// _____|
// |
// |
// <----
if (_ucdSrc.ContainerColumn - _ucdDest.ContainerColumn > 1)
{
//line up
xStart = xEnd;
yStart = yEnd;
//if its the very first row, make sure line is actually visible
if (_ucdSrc.ContainerRow != 0)
{
yEnd = _ucdSrc.Top - (_GenericSpace - (_RandomLineOffSet + Program.GetRandom(_RandomLineOffSet)));
}
else
{
yEnd = _ucdSrc.Top - (_GenericSpace - 10);
}
_g.DrawLine(p, new Point(xStart, yStart), new Point(xEnd, yEnd));
//line across
xStart = xEnd;
yStart = yEnd;
xEnd = _XLeft + (_GenericSpace - (_RandomLineOffSet + Program.GetRandom(_RandomLineOffSet))) ;
_g.DrawLine(p, new Point(xStart, yStart), new Point(xEnd, yEnd));
//line up
xStart = xEnd;
yStart = yEnd;
yEnd = _ucdDest.Top + 40;
_g.DrawLine(p, new Point(xStart, yStart), new Point(xEnd, yEnd));
//line across
xStart = xEnd;
xEnd = _ucdDest.Right;
yStart = yEnd;
_g.DrawLine(p, new Point(xStart, yStart), new Point(xEnd, yEnd));
//draw the end arrow
_g.DrawLine(p, new Point(xEnd, yEnd), new Point(xEnd + 10, yEnd - 5));
_g.DrawLine(p, new Point(xEnd, yEnd), new Point(xEnd + 10, yEnd + 5));
}
//its only 1 column across, so only need to draw up for NorthWest
// <-----
// |
// |
//
// OR down and across for SouthWest
//
// |
// |
// <-----
else
{
//line up
xStart = xEnd;
yStart = yEnd;
yEnd = _ucdDest.Top + 40;
_g.DrawLine(p, new Point(xStart, yStart), new Point(xEnd, yEnd));
//line across
xStart = xEnd;
xEnd = _ucdDest.Right;
yStart = yEnd;
_g.DrawLine(p, new Point(xStart, yStart), new Point(xEnd, yEnd));
//draw the end arrow
_g.DrawLine(p, new Point(xEnd, yEnd), new Point(xEnd + 10, yEnd - 5));
_g.DrawLine(p, new Point(xEnd, yEnd), new Point(xEnd + 10, yEnd + 5));
}
}
--------------------编程问答-------------------- 帮你顶!加油 --------------------编程问答-------------------- 本人已经开发好了,需要的话请联系我。。。。
/// <summary>
/// Draws a NorthNonDirect OR SouthNonDirect association line and arrow
/// </summary>
private void DrawNorthNonDirect_DrawSouthNonDirect()
{
int xStart = _ucdSrc.Left;
int yStart = _ucdSrc.Top + 40;
int xEnd = _ucdSrc.Left - (_GenericSpace - (_RandomLineOffSet + Program.GetRandom(_RandomLineOffSet)));
int yEnd = _ucdSrc.Top + 40;
//create a dasked line
Pen p = new Pen(new SolidBrush(Color.Black));
p.DashStyle = DashStyle.Dash;
//line across
_g.DrawLine(p, new Point(xStart, yStart), new Point(xEnd, yEnd));
//line up
xStart = xEnd;
yStart = yEnd;
yEnd = _ucdDest.Top + 40;
_g.DrawLine(p, new Point(xStart, yStart), new Point(xEnd, yEnd));
//line across
xStart = xEnd;
xEnd = _ucdDest.Left;
yStart = yEnd;
_g.DrawLine(p, new Point(xStart, yStart), new Point(xEnd, yEnd));
//draw the end arrow
_g.DrawLine(p, new Point(xEnd, yEnd), new Point(xEnd - 10, yEnd - 5));
_g.DrawLine(p, new Point(xEnd, yEnd), new Point(xEnd - 10, yEnd + 5));
}
/// <summary>
/// Draws a EastNonDirect OR WestNonDirect association line and arrow
/// </summary>
private void DrawEastNonDirect_DrawWestNonDirect()
{
int xStart = _ucdSrc.Right - 20;
int yStart = _ucdSrc.Top;
int xEnd = _ucdSrc.Right - 20;
int yEnd = _ucdSrc.Top - (_GenericSpace - (_RandomLineOffSet + Program.GetRandom(_RandomLineOffSet))); ;
//create a dasked line
Pen p = new Pen(new SolidBrush(Color.Black));
p.DashStyle = DashStyle.Dash;
//line up
_g.DrawLine(p, new Point(xStart, yStart), new Point(xEnd, yEnd));
//line across
xStart = xEnd;
yStart = yEnd;
xEnd = _ucdDest.Right - 20;
_g.DrawLine(p, new Point(xStart, yStart), new Point(xEnd, yEnd));
//line down
xStart = xEnd;
yStart = yEnd;
yEnd = _ucdDest.Top;
_g.DrawLine(p, new Point(xStart, yStart), new Point(xEnd, yEnd));
//draw the end arrow
_g.DrawLine(p, new Point(xEnd, yEnd), new Point(xEnd - 5, yEnd - 10));
_g.DrawLine(p, new Point(xEnd, yEnd), new Point(xEnd + 5, yEnd - 10));
}
#endregion
}
#endregion
}
补充:.NET技术 , C#