/// <summary> /// 创建竖线和姓名框 /// </summary> /// <param name="x1"></param> /// <param name="y1"></param> private void CreatePerson(Graphics g, float x1, float y1, Person argSon) { #region 竖线 + 姓名框 2 //Graphics g = this.CreateGraphics(); NodeInfo nodeInfo = new NodeInfo(); nodeInfo.MyPerson = argSon; //// 竖线X1,X2 和 横线相同 //// 竖线Y1:= 横线Y1: float fSLineX11 = x1; float fSLineY11 = y1 + FTConfig.fHeight; //// 竖线Y2:中点右移动横线宽度 //float fSLineY2 = fCenterY2 + FTConfig.fHeight; g.DrawLine(new Pen(Color.Red, 1), fSLineX11, y1, fSLineX11, fSLineY11); DrawCircular(g, fSLineX11, y1, 8); //g.draw g.DrawString(argSon.Idx + "子", new Font("宋体", 12), new SolidBrush(Color.DarkOrchid), (Int32)fSLineX11, (Int32)y1, m_strFormat); //nodeInfo = new NodeInfo(); //nodeInfo.MyPerson.Key = "0102"; int iD22_X1 = (Int32)fSLineX11 - FTConfig.iPWidth / 2; int iD22_Y1 = (Int32)fSLineY11; CreateRec(iD22_X1, iD22_Y1, g, nodeInfo); g.DrawString("妻 " + argSon.PartnerName, new Font("宋体", 10), new SolidBrush(Color.DarkOrchid), iD22_X1, iD22_Y1, m_strFormat); g.DrawString("夫 " + argSon.Name, new Font("宋体", 10), new SolidBrush(Color.DarkOrchid), iD22_X1 + FTConfig.iPWidth / 2, iD22_Y1, m_strFormat); #endregion if (argSon.GetChildCount() > 0) { CreateFamilyTree(g, argSon, false, iD22_X1, iD22_Y1); } }
/// <summary> /// 创建家谱图 /// </summary> private void CreateFamilyTree(Graphics g, Person argP, bool isFirst, int x1 = 0, int y1 = 0) { //Graphics g = this.CreateGraphics(); NodeInfo nodeInfo = new NodeInfo(); //x1 = x1 + ScrollOffset.Width; //y1 = y1 + ScrollOffset.Height; //控件边框线 //g.DrawRectangle(new Pen(Color.Red, 2), 0 , 0, this.Width, this.Height); #region 第一世代 // 中点位置(控件宽度的中点) int iCenterX = x1 + FTConfig.iPWidth / 2; // 开始位置:中点位置左移 姓名框的宽度的一半 int iD1_X1 = iCenterX - FTConfig.iPWidth / 2; // 开始Y坐标 int iD1_Y1 = y1; if (isFirst) { // 中点位置(控件宽度的中点) iCenterX = this.Width / 2; // 开始位置:中点位置左移 姓名框的宽度的一半 iD1_X1 = iCenterX - FTConfig.iPWidth / 2; // 开始Y坐标 iD1_Y1 = FTConfig.iTop; nodeInfo = new NodeInfo(); nodeInfo.MyPerson = argP; //nodeInfo.MyPerson.Key = "01"; CreateRec(iD1_X1, iD1_Y1, g, nodeInfo); g.DrawString("母 " + argP.PartnerName, new Font("宋体", 10), new SolidBrush(Color.DarkOrchid), iD1_X1, iD1_Y1, m_strFormat); g.DrawString("父 " + argP.Name, new Font("宋体", 10), new SolidBrush(Color.DarkOrchid), iD1_X1 + FTConfig.iPWidth / 2, iD1_Y1, m_strFormat); } #endregion #region 竖线配置 //横线中点 float fCenterX = iCenterX; float fCenterY1 = iD1_Y1 + FTConfig.iPHeight; float fCenterY2 = fCenterY1 + FTConfig.fHeight; //中点竖线 g.DrawLine(new Pen(Color.Red, 1), fCenterX, fCenterY1, fCenterX, fCenterY2); #endregion #region 横线配置(子世代为复数时才会配置) //人数 int iCn = argP.GetChildCount(); // 横线的长度 float fLineWidth = 0; // 横线X1:中点左移横线一半的宽度 float fLineX1 = fCenterX; // 横线X2:X1右移动横线宽度 float fLineX2 = fLineX1; // 只有一个子代的时候不需要画横线 if (iCn != 1) { // 横线的长度 fLineWidth = FTConfig.fLineWidth * iCn; // 横线X1:中点左移横线一半的宽度 fLineX1 = fCenterX - fLineWidth / 2; // 横线X2:X1右移动横线宽度 fLineX2 = fLineX1 + fLineWidth; g.DrawLine(new Pen(Color.Red, 1), fLineX1, fCenterY2, fLineX2, fCenterY2); } #endregion #region 测试 //if (iCn == 2) //{ // CreatePerson(fLineX2, fCenterY2); // CreatePerson(fLineX2 - fLineWidth, fCenterY2); //} //else if (iCn == 3) //{ // CreatePerson(fLineX2, fCenterY2); // CreatePerson(fLineX2 - fLineWidth / (iCn - 1), fCenterY2); // CreatePerson(fLineX2 - fLineWidth, fCenterY2); //} //else if (iCn == 4) //{ // CreatePerson(fLineX2, fCenterY2); // CreatePerson(fLineX2 - fLineWidth / (iCn - 1), fCenterY2); // CreatePerson(fLineX2 - fLineWidth / (iCn - 1) * 2, fCenterY2); // CreatePerson(fLineX2 - fLineWidth, fCenterY2); //} //else if (iCn == 5) //{ // CreatePerson(fLineX2, fCenterY2); // CreatePerson(fLineX2 - fLineWidth / (iCn - 1), fCenterY2); // CreatePerson(fLineX2 - fLineWidth / (iCn - 1) * 2, fCenterY2); // CreatePerson(fLineX2 - fLineWidth / (iCn - 1) * 3, fCenterY2); // CreatePerson(fLineX2 - fLineWidth, fCenterY2); //} #endregion //遍历生成子世代图 for (int i = 0; i <= iCn - 1; i++) { if (i == 0) { CreatePerson(g, fLineX2, fCenterY2, argP.GetChild(i)); } // 最后 else if (i == iCn - 1) { CreatePerson(g, fLineX2 - fLineWidth, fCenterY2, argP.GetChild(i)); } else { CreatePerson(g, fLineX2 - fLineWidth / (iCn - 1) * i, fCenterY2, argP.GetChild(i)); } } }