当前位置: 首页>>代码示例>>C#>>正文


C# TextBox.SetText方法代码示例

本文整理汇总了C#中TextBox.SetText方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.SetText方法的具体用法?C# TextBox.SetText怎么用?C# TextBox.SetText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TextBox的用法示例。


在下文中一共展示了TextBox.SetText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawString

    /**
     * Renders the text specified by the specified <code>String</code>,
     * using the current text attribute state in the <code>Graphics2D</code> context.
     * The baseline of the first character is at position
     * (<i>x</i>,&nbsp;<i>y</i>) in the User Space.
     * The rendering attributes applied include the <code>Clip</code>,
     * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
     * <code>Composite</code> attributes. For characters in script systems
     * such as Hebrew and Arabic, the glyphs can be rendered from right to
     * left, in which case the coordinate supplied is the location of the
     * leftmost character on the baseline.
     * @param s the <code>String</code> to be rendered
     * @param x the x coordinate of the location where the
     * <code>String</code> should be rendered
     * @param y the y coordinate of the location where the
     * <code>String</code> should be rendered
     * @throws NullPointerException if <code>str</code> is
     *         <code>null</code>
     * @see #setPaint
     * @see java.awt.Graphics#setColor
     * @see java.awt.Graphics#setFont
     * @see #setTransform
     * @see #setComposite
     * @see #setClip
     */
    public void DrawString(String s, float x, float y) {
        TextBox txt = new TextBox(_group);
        txt.GetTextRun().supplySlideShow(_group.Sheet.GetSlideShow());
        txt.GetTextRun().SetSheet(_group.Sheet);
        txt.SetText(s);

        RichTextRun rt = txt.GetTextRun().GetRichTextRuns()[0];
        rt.SetFontSize(_font.GetSize());
        rt.SetFontName(_font.GetFamily());

        if (getColor() != null) rt.SetFontColor(getColor());
        if (_font.IsBold()) rt.SetBold(true);
        if (_font.IsItalic()) rt.SetItalic(true);

        txt.SetMarginBottom(0);
        txt.SetMarginTop(0);
        txt.SetMarginLeft(0);
        txt.SetMarginRight(0);
        txt.SetWordWrap(TextBox.WrapNone);
        txt.SetHorizontalAlignment(TextBox.AlignLeft);
        txt.SetVerticalAlignment(TextBox.AnchorMiddle);


        TextLayout layout = new TextLayout(s, _font, GetFontRenderContext());
        float ascent = layout.GetAscent();

        float width = (float) Math.floor(layout.GetAdvance());
        /**
         * Even if top and bottom margins are Set to 0 PowerPoint
         * always Sets extra space between the text and its bounding box.
         *
         * The approximation height = ascent*2 works good enough in most cases
         */
        float height = ascent * 2;

        /*
          In powerpoint anchor of a shape is its top left corner.
          Java graphics Sets string coordinates by the baseline of the first character
          so we need to shift up by the height of the textbox
        */
        y -= height / 2 + ascent / 2;

        /*
          In powerpoint anchor of a shape is its top left corner.
          Java graphics Sets string coordinates by the baseline of the first character
          so we need to shift down by the height of the textbox
        */
        txt.SetAnchor(new Rectangle2D.Float(x, y, width, height));

        _group.AddShape(txt);
    }
开发者ID:89sos98,项目名称:npoi,代码行数:76,代码来源:PPGraphics2D.cs


注:本文中的TextBox.SetText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。