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