本文整理汇总了C#中Alignment类的典型用法代码示例。如果您正苦于以下问题:C# Alignment类的具体用法?C# Alignment怎么用?C# Alignment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Alignment类属于命名空间,在下文中一共展示了Alignment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Table
/// <summary>
/// Construct a new <see cref="Table" />.
/// </summary>
/// <param name="tableName">
/// The name of the <see cref="Table" />.
/// </param>
/// <param name="headerAlignment">
/// The method to use to align the text in the table's header.
/// Defaults to <see cref="StringFormatting.LeftJustified" />.
/// </param>
public Table(string tableName=null, Alignment headerAlignment=null)
{
Title = tableName ?? string.Empty;
HeaderAlignment = headerAlignment ?? StringFormatting.LeftJustified;
Columns = new ColumnCollection();
Rows = new RowCollection(this);
}
示例2: Center
public void Center(Rectangle theDisplayArea, Alignment theAlignment)
{
Vector2 theTextSize = mFont.MeasureString(mText);
switch (theAlignment)
{
case Alignment.Horizonatal:
{
Position.X = theDisplayArea.X + (theDisplayArea.Width / 2 - theTextSize.X / 2);
break;
}
case Alignment.Vertical:
{
Position.Y = theDisplayArea.Y + (theDisplayArea.Height / 2 - theTextSize.Y / 2);
break;
}
case Alignment.Both:
{
Position.X = theDisplayArea.X + (theDisplayArea.Width / 2 - theTextSize.X / 2);
Position.Y = theDisplayArea.Y + (theDisplayArea.Height / 2 - theTextSize.Y / 2);
break;
}
}
}
示例3: AlignmentState
public AlignmentState (Alignment alignment, float padding, uint[] numberOfItems)
: this()
{
Alignment = alignment;
Padding = padding;
NumberOfItemsPer = numberOfItems;
}
示例4: ItemSelector
//------------------------------------------------------------------------------
// Function: ItemSelector
// Author: nholmes
// Summary: item constructor, allows user to specify the width of the button,
// the options that can be selected from, the vertical position, the
// alignment and the font
//------------------------------------------------------------------------------
public ItemSelector(Menu menu, Game game, string[] optionsText, int selectedOption, int y, int width, Alignment alignment, SpriteFont font, Color fontColor, int textOffset)
: base(menu, game, textOffset)
{
// store the width of the button, options text, selected option and the font to use
this.width = width;
this.optionsText = optionsText;
this.selectedOption = selectedOption;
this.font = font;
this.fontColor = fontColor;
// set the vy position of this button item
position.Y = y;
// calculate position based on alignment provided
switch (alignment)
{
case Alignment.left:
position.X = 0;
break;
case Alignment.centre:
position.X = (menu.ItemArea.Width / 2) - (width / 2);
break;
case Alignment.right:
position.X = width - (int)font.MeasureString(optionsText[selectedOption]).X;
break;
default:
position.X = 0;
break;
}
// store the size of this button item
size.X = width;
size.Y = menu.ButtonTexture.Height;
}
示例5: AlignmentButton
public AlignmentButton()
{
InitializeComponent();
m_alignment = Alignment.Centre;
m_image = Resources.DefaultButtonImage;
}
示例6: ItemSlider
//------------------------------------------------------------------------------
// Function: ItemSlider
// Author: nholmes
// Summary: item constructor, allows user to specify the width of the slider,
// the values that can be selected between, the vertical position, the
// alignment and the font
//------------------------------------------------------------------------------
public ItemSlider(Menu menu, Game game, int minValue, int maxValue, int initialValue, int y, int width, Alignment alignment, SpriteFont font, Color fontColor, int textOffset)
: base(menu, game, textOffset)
{
// store the width of the button, options text, selected option and the font to use
this.width = width;
this.minValue = minValue;
this.maxValue = maxValue;
this.currentValue = initialValue;
this.font = font;
this.fontColor = fontColor;
// set the vy position of this button item
position.Y = y;
// calculate position based on alignment provided
switch (alignment)
{
case Alignment.left:
position.X = 0;
break;
case Alignment.centre:
position.X = (menu.ItemArea.Width / 2) - (width / 2);
break;
case Alignment.right:
position.X = width;
break;
default:
position.X = 0;
break;
}
// store the size of this button item
size.X = width;
size.Y = menu.ButtonTexture.Height;
}
示例7: AddComponent
public void AddComponent(MSGUIUnclickable component, Alignment alignment)
{
switch (alignment)
{
case Alignment.TOP_LEFT:
component.Position = boundedPosition;
break;
case Alignment.TOP_CENTER:
component.Position = boundedPosition + new Vector2((boundedSize.X - component.Size.X) / 2, 0);
break;
case Alignment.TOP_RIGHT:
component.Position = boundedPosition + new Vector2(boundedSize.X - component.Size.X, 0);
break;
case Alignment.MIDDLE_LEFT:
component.Position = boundedPosition + new Vector2(0, (boundedSize.Y - component.Size.Y) / 2);
break;
case Alignment.MIDDLE_CENTER:
component.Position = boundedPosition + (boundedSize - component.Size) / 2;
break;
case Alignment.MIDDLE_RIGHT:
component.Position = boundedPosition + new Vector2(boundedSize.X - component.Size.X, (boundedSize.Y - component.Size.Y) / 2);
break;
case Alignment.BOTTOM_LEFT:
component.Position = boundedPosition + new Vector2(0, boundedSize.Y - component.Size.Y);
break;
case Alignment.BOTTOM_CENTER:
component.Position = boundedPosition + new Vector2((boundedSize.X - component.Size.X) / 2, boundedSize.Y - component.Size.Y);
break;
case Alignment.BOTTOM_RIGHT:
component.Position = boundedPosition + new Vector2(boundedSize.X - component.Size.X, boundedSize.Y - component.Size.Y);
break;
}
components.Add(component);
}
示例8: AlignmentCriterion
public AlignmentCriterion(XmlJointType centerJoint, XmlJointType[] joints, float variance)
: base(variance)
{
this.Alignment = Alignment.Point;
this.CenterJoint = centerJoint;
this.Joints = joints;
}
示例9: alignText
static IEnumerable<string> alignText(IEnumerable<string> lines, Alignment alignment, int width)
{
switch (alignment)
{
case Alignment.LEFT:
return lines;
case Alignment.RIGHT:
return lines.Select(t => new String(' ', width - t.Length) + t);
case Alignment.CENTER:
return lines.Select(t => new String(' ', (width - t.Length) / 2) + t);
case Alignment.JUSTIFY:
return lines.Select(t =>
{
var words = t.Split();
var spaceRequired = width - t.Length;
var spacing = spaceRequired / (words.Length - 1) + 1;
return string.Join(new String(' ', spacing), words);
});
default:
throw new NotImplementedException();
}
}
示例10: FindOffset
/// <summary>
/// Finds the <see cref="Vector2"/> that represents the position to align an object
/// to another object based on the given <see cref="Alignment"/>. The object being aligned
/// to is assumed to be at {0,0).
/// </summary>
/// <param name="alignment">The <see cref="Alignment"/> describing how to align the target
/// to the source.</param>
/// <param name="sourceSize">The object that is being aligned to the target.</param>
/// <param name="targetSize">The size of the object being aligned to.</param>
/// <returns>The <see cref="Vector2"/> that represents the position to align an object
/// to another object based on the given <paramref name="alignment"/>.</returns>
/// <exception cref="ArgumentException"><paramref name="alignment"/> is not a defined value of the <see cref="Alignment"/>
/// enum.</exception>
public static Vector2 FindOffset(Alignment alignment, Vector2 sourceSize, Vector2 targetSize)
{
switch (alignment)
{
case Alignment.TopLeft:
return new Vector2(0, 0);
case Alignment.TopRight:
return new Vector2(targetSize.X - sourceSize.X, 0);
case Alignment.BottomLeft:
return new Vector2(0, targetSize.Y - sourceSize.Y);
case Alignment.BottomRight:
return targetSize - sourceSize;
case Alignment.Top:
return new Vector2(targetSize.X / 2f - sourceSize.X / 2f, 0);
case Alignment.Bottom:
return new Vector2(targetSize.X / 2f - sourceSize.X / 2f, targetSize.Y - sourceSize.Y);
case Alignment.Left:
return new Vector2(0, targetSize.Y / 2f - sourceSize.Y / 2f);
case Alignment.Right:
return new Vector2(targetSize.X - sourceSize.X, targetSize.Y / 2f - sourceSize.Y / 2f);
case Alignment.Center:
return targetSize / 2f - sourceSize / 2f;
default:
throw new ArgumentException("Unknown alignment value specified", "alignment");
}
}
示例11: Draw
public static void Draw(SpriteBatch spriteBatch,int number, Alignment aligment ,Rectangle rect, int scale = 1)
{
var numbers = number.ToString ().ToCharArray ().Select (n => n.ToString ());
var images = numbers.Select (n => textures [n]).ToList ();
var width = images.Sum (n => n.Width* scale) + ((images.Count - 1) * padding*scale);
int x = rect.Left;
if (aligment == Alignment.Right)
x = rect.Right - width;
else if (aligment == Alignment.Center)
x = (rect.Right / 2) - (width / 2);
int y = rect.Top;
var drawRect = new Rectangle (x, y, 0, 0);
images.ForEach (i => {
drawRect.X =x;
drawRect.Width = i.Width*scale;
drawRect.Height = i.Height*scale;
spriteBatch.Draw (
i,
null,
drawRect,
null,
null,
0,
new Vector2(scale),
Color.White,
SpriteEffects.None,
0.0f);
spriteBatch.Draw(i,drawRect,Color.White);
x += i.Width * scale + padding*scale;
});
}
示例12: ApplyTextPositionAndAlignment
public void ApplyTextPositionAndAlignment(Position pos, Alignment alignment)
{
new TextBoxes(Shapes.Range(), SlideWidth, SlideHeight)
.SetPosition(pos)
.SetAlignment(alignment)
.StartBoxing();
}
示例13: TabWidgetModel
public TabWidgetModel(String id, Alignment alignment, String href)
{
this.Id = "tab" + id;
this.Alignment = alignment;
this.TabImage = "~/Content/img/tabs/" + id + ".png";
this.Href = href;
}
示例14: ItemText
//------------------------------------------------------------------------------
// Function: ItemText
// Author: nholmes
// Summary: item constructor, allows user to specify text, vertical position,
// alignment and font as well as whether the text is selectable
//------------------------------------------------------------------------------
public ItemText(Menu menu, Game game, string text, int y, Alignment alignment, SpriteFont font, Color fontColor, int textOffset, bool selectable)
: base(menu, game, textOffset)
{
// store the text font and font color to use
this.text = text;
this.font = font;
this.fontColor = fontColor;
// store whether this item is selectable
this.selectable = selectable;
// set the vy position of this text item
position.Y = y;
// calculate position based on alignment provided
switch (alignment)
{
case Alignment.left:
position.X = 0;
break;
case Alignment.centre:
position.X = (int)((menu.ItemArea.Width - font.MeasureString(text).X) / 2);
break;
case Alignment.right:
position.X = (int)(menu.ItemArea.Width - font.MeasureString(text).X);
break;
default:
position.X = 0;
break;
}
// store the size of this text item
size = font.MeasureString(text);
}
示例15: OnButtonClicked
protected void OnButtonClicked(object sender, EventArgs e)
{
if (sender == button1)
{
Gtk.FileChooserDialog dialog = new Gtk.FileChooserDialog ("Choose item...", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Insert Spacer", ResponseType.None, "Add", ResponseType.Accept);
Gtk.Alignment align = new Alignment (1, 0, 0, 1);
Gtk.Frame frame = new Frame ("Position");
Gtk.HBox hbox = new HBox (false, 4);
RadioButton rbRight;
rbRight = new RadioButton ("Right");
hbox.PackEnd(rbRight, false, false, 1);
hbox.PackEnd(new RadioButton (rbRight, "Left"), false, false, 1);
frame.Add (hbox);
align.Add (frame);
align.ShowAll ();
dialog.ExtraWidget = align;
ResponseType response = (ResponseType)dialog.Run ();
if (response == ResponseType.Accept) {
RunCommand ("defaults write com.apple.dock " + GetAlign(dialog.ExtraWidget) + " -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" + dialog.Filename + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>' && /bin/sleep 1 &&/usr/bin/killall Dock");
} else if (response == ResponseType.None) {
RunCommand ("defaults write com.apple.dock " + GetAlign(dialog.ExtraWidget) + " -array-add '{tile-data={}; tile-type=\"spacer-tile\";}' && /bin/sleep 1 &&/usr/bin/killall Dock");
}
dialog.Destroy ();
}
}