本文整理匯總了C#中System.Drawing.StringFormat.SetTabStops方法的典型用法代碼示例。如果您正苦於以下問題:C# StringFormat.SetTabStops方法的具體用法?C# StringFormat.SetTabStops怎麽用?C# StringFormat.SetTabStops使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Drawing.StringFormat
的用法示例。
在下文中一共展示了StringFormat.SetTabStops方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: pd_PrintPage
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
String line = null;
StringFormat stringFormat = new StringFormat();
stringFormat.SetTabStops(firstTabOffset, tabStops);
// Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics);
// Iterate over the file, printing each line.
while (count < linesPerPage &&
((line = streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, printFont, Brushes.Black,
leftMargin, yPos, stringFormat);
count++;
}
// If more lines exist, print another page.
if (line != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
}
示例2: BeginPrint
void BeginPrint(object sender, PrintEventArgs ev)
{
_currentLine = 0;
_printingStringFormat = (StringFormat) StringFormat.GenericTypographic.Clone();
// 100 should be enough for everyone ...err ?
float[] tabStops = new float[100];
for (int i = 0; i < tabStops.Length; ++i)
tabStops[i] = TabIndent * _primaryTextArea.TextArea.TextView.ColumnWidth;
_printingStringFormat.SetTabStops(0, tabStops);
}
示例3: EMFStringFormat
private EMFStringFormat(byte[] RecordData)
{
ObjectType = EmfObjectType.stringformat;
myStringFormat = new System.Drawing.StringFormat();
//put the Data into a stream and use a binary reader to read the data
MemoryStream _ms = new MemoryStream(RecordData);
BinaryReader _br = new BinaryReader(_ms);
_br.ReadUInt32(); //Who cares about version..not me!
myStringFormat.FormatFlags = (StringFormatFlags)_br.ReadUInt32();
_br.ReadBytes(4);//Language...Ignore for now!
myStringFormat.LineAlignment = (StringAlignment)_br.ReadUInt32();
myStringFormat.Alignment = (StringAlignment)_br.ReadUInt32();
UInt32 DigitSubstitutionMethod = _br.ReadUInt32();
UInt32 DigitSubstitutionLanguage = _br.ReadUInt32();
myStringFormat.SetDigitSubstitution((int)DigitSubstitutionLanguage, (StringDigitSubstitute)DigitSubstitutionMethod);
Single FirstTabOffSet = _br.ReadSingle();
myStringFormat.HotkeyPrefix = (System.Drawing.Text.HotkeyPrefix) _br.ReadInt32();
_br.ReadSingle();//leading Margin
_br.ReadSingle();//trailingMargin
_br.ReadSingle();//tracking
myStringFormat.Trimming = (StringTrimming)_br.ReadUInt32();
Int32 TabStopCount = _br.ReadInt32();
Int32 RangeCount = _br.ReadInt32();
//Next is stringformatdata...
Single[] TabStopArray;
System.Drawing.CharacterRange[] RangeArray;
if (TabStopCount > 0)
{
TabStopArray = new Single[TabStopCount];
for (int i = 0; i < TabStopCount; i++)
{
TabStopArray[i] = _br.ReadSingle();
}
myStringFormat.SetTabStops(FirstTabOffSet, TabStopArray);
}
if (RangeCount > 0)
{
RangeArray = new System.Drawing.CharacterRange[RangeCount];
for (int i = 0; i < RangeCount; i++)
{
RangeArray[i].First = _br.ReadInt32();
RangeArray[i].Length = _br.ReadInt32();
}
myStringFormat.SetMeasurableCharacterRanges(RangeArray);
}
}
示例4: ResetDefaults
public override void ResetDefaults() {
defaultWindowBackColor = this.ColorWindow;
defaultWindowForeColor = this.ColorControlText;
window_border_font = new Font(FontFamily.GenericSansSerif, 8.25f, FontStyle.Bold);
/* Menu string formats */
string_format_menu_text = new StringFormat ();
string_format_menu_text.LineAlignment = StringAlignment.Center;
string_format_menu_text.Alignment = StringAlignment.Near;
string_format_menu_text.HotkeyPrefix = HotkeyPrefix.Show;
string_format_menu_text.SetTabStops (0f, new float [] { 50f });
string_format_menu_text.FormatFlags |= StringFormatFlags.NoWrap;
string_format_menu_shortcut = new StringFormat ();
string_format_menu_shortcut.LineAlignment = StringAlignment.Center;
string_format_menu_shortcut.Alignment = StringAlignment.Far;
string_format_menu_menubar_text = new StringFormat ();
string_format_menu_menubar_text.LineAlignment = StringAlignment.Center;
string_format_menu_menubar_text.Alignment = StringAlignment.Center;
string_format_menu_menubar_text.HotkeyPrefix = HotkeyPrefix.Show;
}
示例5: OnDrawItem
//.........這裏部分代碼省略.........
if (SelectionMode != SelectionMode.None && (e.State & DrawItemState.Selected) == DrawItemState.Selected) {
if (Enabled)
{
backColor = SystemColors.Highlight;
foreColor = SystemColors.HighlightText;
}
else
{
backColor = SystemColors.InactiveBorder;
foreColor = SystemColors.GrayText;
}
}
// Draw the text
//
// Due to some sort of unpredictable painting optimization in the Windows ListBox control,
// we need to always paint the background rectangle for the current line.
using (Brush b = new SolidBrush(backColor)) {
e.Graphics.FillRectangle(b, textBounds);
}
Rectangle stringBounds = new Rectangle(
textBounds.X + 1,
textBounds.Y,
textBounds.Width - 1,
textBounds.Height - border * 2);
if( UseCompatibleTextRendering ){
using (StringFormat format = new StringFormat()) {
if (UseTabStops) {
// Set tab stops so it looks similar to a ListBox, at least with the default font size.
float tabDistance = 3.6f * Font.Height; // about 7 characters
float[] tabStops = new float[15];
float tabOffset = -(idealCheckSize + (border * 2));
for (int i = 1; i < tabStops.Length; i++)
tabStops[i] = tabDistance;
//(bug 111825)
if (Math.Abs(tabOffset) < tabDistance) {
tabStops[0] = tabDistance +tabOffset;
}
else {
tabStops[0] = tabDistance;
}
format.SetTabStops(0, tabStops);
}
else if (UseCustomTabOffsets) {
//Set TabStops to userDefined values
int wpar = CustomTabOffsets.Count;
float[] tabStops = new float[wpar];
CustomTabOffsets.CopyTo(tabStops, 0);
format.SetTabStops(0, tabStops);
}
// Adjust string format for Rtl controls
if (RightToLeft == RightToLeft.Yes) {
format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
}
// ListBox doesn't word-wrap its items, so neither should CheckedListBox
//
format.FormatFlags |= StringFormatFlags.NoWrap;
// VSWhidbey 95774: Set Trimming to None to prevent DrawString() from whacking the entire
// string when there is only one character per tab included in the string.
format.Trimming = StringTrimming.None;
// Do actual drawing
using (SolidBrush brush = new SolidBrush(foreColor)) {
e.Graphics.DrawString(text, font, brush, stringBounds, format);
}
}
}
else{
TextFormatFlags flags = TextFormatFlags.Default;
flags |= TextFormatFlags.NoPrefix;
if (UseTabStops || UseCustomTabOffsets) {
flags |= TextFormatFlags.ExpandTabs;
}
// Adjust string format for Rtl controls
if (RightToLeft == RightToLeft.Yes) {
flags |= TextFormatFlags.RightToLeft;
flags |= TextFormatFlags.Right;
}
// Do actual drawing
TextRenderer.DrawText(e.Graphics, text, font, stringBounds, foreColor, flags );
}
// Draw the focus rect if required
//
if ((e.State & DrawItemState.Focus) == DrawItemState.Focus &&
(e.State & DrawItemState.NoFocusRect) != DrawItemState.NoFocusRect) {
ControlPaint.DrawFocusRectangle(e.Graphics, textBounds, foreColor, backColor);
}
}
}
示例6: OnMeasureItem
protected override void OnMeasureItem(MeasureItemEventArgs e)
{
StringFormat format = new StringFormat();
format.SetTabStops(0, new Single[] {0});
format.HotkeyPrefix = HotkeyPrefix.Show;
float textWidth = e.Graphics.MeasureString(GetFormattedText(), font, 50000, format).Width;
if (Parent.GetType().Equals(typeof(MainMenu))) {
e.ItemWidth = (int) (textWidth) - 2;
e.ItemHeight = SystemInformation.MenuHeight + 2;
} else {
e.ItemWidth = e.ItemHeight + (int)Math.Ceiling(textWidth) + sideBarWidth + 10;
if (IsSeparator()) {
e.ItemHeight = menuSeperaterWidth + 2;
} else {
e.ItemHeight = SystemInformation.MenuHeight + 2;
}
}
}
示例7: BeginPrint
void BeginPrint(object sender, PrintEventArgs ev)
{
curLineNr = 0;
printingStringFormat = (StringFormat)System.Drawing.StringFormat.GenericTypographic.Clone();
// 100 should be enough for everyone ...err ?
float[] tabStops = new float[100];
for (int i = 0; i < tabStops.Length; ++i) {
tabStops[i] = TabIndent * primaryTextArea.TextArea.TextView.WideSpaceWidth;
}
printingStringFormat.SetTabStops(0, tabStops);
}
示例8: DrawItem
/// <summary>
/// 繪製列表項
/// </summary>
/// <param name="g">繪圖表麵</param>
/// <param name="item">要繪製的列表項</param>
/// <param name="rectItem">該列表項的區域</param>
/// <param name="sb">畫刷</param>
protected virtual void DrawItem(Graphics g, ChatListItem item, Rectangle rectItem, SolidBrush sb)
{
StringFormat sf = new StringFormat();
sf.LineAlignment = StringAlignment.Center;
sf.SetTabStops(0.0F, new float[] { 20.0F });
if (item.Equals(m_mouseOnItem)) //根據列表項現在的狀態繪製相應的背景色
sb.Color = this.itemMouseOnColor;
else
sb.Color = this.itemColor;
g.FillRectangle(sb, rectItem);
if (item.IsOpen) { //如果展開的畫繪製 展開的三角形
sb.Color = this.arrowColor;
g.FillPolygon(sb, new Point[] {
new Point(2, rectItem.Top + 11),
new Point(12, rectItem.Top + 11),
new Point(7, rectItem.Top + 16) });
} else { //如果沒有展開判斷該列表項下麵的子項閃動的個數
if (item.TwinkleSubItemNumber > 0) { //如果列表項下麵有子項閃動 那麽判斷閃動狀態 是否繪製或者不繪製
if (item.IsTwinkleHide) //該布爾值 在線程中不停 取反賦值
return;
}
sb.Color = this.arrowColor;
g.FillPolygon(sb, new Point[] {
new Point(5, rectItem.Top + 8),
new Point(5, rectItem.Top + 18),
new Point(10, rectItem.Top + 13) });
}
string strItem = "\t" + item.Text;
sb.Color = this.ForeColor;
sf.Alignment = StringAlignment.Near;
g.DrawString(strItem, this.Font, sb, rectItem, sf);
sf.Alignment = StringAlignment.Far;
g.DrawString("[" + item.SubItems.GetOnLineNumber() + "/" + item.SubItems.Count + "]", this.Font, sb,
new Rectangle(rectItem.X, rectItem.Y, rectItem.Width - 15, rectItem.Height), sf);
}
示例9: ODGrid
///<summary></summary>
public ODGrid() {
//InitializeComponent();// Required for Windows.Forms Class Composition Designer support
//Add any constructor code after InitializeComponent call
columns=new ODGridColumnCollection();
rows=new ODGridRowCollection();
vScroll=new VScrollBar();
vScroll.Scroll+=new ScrollEventHandler(vScroll_Scroll);
vScroll.MouseEnter+=new EventHandler(vScroll_MouseEnter);
vScroll.MouseLeave+=new EventHandler(vScroll_MouseLeave);
vScroll.MouseMove+=new MouseEventHandler(vScroll_MouseMove);
hScroll=new HScrollBar();
hScroll.Scroll+=new ScrollEventHandler(hScroll_Scroll);
hScroll.MouseEnter+=new EventHandler(hScroll_MouseEnter);
hScroll.MouseLeave+=new EventHandler(hScroll_MouseLeave);
hScroll.MouseMove+=new MouseEventHandler(hScroll_MouseMove);
this.Controls.Add(vScroll);
this.Controls.Add(hScroll);
selectedIndices=new ArrayList();
selectedCell=new Point(-1,-1);
selectionMode=GridSelectionMode.One;
selectedRowColor=Color.Silver;
allowSelection=true;
wrapText=true;
noteSpanStart=0;
noteSpanStop=0;
sortedByColumnIdx=-1;
float[] arrayTabStops={50.0f};
_format=new StringFormat();
_format.SetTabStops(0.0f,arrayTabStops);
}
示例10: loadStringFormat
internal StringFormat loadStringFormat()
{
int nullMrk = reader.ReadInt32();
if (nullMrk == 0)
return null;
StringAlignment al;
int dsl;
StringDigitSubstitute dsm;
StringFormatFlags sff;
System.Drawing.Text.HotkeyPrefix hp;
StringAlignment lal;
StringTrimming tr;
float fto;
float[] ts;
al = (StringAlignment)reader.ReadInt32();
dsl = reader.ReadInt32();
dsm = (StringDigitSubstitute)reader.ReadInt32();
sff = (StringFormatFlags)reader.ReadInt32();
hp = (System.Drawing.Text.HotkeyPrefix)reader.ReadInt32();
lal = (StringAlignment)reader.ReadInt32();
tr = (StringTrimming)reader.ReadInt32();
fto = (float)reader.ReadDouble();
int len = reader.ReadInt32();
ts = new float[len];
for (int i = 0; i < len; ++i)
ts[i] = (float)reader.ReadDouble();
StringFormat res = new StringFormat(sff);
res.Alignment = al;
res.LineAlignment = lal;
res.SetDigitSubstitution(dsl, dsm);
res.HotkeyPrefix = hp;
res.Trimming = tr;
res.SetTabStops(fto, ts);
return res;
}
示例11: OnDrawItem
//.........這裏部分代碼省略.........
{
CheckBoxState state3 = CheckBoxRenderer.ConvertFromButtonState(normal, false, (e.State & DrawItemState.HotLight) == DrawItemState.HotLight);
CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(rectangle.X, rectangle.Y), state3);
}
else
{
ControlPaint.DrawCheckBox(e.Graphics, rectangle, normal);
}
Rectangle rect = new Rectangle((bounds.X + this.idealCheckSize) + (num * 2), bounds.Y, bounds.Width - (this.idealCheckSize + (num * 2)), bounds.Height);
if (this.RightToLeft == RightToLeft.Yes)
{
rect.X = bounds.X;
}
string s = "";
Color highlight = (this.SelectionMode != System.Windows.Forms.SelectionMode.None) ? e.BackColor : this.BackColor;
Color grayText = (this.SelectionMode != System.Windows.Forms.SelectionMode.None) ? e.ForeColor : this.ForeColor;
if (!base.Enabled)
{
grayText = SystemColors.GrayText;
}
Font font = this.Font;
s = base.GetItemText(obj2);
if ((this.SelectionMode != System.Windows.Forms.SelectionMode.None) && ((e.State & DrawItemState.Selected) == DrawItemState.Selected))
{
if (base.Enabled)
{
highlight = SystemColors.Highlight;
grayText = SystemColors.HighlightText;
}
else
{
highlight = SystemColors.InactiveBorder;
grayText = SystemColors.GrayText;
}
}
using (Brush brush = new SolidBrush(highlight))
{
e.Graphics.FillRectangle(brush, rect);
}
Rectangle layoutRectangle = new Rectangle(rect.X + 1, rect.Y, rect.Width - 1, rect.Height - (num * 2));
if (this.UseCompatibleTextRendering)
{
using (StringFormat format = new StringFormat())
{
if (base.UseTabStops)
{
float num4 = 3.6f * this.Font.Height;
float[] tabStops = new float[15];
float num5 = -(this.idealCheckSize + (num * 2));
for (int i = 1; i < tabStops.Length; i++)
{
tabStops[i] = num4;
}
if (Math.Abs(num5) < num4)
{
tabStops[0] = num4 + num5;
}
else
{
tabStops[0] = num4;
}
format.SetTabStops(0f, tabStops);
}
else if (base.UseCustomTabOffsets)
{
float[] destination = new float[base.CustomTabOffsets.Count];
base.CustomTabOffsets.CopyTo(destination, 0);
format.SetTabStops(0f, destination);
}
if (this.RightToLeft == RightToLeft.Yes)
{
format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
}
format.FormatFlags |= StringFormatFlags.NoWrap;
format.Trimming = StringTrimming.None;
using (SolidBrush brush2 = new SolidBrush(grayText))
{
e.Graphics.DrawString(s, font, brush2, layoutRectangle, format);
}
goto Label_049B;
}
}
TextFormatFlags flags = TextFormatFlags.Default;
flags |= TextFormatFlags.NoPrefix;
if (base.UseTabStops || base.UseCustomTabOffsets)
{
flags |= TextFormatFlags.ExpandTabs;
}
if (this.RightToLeft == RightToLeft.Yes)
{
flags |= TextFormatFlags.RightToLeft;
flags |= TextFormatFlags.Right;
}
TextRenderer.DrawText(e.Graphics, s, font, layoutRectangle, grayText, flags);
Label_049B:
if (((e.State & DrawItemState.Focus) == DrawItemState.Focus) && ((e.State & DrawItemState.NoFocusRect) != DrawItemState.NoFocusRect))
{
ControlPaint.DrawFocusRectangle(e.Graphics, rect, grayText, highlight);
}
}
示例12: UIControl_Paint
/// <summary>
/// Paint handler. Calculates the scaled tabstops based
/// on the scale factor. Displays text. The base class
/// scales the size of the font
/// </summary>
/// <param name="sender">event sender</param>
/// <param name="e">event args</param>
protected override void UIControl_Paint(object sender, PaintEventArgs e)
{
if (isDisposing)
{
return;
}
try
{
if (_originalTabStops == null || _scaledTabStops == null)
{
return;
}
_scaledFirstTab = _originalFirstTab * _scaleFactor;
_scaledTabStops = new float[_originalTabStops.Length];
for (int ii = 0; ii < _originalTabStops.Length; ii++)
{
_scaledTabStops[ii] = _originalTabStops[ii] * _scaleFactor;
}
Size s = measureDisplayStringSize(e.Graphics, GetText(), UIControl.Font);
// vertically center the text
var rect = new Rectangle(0, (Height - s.Height) / 2, Width, Height);
var stringFormat = new StringFormat();
var solidBrush = new SolidBrush(UIControl.ForeColor);
if (_scaledTabStops != null)
{
stringFormat.SetTabStops(_scaledFirstTab, _scaledTabStops);
}
e.Graphics.DrawString(GetText(), UIControl.Font, solidBrush, rect, stringFormat);
var pen = Pens.Transparent;
e.Graphics.DrawRectangle(pen, rect);
}
catch (Exception ex)
{
Log.Debug(ex.ToString());
}
}
示例13: BeginPrint
private void BeginPrint(object sender, PrintEventArgs ev)
{
curLineNr = 0;
printingStringFormat = (StringFormat)System.Drawing.StringFormat.GenericTypographic.Clone();
// 100 should be enough for everyone ...err ?
float[] tabStops = new float[100];
for (int i = 0; i < tabStops.Length; ++i)
{
tabStops[i] = scriptEditor.TabIndent * scriptEditor.ActiveTextAreaControl.TextArea.TextView.GetWidth(" ");
}
printingStringFormat.SetTabStops(0, tabStops);
}
示例14: DrawText
private void DrawText(Graphics graphics, Rectangle dest)
{
Brush br;
StringFormat format = new StringFormat();
format.SetTabStops(60, new Single[] {0});
format.HotkeyPrefix = HotkeyPrefix.Show;
// Alligned Right, looks messy. Because the letter widths are not equal
float scTextWidth = graphics.MeasureString(GetShortcutText(), font, 50000, format).Width;
int tabStopWidth = dest.Width - sideBarWidth - 5 - (int) Math.Ceiling(scTextWidth);
if (tabStopWidth > 0) {
format.SetTabStops(tabStopWidth, new Single[] {0});
}
if (Enabled) {
br = new SolidBrush(Color.Black);
} else {
br = new SolidBrush(Color.Gray);
}
graphics.DrawString(GetFormattedText(), font, br, dest.Left + sideBarWidth + 5, dest.Top + 4, format);
}
示例15: DrawMainMenu
private void DrawMainMenu(Graphics graphics, Rectangle dest, DrawItemState state)
{
if ((state & DrawItemState.HotLight) == DrawItemState.HotLight) {
graphics.FillRectangle(new SolidBrush(selectedGradientLeft), dest.X + 1, dest.Y, dest.Width - 1, dest.Height - 1);
graphics.DrawRectangle(new Pen(selectedBorder), dest.X + 1, dest.Y, dest.Width - 1, dest.Height - 1);
} else if ((state & DrawItemState.Selected) == DrawItemState.Selected) {
graphics.FillRectangle(new SolidBrush(sideBarColor), dest.X + 1, dest.Y + 1, dest.Width - 1, dest.Height - 1);
graphics.DrawLine(new Pen(selectedBorder), dest.Left + 1, dest.Top, dest.Left + 1, dest.Bottom - 1);
graphics.DrawLine(new Pen(selectedBorder), dest.Left + 1 + (dest.Width - 1), dest.Top + 1, dest.Left + 1 + (dest.Width - 1), dest.Bottom - 1);
graphics.DrawLine(new Pen(selectedBorder), dest.Left + 1, dest.Top, dest.Left + 1 + (dest.Width - 1), dest.Top);
} else {
graphics.FillRectangle(SystemBrushes.Control, dest.X, dest.Y, dest.Width + 1, dest.Height);
}
StringFormat format = new StringFormat();
format.HotkeyPrefix = HotkeyPrefix.Show;
format.SetTabStops(60, new Single[] {0});
graphics.DrawString(Text, font, Brushes.Black, dest.Left + 6, dest.Top + 3, format);
}