Exemplo n.º 1
0
        /// <summary>
        /// 创建家谱图
        /// </summary>
        private void CreateFamilyTree2()
        {
            Graphics g        = this.CreateGraphics();
            NodeInfo nodeInfo = new NodeInfo();

            //控件边框线
            //g.DrawRectangle(new Pen(Color.Red, 2), 0, 0, this.Width + ScrollOffset.Width, this.Height + ScrollOffset.Height);
            g.DrawRectangle(new Pen(Color.Red, 2), 0, 0, this.Width + ScrollOffset.Width, this.Height + ScrollOffset.Height);

            #region 第一世代
            // 中点位置(控件宽度的中点)
            int iCenterX = this.Width / 2;

            // 开始位置:中点位置左移 姓名框的宽度的一半
            int iD1_X1 = iCenterX - FTConfig.iPWidth / 2;
            // 开始Y坐标
            int iD1_Y1 = FTConfig.iTop;

            nodeInfo = new NodeInfo();
            nodeInfo.MyPerson.Key = "01";
            CreateRec(iD1_X1, iD1_Y1, g, nodeInfo);

            g.DrawString("母 张 氏", new Font("宋体", 10), new SolidBrush(Color.DarkOrchid), iD1_X1, iD1_Y1, m_strFormat);
            g.DrawString("父 张老大", 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 = 3;

            // 横线的长度
            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(fLineX2, fCenterY2);
                }
                // 最后
                else if (i == iCn - 1)
                {
                    CreatePerson(fLineX2 - fLineWidth, fCenterY2);
                }
                else
                {
                    CreatePerson(fLineX2 - fLineWidth / (iCn - 1) * i, fCenterY2);
                }
            }
        }
Exemplo n.º 2
0
        /// <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 + ScrollOffset.Width, this.Height + 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);

                DrawString("母 " + argP.PartnerName, iD1_X1, iD1_Y1, g);
                DrawString("父 " + argP.Name, iD1_X1 + FTConfig.iPWidth / 2, iD1_Y1, g);
            }
            #endregion

            #region 竖线配置
            //横线中点
            float fCenterX  = iCenterX;
            float fCenterY1 = iD1_Y1 + FTConfig.iPHeight;

            float fCenterY2 = fCenterY1 + FTConfig.fHeight;
            //中点竖线
            DrawLine(fCenterX, fCenterY1, fCenterX, fCenterY2, g);
            #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;
                DrawLine(fLineX1, fCenterY2, fLineX2, fCenterY2, g);
            }
            #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));
                }
            }
        }