public override IElement CreateElement(IPageLayout ipageLayout_0)
        {
            ILegend style;

            if (base.Style != null)
            {
                style = base.Style as ILegend;
            }
            else
            {
                style = new LegendClass_2();
            }
            style.AutoAdd        = true;
            style.AutoReorder    = true;
            style.AutoVisibility = true;
            UID clsid = new UIDClass
            {
                Value = "esriCarto.Legend"
            };
            IMapFrame frame =
                (ipageLayout_0 as IGraphicsContainer).FindFrame((ipageLayout_0 as IActiveView).FocusMap) as IMapFrame;
            IElement element = frame.CreateSurroundFrame(clsid, style) as IElement;

            (element as IFrameElement).Border     = this.Border;
            (element as IFrameElement).Background = this.Background;
            (element as IFrameProperties).Shadow  = this.Shadow;
            IEnvelope oldBounds = new EnvelopeClass();
            IPoint    position  = this.GetPosition(ipageLayout_0);

            oldBounds.PutCoords(position.X, position.Y, position.X + 4.0, position.Y + 8.0);
            IEnvelope newBounds = new EnvelopeClass();

            style.QueryBounds((ipageLayout_0 as IActiveView).ScreenDisplay, oldBounds, newBounds);
            oldBounds.PutCoords(position.X, position.Y, position.X + newBounds.Width, position.Y + newBounds.Height);
            element.Geometry = oldBounds;
            this.Element     = element;
            return(element);
        }
Exemple #2
0
        //创建图例
        private void CreateLegend()
        {
            ILegendFormat     pLegendFormat     = new LegendFormatClass();
            IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();

            pActiveView = m_hookHelper.ActiveView as IActiveView;
            pMap        = pActiveView.FocusMap;

            //边框、背景、阴影的间距
            if (txtLegendFrameGap.Text != null && pSymbolBorder != null)
            {
                pSymbolBorder.Gap = double.Parse(this.txtLegendFrameGap.Text);
            }
            if (txtLegendFrameGap.Text != null && pSymbolBackground != null)
            {
                pSymbolBackground.Gap = double.Parse(this.txtLegendFrameGap.Text);
            }
            if (txtLegendFrameGap.Text != null && pSymbolShadow != null)
            {
                pSymbolShadow.VerticalSpacing   = double.Parse(this.txtLegendFrameGap.Text) + 10;
                pSymbolShadow.HorizontalSpacing = double.Parse(this.txtLegendFrameGap.Text) + 10;
            }
            //边框、背景、阴影的角度
            if (txtLegendFrameAngle.Text != null && pSymbolBorder != null)
            {
                pSymbolBorder.CornerRounding = short.Parse(txtLegendFrameAngle.Text);
            }
            if (txtLegendFrameAngle.Text != null && pSymbolBackground != null)
            {
                pSymbolBackground.CornerRounding = short.Parse(txtLegendFrameAngle.Text);
            }
            if (txtLegendFrameAngle.Text != null && pSymbolShadow != null)
            {
                pSymbolShadow.CornerRounding = short.Parse(txtLegendFrameAngle.Text);
            }
            //边框、背景、阴影
            IFrameProperties pFrameProperties = pMapSurroundFrame as IFrameProperties;

            if (pSymbolBorder != null)
            {
                pFrameProperties.Border = pSymbolBorder;
            }
            if (pSymbolBackground != null)
            {
                pFrameProperties.Background = pSymbolBackground;
            }
            if (pSymbolShadow != null)
            {
                pFrameProperties.Shadow = pSymbolShadow;
            }

            //显示标题
            pLegendFormat.ShowTitle = true;
            //标题位置
            pLegendFormat.TitlePosition = esriRectanglePosition.esriTopSide;
            //标题样式
            pLegendFormat.TitleSymbol = CreateTitleSymbol();


            //第四界面从上到下图例各部分之间的距离
            pLegendFormat.TitleGap           = double.Parse(txtTitleAndLegend.Text);
            pLegendFormat.VerticalItemGap    = double.Parse(txtLegendItems.Text);
            pLegendFormat.HorizontalItemGap  = double.Parse(txtColumns.Text);
            pLegendFormat.HeadingGap         = double.Parse(txtHeadings.Text);
            pLegendFormat.TextGap            = double.Parse(txtLabelsAndDescription.Text);
            pLegendFormat.VerticalPatchGap   = double.Parse(txtPatchesV.Text);
            pLegendFormat.HorizontalPatchGap = double.Parse(txtPatchAndLabels.Text);

            pLegendFormat.LayerNameGap = 2;

            //图面的样式以及高度和宽度
            if (pLinePatch != null)
            {
                pLegendFormat.DefaultLinePatch = pLinePatch;
            }
            if (pAreaPatch != null)
            {
                pLegendFormat.DefaultAreaPatch = pAreaPatch;
            }
            pLegendFormat.DefaultPatchHeight = double.Parse(this.txtPatchHeight.Text);
            pLegendFormat.DefaultPatchWidth  = double.Parse(this.txtPatchWith.Text);


            //创建图例
            ILegend pLegend = new LegendClass_2();

            //图例名称
            //pLegend.Name = this.txtLegendTitle.Text;
            pLegend.AutoVisibility = false; //显示显示的图层
            pLegend.AutoAdd        = false; //自动添加新数据到图例

            pLegend.AutoReorder = true;     //根据图层顺序自动排列
            pLegend.Title       = this.txtLegendTitle.Text;
            pLegend.Format      = pLegendFormat;

            pLegend.Map = pMap;
            pLegend.ClearItems();
            //pLegend.Refresh();

            //图例列数
            double pLegendColumn = double.Parse(this.LegendColumn.Text);
            //图例中要包含的图层个数为  pSelectedidx.Count
            double pLegendItemCount = pSelectedidx.Count;
            //计算图例分裂的位置
            int    ColumnPos = (int)(pLegendItemCount / pLegendColumn);
            double remainder = (pLegendItemCount % pLegendColumn) / pLegendColumn;

            if (remainder >= 0.5)
            {
                ColumnPos = ColumnPos + 1;
            }
            //设置添加到图例的图层
            for (int i = 0; i < pSelectedidx.Count; i++)
            {
                ILegendItem pLegendItem = new HorizontalLegendItemClass();

                ILayer pLayer = (ILayer)(pMap.get_Layer(pSelectedidx[i]));
                if (!pLayer.Valid)
                {
                    continue;
                }
                pLegendItem.Layer = pLayer;

                //显示标注和描述
                pLegendItem.ShowDescriptions = true;
                pLegendItem.ShowLabels       = true;

                //标注和描述字体样式
                ITextSymbol pLDTextSymbol = new TextSymbolClass();
                IFontDisp   pLDFont       = new StdFontClass() as IFontDisp;
                IRgbColor   pLDColor      = new RgbColorClass();
                pLDColor.Red        = 0;
                pLDColor.Green      = 0;
                pLDColor.Blue       = 0;
                pLDTextSymbol.Color = pLDColor;

                pLDFont.Size       = (decimal)8;
                pLDFont.Name       = "宋体";
                pLDTextSymbol.Font = pLDFont;
                ILegendClassFormat pLegendClassFormat = new LegendClassFormatClass();
                pLegendClassFormat.LabelSymbol       = pLDTextSymbol;
                pLegendClassFormat.DescriptionSymbol = pLDTextSymbol;

                pLegendItem.LegendClassFormat = pLegendClassFormat;
                //图层名称是否显示
                if (pLegendItem.Layer is IFeatureLayer)
                {
                    if (((IGeoFeatureLayer)pLegendItem.Layer).Renderer is ISimpleRenderer)
                    {
                        pLegendItem.ShowHeading   = false;
                        pLegendItem.ShowLayerName = false;
                    }
                    else
                    {
                        pLegendItem.ShowLayerName = true;
                        pLegendItem.ShowHeading   = true;
                        //图层名称和头文件的样式
                        ITextSymbol pLHTextSymbol = new TextSymbolClass();
                        IFontDisp   pLHFont       = new StdFontClass() as IFontDisp;
                        IRgbColor   pLHColor      = new RgbColorClass();
                        pLDColor.Red   = 0;
                        pLDColor.Green = 0;
                        pLDColor.Blue  = 0;

                        pLHTextSymbol.Color = pLHColor;
                        pLHFont.Name        = "宋体";
                        pLHFont.Size        = 10;
                        pLHFont.Bold        = true;
                        pLHTextSymbol.Font  = pLHFont;
                        pLHTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;

                        pLegendItem.HeadingSymbol   = pLHTextSymbol;
                        pLegendItem.LayerNameSymbol = pLHTextSymbol;
                    }
                }
                else if (pLegendItem.Layer is IRasterLayer)
                {
                    pLegendItem.ShowLayerName = true;
                    pLegendItem.ShowHeading   = true;
                    //图层名称和头文件的样式
                    ITextSymbol pLHTextSymbol = new TextSymbolClass();
                    IFontDisp   pLHFont       = new StdFontClass() as IFontDisp;
                    IRgbColor   pLHColor      = new RgbColorClass();
                    pLDColor.Red   = 0;
                    pLDColor.Green = 0;
                    pLDColor.Blue  = 0;

                    pLHTextSymbol.Color = pLHColor;
                    pLHFont.Name        = "宋体";
                    pLHFont.Size        = 10;
                    pLHFont.Bold        = true;
                    pLHTextSymbol.Font  = pLHFont;
                    pLHTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;

                    pLegendItem.HeadingSymbol   = pLHTextSymbol;
                    pLegendItem.LayerNameSymbol = pLHTextSymbol;
                }

                //列数设置
                if (ColumnPos <= 1)
                {
                    pLegendItem.NewColumn = true;
                }
                else if (ColumnPos > 1 && i > 0)
                {
                    int columnI = i % ColumnPos;
                    if (columnI == 0)
                    {
                        pLegendItem.NewColumn = true;
                    }
                }

                ILegendLayout pLegendLayout = pLegendFormat as ILegendLayout;
                pLegendLayout.ScaleGraphicsOnResize = false;


                //将图层及样式设计加入图例中
                pLegend.AddItem(pLegendItem);
                pLegend.Refresh();
            }



            //将图例加载到PageLayout上
            IGraphicsContainer pGraphicsContainer = pActiveView.GraphicsContainer;
            IMapFrame          pMapFrame          = pGraphicsContainer.FindFrame(pMap) as IMapFrame;

            if (pMapFrame == null)
            {
                return;
            }

            pMapSurroundFrame.MapFrame    = pMapFrame;
            pMapSurroundFrame.MapSurround = (IMapSurround)pLegend;
            IElement pElement = (IElement)pMapSurroundFrame;


            IPageLayout pPageLayout = (IPageLayout)pActiveView;
            IPage       pPage       = pPageLayout.Page;
            double      pWidth      = pPage.PrintableBounds.XMax / 10.0;
            double      pHeigth     = pPage.PrintableBounds.YMin / 10.0;

            IEnvelope pEnvelope = new EnvelopeClass();

            pEnvelope.PutCoords(pWidth, pHeigth, pWidth + 6, pHeigth + 6);
            pElement.Geometry = (IGeometry)pEnvelope;

            pGraphicsContainer.AddElement((IElement)pMapSurroundFrame, 0);

            m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pMapSurroundFrame, null);
        }
Exemple #3
0
        public static IElement CreateElement(IPageLayout ipageLayout_0)
        {
            int         num;
            double      num1;
            double      num2;
            ITextSymbol symbol;
            esriTextHorizontalAlignment horizontalAlignment;
            esriTextVerticalAlignment   verticalAlignment;
            IScaleText  scaleTextClass;
            UID         uIDClass;
            IMapFrame   mapFrame;
            IEnvelope   envelopeClass;
            IEnvelope   envelope;
            ILegend     legendClass2;
            IScaleBar   hollowScaleBarClass;
            double      num3;
            double      num4;
            INorthArrow markerNorthArrowClass;
            IPoint      position         = ElementWizardHelp.GetPosition(ipageLayout_0, out num, out num1, out num2);
            IElement    textElementClass = null;

            switch (ElementWizardHelp.m_ElementType)
            {
            case ElementType.ConstantText:
            {
                textElementClass = new TextElementClass();
                (textElementClass as IElementProperties).Name = ElementWizardHelp.m_Text;
                (textElementClass as ITextElement).Text       = ElementWizardHelp.m_Text;
                if (ElementWizardHelp.m_pStyle != null)
                {
                    ElementWizardHelp.SetTextSymblAlign(ElementWizardHelp.m_pStyle as ITextSymbol, num);
                    (textElementClass as ITextElement).Symbol = ElementWizardHelp.m_pStyle as ITextSymbol;
                }
                textElementClass.Geometry = position;
                if (!ElementWizardHelp.m_IsVerticalText)
                {
                    (textElementClass as IElementProperties).Type = "";
                    symbol = (textElementClass as ITextElement).Symbol;
                    if (symbol.Angle != 270)
                    {
                        return(textElementClass);
                    }
                    (symbol as ICharacterOrientation).CJKCharactersRotation = false;
                    symbol.Angle        = 0;
                    horizontalAlignment = symbol.HorizontalAlignment;
                    verticalAlignment   = symbol.VerticalAlignment;
                    if (horizontalAlignment == esriTextHorizontalAlignment.esriTHALeft)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom;
                    }
                    else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHAFull)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom;
                    }
                    else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHARight)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop;
                    }
                    else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHACenter)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter;
                    }
                    if (verticalAlignment == esriTextVerticalAlignment.esriTVATop)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
                    }
                    else if (verticalAlignment == esriTextVerticalAlignment.esriTVABottom)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight;
                    }
                    else if (verticalAlignment == esriTextVerticalAlignment.esriTVACenter)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
                    }
                    else if (verticalAlignment == esriTextVerticalAlignment.esriTVABaseline)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight;
                    }
                    (textElementClass as ITextElement).Symbol = symbol;
                    return(textElementClass);
                }
                else
                {
                    (textElementClass as IElementProperties).Type = "竖向";
                    symbol = (textElementClass as ITextElement).Symbol;
                    (symbol as ICharacterOrientation).CJKCharactersRotation = true;
                    symbol.Angle        = 270;
                    horizontalAlignment = symbol.HorizontalAlignment;
                    verticalAlignment   = symbol.VerticalAlignment;
                    if (horizontalAlignment == esriTextHorizontalAlignment.esriTHALeft)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop;
                    }
                    else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHAFull)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop;
                    }
                    else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHARight)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom;
                    }
                    else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHACenter)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter;
                    }
                    if (verticalAlignment == esriTextVerticalAlignment.esriTVATop)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
                    }
                    else if (verticalAlignment == esriTextVerticalAlignment.esriTVABottom)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight;
                    }
                    else if (verticalAlignment == esriTextVerticalAlignment.esriTVACenter)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
                    }
                    else if (verticalAlignment == esriTextVerticalAlignment.esriTVABaseline)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight;
                    }
                    (textElementClass as ITextElement).Symbol = symbol;
                    return(textElementClass);
                }
            }

            case ElementType.SingleText:
            {
                textElementClass = new TextElementClass();
                (textElementClass as IElementProperties).Name = ElementWizardHelp.m_Text;
                (textElementClass as ITextElement).Text       = string.Concat("=", ElementWizardHelp.m_Text);
                if (ElementWizardHelp.m_pStyle != null)
                {
                    ElementWizardHelp.SetTextSymblAlign(ElementWizardHelp.m_pStyle as ITextSymbol, num);
                    (textElementClass as ITextElement).Symbol = ElementWizardHelp.m_pStyle as ITextSymbol;
                }
                textElementClass.Geometry = position;
                if (!ElementWizardHelp.m_IsVerticalText)
                {
                    (textElementClass as IElementProperties).Type = "";
                    symbol = (textElementClass as ITextElement).Symbol;
                    if (symbol.Angle != 270)
                    {
                        return(textElementClass);
                    }
                    (symbol as ICharacterOrientation).CJKCharactersRotation = false;
                    symbol.Angle        = 0;
                    horizontalAlignment = symbol.HorizontalAlignment;
                    verticalAlignment   = symbol.VerticalAlignment;
                    if (horizontalAlignment == esriTextHorizontalAlignment.esriTHALeft)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom;
                    }
                    else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHAFull)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom;
                    }
                    else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHARight)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop;
                    }
                    else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHACenter)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter;
                    }
                    if (verticalAlignment == esriTextVerticalAlignment.esriTVATop)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
                    }
                    else if (verticalAlignment == esriTextVerticalAlignment.esriTVABottom)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight;
                    }
                    else if (verticalAlignment == esriTextVerticalAlignment.esriTVACenter)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
                    }
                    else if (verticalAlignment == esriTextVerticalAlignment.esriTVABaseline)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight;
                    }
                    (textElementClass as ITextElement).Symbol = symbol;
                    return(textElementClass);
                }
                else
                {
                    (textElementClass as IElementProperties).Type = "竖向";
                    symbol = (textElementClass as ITextElement).Symbol;
                    (symbol as ICharacterOrientation).CJKCharactersRotation = true;
                    symbol.Angle        = 270;
                    horizontalAlignment = symbol.HorizontalAlignment;
                    verticalAlignment   = symbol.VerticalAlignment;
                    if (horizontalAlignment == esriTextHorizontalAlignment.esriTHALeft)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom;
                    }
                    else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHAFull)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom;
                    }
                    else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHARight)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop;
                    }
                    else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHACenter)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter;
                    }
                    if (verticalAlignment == esriTextVerticalAlignment.esriTVATop)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
                    }
                    else if (verticalAlignment == esriTextVerticalAlignment.esriTVABottom)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight;
                    }
                    else if (verticalAlignment == esriTextVerticalAlignment.esriTVACenter)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
                    }
                    else if (verticalAlignment == esriTextVerticalAlignment.esriTVABaseline)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight;
                    }
                    (textElementClass as ITextElement).Symbol = symbol;
                    return(textElementClass);
                }
            }

            case ElementType.MultiText:
            {
                textElementClass = new TextElementClass();
                (textElementClass as IElementProperties).Name = ElementWizardHelp.m_Text;
                (textElementClass as ITextElement).Text       = string.Concat("M=", ElementWizardHelp.m_Text);
                if (ElementWizardHelp.m_pStyle != null)
                {
                    ElementWizardHelp.SetTextSymblAlign(ElementWizardHelp.m_pStyle as ITextSymbol, num);
                    (textElementClass as ITextElement).Symbol = ElementWizardHelp.m_pStyle as ITextSymbol;
                }
                textElementClass.Geometry = position;
                if (!ElementWizardHelp.m_IsVerticalText)
                {
                    (textElementClass as IElementProperties).Type = "";
                    symbol = (textElementClass as ITextElement).Symbol;
                    if (symbol.Angle != 270)
                    {
                        return(textElementClass);
                    }
                    (symbol as ICharacterOrientation).CJKCharactersRotation = false;
                    symbol.Angle        = 0;
                    horizontalAlignment = symbol.HorizontalAlignment;
                    verticalAlignment   = symbol.VerticalAlignment;
                    if (horizontalAlignment == esriTextHorizontalAlignment.esriTHALeft)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom;
                    }
                    else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHAFull)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom;
                    }
                    else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHARight)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop;
                    }
                    else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHACenter)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter;
                    }
                    if (verticalAlignment == esriTextVerticalAlignment.esriTVATop)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
                    }
                    else if (verticalAlignment == esriTextVerticalAlignment.esriTVABottom)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight;
                    }
                    else if (verticalAlignment == esriTextVerticalAlignment.esriTVACenter)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
                    }
                    else if (verticalAlignment == esriTextVerticalAlignment.esriTVABaseline)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight;
                    }
                    (textElementClass as ITextElement).Symbol = symbol;
                    return(textElementClass);
                }
                else
                {
                    (textElementClass as IElementProperties).Type = "竖向";
                    symbol = (textElementClass as ITextElement).Symbol;
                    (symbol as ICharacterOrientation).CJKCharactersRotation = true;
                    symbol.Angle        = 270;
                    horizontalAlignment = symbol.HorizontalAlignment;
                    verticalAlignment   = symbol.VerticalAlignment;
                    if (horizontalAlignment == esriTextHorizontalAlignment.esriTHALeft)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop;
                    }
                    else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHAFull)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop;
                    }
                    else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHARight)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom;
                    }
                    else if (horizontalAlignment == esriTextHorizontalAlignment.esriTHACenter)
                    {
                        symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter;
                    }
                    if (verticalAlignment == esriTextVerticalAlignment.esriTVATop)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
                    }
                    else if (verticalAlignment == esriTextVerticalAlignment.esriTVABottom)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight;
                    }
                    else if (verticalAlignment == esriTextVerticalAlignment.esriTVACenter)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
                    }
                    else if (verticalAlignment == esriTextVerticalAlignment.esriTVABaseline)
                    {
                        symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight;
                    }
                    (textElementClass as ITextElement).Symbol = symbol;
                    return(textElementClass);
                }
            }

            case ElementType.JoinTable:
            {
                textElementClass = (new JionTab()).CreateJionTab(ipageLayout_0 as IActiveView, position);
                return(textElementClass);
            }

            case ElementType.ScaleText:
            {
                if (ElementWizardHelp.m_pStyle == null)
                {
                    scaleTextClass = new ScaleTextClass();
                }
                else
                {
                    scaleTextClass = ElementWizardHelp.m_pStyle as IScaleText;
                }
                uIDClass = new UIDClass()
                {
                    Value = "esriCarto.ScaleText"
                };
                mapFrame = (ipageLayout_0 as IGraphicsContainer).FindFrame((ipageLayout_0 as IActiveView).FocusMap) as IMapFrame;
                scaleTextClass.MapUnits  = mapFrame.Map.DistanceUnits;
                scaleTextClass.PageUnits = ipageLayout_0.Page.Units;
                scaleTextClass.Style     = esriScaleTextStyleEnum.esriScaleTextAbsolute;
                INumberFormat numberFormat = scaleTextClass.NumberFormat;
                if (numberFormat is INumericFormat)
                {
                    (numberFormat as INumericFormat).RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfDecimals;
                    (numberFormat as INumericFormat).UseSeparator   = false;
                    (numberFormat as INumericFormat).RoundingValue  = 0;
                    scaleTextClass.NumberFormat = numberFormat;
                }
                textElementClass = mapFrame.CreateSurroundFrame(uIDClass, scaleTextClass) as IElement;
                envelopeClass    = new EnvelopeClass();
                envelopeClass.PutCoords(position.X, position.Y, position.X + 4, position.Y + 8);
                envelope = new EnvelopeClass();
                scaleTextClass.QueryBounds((ipageLayout_0 as IActiveView).ScreenDisplay, envelopeClass, envelope);
                envelopeClass.PutCoords(position.X, position.Y, position.X + envelope.Width, position.Y + envelope.Height);
                textElementClass.Geometry = envelopeClass;
                return(textElementClass);
            }

            case ElementType.CustomLegend:
            {
                CustomLegend customLegend = new CustomLegend()
                {
                    LegendInfo = ElementWizardHelp.m_pLegendInfo
                };
                customLegend.Init(ipageLayout_0 as IActiveView, position);
                textElementClass = customLegend;
                return(textElementClass);
            }

            case ElementType.Legend:
            {
                if (ElementWizardHelp.m_pStyle == null)
                {
                    legendClass2 = new LegendClass_2();
                }
                else
                {
                    legendClass2 = ElementWizardHelp.m_pStyle as ILegend;
                }
                legendClass2.AutoAdd        = true;
                legendClass2.AutoReorder    = true;
                legendClass2.AutoVisibility = true;
                uIDClass = new UIDClass()
                {
                    Value = "esriCarto.Legend"
                };
                mapFrame         = (ipageLayout_0 as IGraphicsContainer).FindFrame((ipageLayout_0 as IActiveView).FocusMap) as IMapFrame;
                textElementClass = mapFrame.CreateSurroundFrame(uIDClass, legendClass2) as IElement;
                envelopeClass    = new EnvelopeClass();
                envelopeClass.PutCoords(position.X, position.Y, position.X + 4, position.Y + 8);
                envelope = new EnvelopeClass();
                legendClass2.QueryBounds((ipageLayout_0 as IActiveView).ScreenDisplay, envelopeClass, envelope);
                envelopeClass.PutCoords(position.X, position.Y, position.X + envelope.Width, position.Y + envelope.Height);
                textElementClass.Geometry = envelopeClass;
                return(textElementClass);
            }

            case ElementType.Picture:
            {
                string lower = System.IO.Path.GetExtension(ElementWizardHelp.m_PictureFileName).ToLower();
                textElementClass = null;
                string str = lower;
                if (string.IsNullOrEmpty(str))
                {
                    textElementClass = new PngPictureElementClass();
                    (textElementClass as IPictureElement).ImportPictureFromFile(ElementWizardHelp.m_PictureFileName);
                    (textElementClass as IPictureElement).MaintainAspectRatio = true;
                    num3 = 0;
                    num4 = 0;
                    (textElementClass as IPictureElement2).QueryIntrinsicSize(ref num3, ref num4);
                    num3 = num3 * 0.0353;
                    num4 = num4 * 0.0353;
                    (textElementClass as IElementProperties2).AutoTransform = true;
                    envelopeClass = new EnvelopeClass();
                    envelopeClass.PutCoords(position.X, position.Y, position.X + num3, position.Y + num4);
                    textElementClass.Geometry = envelopeClass;
                    return(textElementClass);
                }
                else if (str == ".bmp")
                {
                    textElementClass = new BmpPictureElementClass();
                }
                else if (str == ".jpg")
                {
                    textElementClass = new JpgPictureElementClass();
                }
                else if (str == ".gif")
                {
                    textElementClass = new GifPictureElementClass();
                }
                else if (str == ".tif")
                {
                    textElementClass = new TifPictureElementClass();
                }
                else
                {
                    if (str != ".emf")
                    {
                        textElementClass = new PngPictureElementClass();
                        (textElementClass as IPictureElement).ImportPictureFromFile(ElementWizardHelp.m_PictureFileName);
                        (textElementClass as IPictureElement).MaintainAspectRatio = true;
                        num3 = 0;
                        num4 = 0;
                        (textElementClass as IPictureElement2).QueryIntrinsicSize(ref num3, ref num4);
                        num3 = num3 * 0.0353;
                        num4 = num4 * 0.0353;
                        (textElementClass as IElementProperties2).AutoTransform = true;
                        envelopeClass = new EnvelopeClass();
                        envelopeClass.PutCoords(position.X, position.Y, position.X + num3, position.Y + num4);
                        textElementClass.Geometry = envelopeClass;
                        return(textElementClass);
                    }
                    textElementClass = new EmfPictureElementClass();
                }
                (textElementClass as IPictureElement).ImportPictureFromFile(ElementWizardHelp.m_PictureFileName);
                (textElementClass as IPictureElement).MaintainAspectRatio = true;
                num3 = 0;
                num4 = 0;
                (textElementClass as IPictureElement2).QueryIntrinsicSize(ref num3, ref num4);
                num3 = num3 * 0.0353;
                num4 = num4 * 0.0353;
                (textElementClass as IElementProperties2).AutoTransform = true;
                envelopeClass = new EnvelopeClass();
                envelopeClass.PutCoords(position.X, position.Y, position.X + num3, position.Y + num4);
                textElementClass.Geometry = envelopeClass;
                return(textElementClass);
            }

            case ElementType.OLE:
            {
                int screenDisplay = (ipageLayout_0 as IActiveView).ScreenDisplay.hWnd;
                Common.ExtendClass.IOleFrame oleFrame = new OleFrame();
                if (!oleFrame.CreateOleClientItem((ipageLayout_0 as IActiveView).ScreenDisplay, screenDisplay))
                {
                    return(textElementClass);
                }
                textElementClass = oleFrame as IElement;
                envelopeClass    = new EnvelopeClass();
                envelopeClass.PutCoords(position.X, position.Y, position.X + 4, position.Y + 8);
                envelope = new EnvelopeClass();
                textElementClass.QueryBounds((ipageLayout_0 as IActiveView).ScreenDisplay, envelope);
                envelopeClass.PutCoords(position.X, position.Y, position.X + envelope.Width, position.Y + envelope.Height);
                textElementClass.Geometry = envelopeClass;
                return(textElementClass);
            }

            case ElementType.ScaleBar:
            {
                if (ElementWizardHelp.m_pStyle == null)
                {
                    hollowScaleBarClass = new HollowScaleBarClass();
                }
                else
                {
                    hollowScaleBarClass = ElementWizardHelp.m_pStyle as IScaleBar;
                }
                uIDClass = new UIDClass()
                {
                    Value = "esriCarto.ScaleBar"
                };
                mapFrame = (ipageLayout_0 as IGraphicsContainer).FindFrame((ipageLayout_0 as IActiveView).FocusMap) as IMapFrame;
                hollowScaleBarClass.Units = mapFrame.Map.DistanceUnits;
                textElementClass          = mapFrame.CreateSurroundFrame(uIDClass, hollowScaleBarClass) as IElement;
                envelopeClass             = new EnvelopeClass();
                envelopeClass.PutCoords(position.X, position.Y, position.X + 4, position.Y + 8);
                envelope = new EnvelopeClass();
                hollowScaleBarClass.QueryBounds((ipageLayout_0 as IActiveView).ScreenDisplay, envelopeClass, envelope);
                envelopeClass.PutCoords(position.X, position.Y, position.X + envelope.Width, position.Y + envelope.Height);
                textElementClass.Geometry = envelopeClass;
                return(textElementClass);
            }

            case ElementType.North:
            {
                if (ElementWizardHelp.m_pStyle == null)
                {
                    markerNorthArrowClass = new MarkerNorthArrowClass();
                }
                else
                {
                    markerNorthArrowClass = ElementWizardHelp.m_pStyle as INorthArrow;
                }
                envelopeClass = new EnvelopeClass();
                envelopeClass.PutCoords(position.X, position.Y, position.X + 3, position.Y + 3);
                uIDClass = new UIDClass()
                {
                    Value = "esriCarto.MarkerNorthArrow"
                };
                mapFrame         = (ipageLayout_0 as IGraphicsContainer).FindFrame((ipageLayout_0 as IActiveView).FocusMap) as IMapFrame;
                textElementClass = mapFrame.CreateSurroundFrame(uIDClass, markerNorthArrowClass) as IElement;
                envelope         = new EnvelopeClass();
                markerNorthArrowClass.QueryBounds((ipageLayout_0 as IActiveView).ScreenDisplay, envelopeClass, envelope);
                envelopeClass.PutCoords(position.X, position.Y, position.X + envelope.Width, position.Y + envelope.Height);
                textElementClass.Geometry = envelopeClass;
                return(textElementClass);
            }

            case ElementType.GraphicElement:
            {
                return(textElementClass);
            }

            case ElementType.DataGraphicElement:
            {
                envelopeClass = new EnvelopeClass();
                envelopeClass.PutCoords(position.X, position.Y, position.X + 8, position.Y + 8);
                textElementClass = new DataGraphicsElement()
                {
                    Geometry = envelopeClass
                };
                return(textElementClass);
            }

            default:
            {
                return(textElementClass);
            }
            }
        }