本文整理汇总了C#中System.Drawing.StringFormat.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# StringFormat.Clone方法的具体用法?C# StringFormat.Clone怎么用?C# StringFormat.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.StringFormat
的用法示例。
在下文中一共展示了StringFormat.Clone方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MeasureString
public static SizeF MeasureString(Graphics g, string str, Font font, Rectangle rect, StringFormat sf)
{
var sfTemp = sf.Clone() as StringFormat;
var ranges = new CharacterRange[] { new CharacterRange(0, str.Length) };
sfTemp.SetMeasurableCharacterRanges(ranges);
var regions = g.MeasureCharacterRanges(str, font, rect, sfTemp);
if (regions != null && regions.Length > 0) return regions[0].GetBounds(g).Size;
return new SizeF();
}
示例2: HighlightString
private void HighlightString(Graphics g, PageText dtext, RectangleF r, Font f, StringFormat sf)
{
if (_HighlightText == null || _HighlightText.Length == 0)
return; // nothing to highlight
bool bhighlightItem = dtext == _HighlightItem ||
(_HighlightItem != null && dtext.HtmlParent == _HighlightItem);
if (!(_HighlightAll || bhighlightItem))
return; // not highlighting all and not on current highlight item
string hlt = _HighlightCaseSensitive ? _HighlightText : _HighlightText.ToLower();
string text = _HighlightCaseSensitive ? dtext.Text : dtext.Text.ToLower();
if (text.IndexOf(hlt) < 0)
return; // string not in text
StringFormat sf2 = null;
try
{
// Create a CharacterRange array with the highlight location and length
// Handle multiple occurences of text
List<CharacterRange> rangel = new List<CharacterRange>();
int loc = text.IndexOf(hlt);
int hlen = hlt.Length;
int len = text.Length;
while (loc >= 0)
{
rangel.Add(new CharacterRange(loc, hlen));
if (loc + hlen < len) // out of range of text
loc = text.IndexOf(hlt, loc + hlen);
else
loc = -1;
}
if (rangel.Count <= 0) // we should have gotten one; but
return;
CharacterRange[] ranges = rangel.ToArray();
// Construct a new StringFormat object.
sf2 = sf.Clone() as StringFormat;
// Set the ranges on the StringFormat object.
sf2.SetMeasurableCharacterRanges(ranges);
// Get the Regions to highlight by calling the
// MeasureCharacterRanges method.
if (r.Width <= 0 || r.Height <= 0)
{
SizeF ts = g.MeasureString(dtext.Text, f);
r.Height = ts.Height;
r.Width = ts.Width;
}
Region[] charRegion = g.MeasureCharacterRanges(dtext.Text, f, r, sf2);
// Fill in the region using a semi-transparent color to highlight
foreach (Region rg in charRegion)
{
Color hl = bhighlightItem ? _HighlightItemColor : _HighlightAllColor;
g.FillRegion(new SolidBrush(Color.FromArgb(50, hl)), rg);
}
}
catch { } // if highlighting fails we don't care; need to continue
finally
{
if (sf2 != null)
sf2.Dispose();
}
}
示例3: DrawBackground
//.........这里部分代码省略.........
{
bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.TitleBackPlain), 0, goalY, wsplit.Width, 16);
}
else
{
bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.TitleBack), 0, goalY, wsplit.Width, 16);
bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.TitleBack2), 0, goalY, wsplit.Width, 8);
}
}
}
}
// Compact mode - Draw the title bar
else if (wsplit.currentDispMode == DisplayMode.Compact)
{
if (Settings.Profile.BackgroundPlain)
bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.TitleBackPlain), 0, 0, wsplit.Width, 18);
else
{
bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.TitleBack), 0, 0, wsplit.Width, 15);
bgGraphics.FillRectangle(new SolidBrush(ColorSettings.Profile.TitleBack2), 0, 0, wsplit.Width, 7);
}
}
}
// Refactor? Only used once, never changes
StringFormat format3 = new StringFormat
{
LineAlignment = StringAlignment.Center,
Trimming = StringTrimming.EllipsisCharacter
};
// Only used once, Alignment changes
StringFormat format4 = (StringFormat)format3.Clone();
if (wsplit.currentDispMode == DisplayMode.Compact)
format4.Alignment = StringAlignment.Far;
string s = "";
string statusText = "";
// The run is not started yet
if (wsplit.timer.ElapsedTicks == 0L)
{
if (wsplit.currentDispMode != DisplayMode.Wide)
format4.Alignment = StringAlignment.Far;
if (wsplit.startDelay != null)
statusText = "Delay";
else
{
statusText = "Ready";
if (Settings.Profile.ShowAttempts && ((wsplit.currentDispMode != DisplayMode.Detailed) || !Settings.Profile.ShowTitle))
statusText += ", Attempt #" + (wsplit.split.AttemptsCount + 1);
}
}
// The run is done
else if (wsplit.split.Done)
{
if (wsplit.split.CompTime(wsplit.split.LastIndex) == 0.0)
{
if (wsplit.currentDispMode != DisplayMode.Wide)
format4.Alignment = StringAlignment.Far;
statusText = "Done";
示例4: PaintAll
//.........这里部分代码省略.........
string text = "";
string str4 = "";
double num10 = 0.0;
Brush white = Brushes.White;
if (wsplit.currentDispMode != DisplayMode.Timer)
{
if (wsplit.currentDispMode == DisplayMode.Wide)
{
layoutRectangle = new Rectangle(wsplit.Width - 119, 2, 119, wsplit.Height / 2);
rectangle2 = new Rectangle(wsplit.Width - 119, layoutRectangle.Bottom - 2, 119, wsplit.Height / 2);
}
else if (wsplit.currentDispMode == DisplayMode.Detailed)
{
layoutRectangle = new Rectangle(0, 0, 0, 0);
rectangle2 = new Rectangle(1, wsplit.clockRect.Bottom + 2, wsplit.Width - 1, 16);
}
else
{
rectangle2 = new Rectangle(1, 2, wsplit.Width - 1, 13);
layoutRectangle = new Rectangle(1, wsplit.clockRect.Bottom + 2, wsplit.Width - 1, 14);
if ((Settings.Profile.SegmentIcons > 0) && !wsplit.split.Done)
{
rectangle2.Width -= 2 + x;
rectangle2.X += 2 + x;
}
}
format.LineAlignment = StringAlignment.Center;
format.Trimming = StringTrimming.EllipsisCharacter;
format.Alignment = StringAlignment.Far;
format2 = (StringFormat)format.Clone();
if (wsplit.currentDispMode == DisplayMode.Compact)
format2.Alignment = StringAlignment.Near;
if (num3 <= 0.0)
this.segLosingTime = false;
if (wsplit.timer.ElapsedTicks != 0L)
{
if (wsplit.split.Done)
{
if (wsplit.split.CompTime(wsplit.split.LastIndex) != 0.0)
{
num10 = wsplit.split.SegDelta(wsplit.split.LastSegment.LiveTime, wsplit.split.LastIndex);
text = wsplit.timeFormatter(num10, TimeFormat.DeltaShort);
}
}
// If we are losing time on the current segment...
else if (num3 > 0.0)
{
num10 = num3; // The number to be written becomes the current segment delta
text = wsplit.timeFormatter(num10, TimeFormat.DeltaShort);
// If we just started losing time, we indicate we are and we ask for a redraw of the timer background since color has changed
if (!this.segLosingTime)
{
this.segLosingTime = true;
this.RequestBackgroundRedraw();
}
}
// If we aren't losing time on the current segment and if the current segment isn't the first segment...
示例5: DrawString
void DrawString(Graphics g, Brush brush, ref Rectangle rect, out Size used,
StringFormat format, string text, Font font)
{
using (StringFormat copy = (StringFormat)format.Clone())
{
copy.SetMeasurableCharacterRanges(new CharacterRange[]
{
new CharacterRange(0, text.Length)
});
Region[] regions = g.MeasureCharacterRanges(text, font, rect, copy);
g.DrawString(text, font, brush, rect, format);
int height = (int)(regions[0].GetBounds(g).Height);
int width = (int)(regions[0].GetBounds(g).Width);
// First just one line...
used = new Size(width, height);
rect.X += width;
rect.Width -= width;
}
}
示例6: DrawString
/// <summary>
/// Draws label string in oriented way.
/// </summary>
/// <param name="g"></param>
/// <param name="labelCaption"></param>
/// <param name="labelFont"></param>
/// <param name="labelBrush"></param>
/// <param name="yOffset">Y Offset value (in pixel)</param>
/// <param name="xyLocation"></param>
/// <param name="_stringFormat"></param>
/// <param name="orientationAngle">-90 to +90 degrees</param>
private void DrawString(Graphics g, string labelCaption, bool ShowLabelAboveChart, Font labelFont, Brush labelBrush, PointF xyLocation, int yOffset, StringFormat _stringFormat, int orientationAngle)
{
try
{
//-- Apply Y Offset Settings
xyLocation.Y += (-1) * yOffset;
//- Get Label's measurement
SizeF labelSize = g.MeasureString(labelCaption, labelFont);
if (orientationAngle != 0)
{
orientationAngle = orientationAngle * -1;
//-- To draw orientated text label,
// draw string in new graphics object with Rotation applied,
// convert that into image object and then add image object into original graphics object
StringFormat NewStringFormat = (StringFormat)(_stringFormat.Clone());
NewStringFormat.Alignment = StringAlignment.Near;
//-- Get image rectangular Area considering Label's orientationAngle too (height should accomodate orientation)
Bitmap stringImg = new Bitmap((int)labelSize.Width + 10, (int)(labelSize.Width) + 10);
Graphics gbitmap = Graphics.FromImage(stringImg);
gbitmap.SmoothingMode = SmoothingMode.AntiAlias;
gbitmap.Clear(Color.Transparent);
PointF xyPos = new PointF();
xyPos.X = 0 - labelSize.Width / 2;
xyPos.Y = 0 - labelSize.Height / 2;
int TextOffsetX = (int)(labelSize.Height / 2);
//-- Calculate transformed distance caused due to rotation
float XTransformed = TextOffsetX + labelSize.Width / 2;
float YTransformed = TextOffsetX + labelSize.Width / 2;
gbitmap.TranslateTransform(XTransformed, YTransformed);
gbitmap.RotateTransform(orientationAngle);
gbitmap.DrawString(labelCaption, labelFont, labelBrush, xyPos, NewStringFormat);
//add image object into original graphics object
if (ShowLabelAboveChart)
{
//-- Show label above Chart (i.e Case of DataValue Label)
g.DrawImage(stringImg, xyLocation.X - (labelSize.Width / 2), xyLocation.Y - (labelSize.Width * 0.75F) - (labelSize.Width * 0.56F) * (float)(Math.Sin(Math.Abs(orientationAngle) * Math.PI / 180)));
}
else
{
//-- Show label below Chart (i.e Case of TimePeriod Label)
g.DrawImage(stringImg, xyLocation.X + 2 - (labelSize.Width / 2) - TextOffsetX / 2, xyLocation.Y - (labelSize.Height / 2) - TextOffsetX);
}
//dispose your bitmap and graphics objects at the end of onpaint
gbitmap.Dispose();
stringImg.Dispose();
}
else
{
if (ShowLabelAboveChart)
{
xyLocation.Y = xyLocation.Y - (labelSize.Height * 0.5F);
}
g.DrawString(labelCaption, labelFont, labelBrush, xyLocation, _stringFormat);
}
}
catch
{
}
}
示例7: Clone_Complex
public void Clone_Complex ()
{
using (StringFormat sf = new StringFormat ()) {
CharacterRange[] ranges = new CharacterRange [2];
ranges[0].First = 1;
ranges[0].Length = 2;
ranges[1].First = 3;
ranges[1].Length = 4;
sf.SetMeasurableCharacterRanges (ranges);
float[] stops = new float [2];
stops [0] = 6.0f;
stops [1] = 7.0f;
sf.SetTabStops (5.0f, stops);
using (StringFormat clone = (StringFormat) sf.Clone ()) {
CheckDefaults (clone);
float first;
float[] cloned_stops = clone.GetTabStops (out first);
Assert.AreEqual (5.0f, first, "first");
Assert.AreEqual (6.0f, cloned_stops[0], "cloned_stops[0]");
Assert.AreEqual (7.0f, cloned_stops[1], "cloned_stops[1]");
}
}
}
示例8: Clone
public void Clone()
{
using (StringFormat sf = new StringFormat ()) {
using (StringFormat clone = (StringFormat) sf.Clone ()) {
CheckDefaults (clone);
}
}
}
示例9: GetMeasuredItems
public override IMeasuredLabelItem[] GetMeasuredItems(Graphics g, Font font, StringFormat strfmt, Altaxo.Data.AltaxoVariant[] items)
{
MeasuredLabelItem[] litems = new MeasuredLabelItem[items.Length];
Font localfont1 = (Font)font.Clone();
Font localfont2 = new Font(font.FontFamily, font.Size * 2 / 3, font.Style, GraphicsUnit.World);
StringFormat localstrfmt = (StringFormat)strfmt.Clone();
string[] firstp = new string[items.Length];
string[] expos = new string[items.Length];
float maxexposize=0;
for (int i = 0; i < items.Length; ++i)
{
string firstpart, exponent;
if (items[i].IsType(Altaxo.Data.AltaxoVariant.Content.VDouble))
{
SplitInFirstPartAndExponent((double)items[i], out firstpart, out exponent);
}
else
{
firstpart = items[i].ToString(); exponent = string.Empty;
}
firstp[i] = firstpart;
expos[i] = exponent;
maxexposize = Math.Max(maxexposize,g.MeasureString(exponent,localfont2,new PointF(0,0),strfmt).Width);
}
for (int i = 0; i < items.Length; ++i)
{
litems[i] = new MeasuredLabelItem(g, localfont1, localfont2, localstrfmt, firstp[i],expos[i],maxexposize);
}
return litems;
}
示例10: GetMeasuredItems
public override IMeasuredLabelItem[] GetMeasuredItems(Graphics g, FontX font, StringFormat strfmt, Altaxo.Data.AltaxoVariant[] items)
{
MeasuredLabelItem[] litems = new MeasuredLabelItem[items.Length];
FontX localfont1 = font;
FontX localfont2 = font.WithSize(font.Size * 2 / 3);
StringFormat localstrfmt = (StringFormat)strfmt.Clone();
string[] firstp = new string[items.Length];
string[] middel = new string[items.Length];
string[] expos = new string[items.Length];
double[] mants = new double[items.Length];
float maxexposize = 0;
int firstpartmin = int.MaxValue;
int firstpartmax = int.MinValue;
for (int i = 0; i < items.Length; ++i)
{
string firstpart, exponent;
if (items[i].IsType(Altaxo.Data.AltaxoVariant.Content.VDouble))
{
SplitInFirstPartAndExponent((double)items[i], out firstpart, out mants[i], out middel[i], out exponent);
if (exponent.Length > 0)
{
firstpartmin = Math.Min(firstpartmin, firstpart.Length);
firstpartmax = Math.Max(firstpartmax, firstpart.Length);
}
}
else
{
firstpart = items[i].ToString(); middel[i] = string.Empty; exponent = string.Empty;
}
firstp[i] = firstpart;
expos[i] = exponent;
maxexposize = Math.Max(maxexposize, g.MeasureString(exponent, GdiFontManager.ToGdi(localfont2), new PointF(0, 0), strfmt).Width);
}
if (firstpartmax > 0 && firstpartmax > firstpartmin) // then we must use special measures to equilibrate the mantissa
{
firstp = NumericLabelFormattingAuto.FormatItems(mants);
}
for (int i = 0; i < items.Length; ++i)
{
string mid = string.Empty;
if (!string.IsNullOrEmpty(expos[i]))
{
if (string.IsNullOrEmpty(firstp[i]))
mid = "10";
else
mid = "\u00D710";
}
litems[i] = new MeasuredLabelItem(g, localfont1, localfont2, localstrfmt, _prefix + firstp[i] + mid, expos[i], _suffix, maxexposize);
}
return litems;
}