本文整理汇总了C#中System.Windows.Forms.RichTextBox.CreateGraphics方法的典型用法代码示例。如果您正苦于以下问题:C# RichTextBox.CreateGraphics方法的具体用法?C# RichTextBox.CreateGraphics怎么用?C# RichTextBox.CreateGraphics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.RichTextBox
的用法示例。
在下文中一共展示了RichTextBox.CreateGraphics方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PaintNoSpaceAfterPeriod
void PaintNoSpaceAfterPeriod(PaintEventArgs e, int Start, int End, RichTextBox RichText)
{
Graphics g;
g = RichText.CreateGraphics ();
//Pen myPen = null;// new Pen (Color.FromArgb (60, Color.Yellow)); // Alpha did not seem to work this way
// this gets tricky. The loop is just to find all the [[~scenes]] on the note
// even if offscreen.
// OK: but with th eoptimization to only show on screen stuff, do we need this anymore???
// august 10 - settting it back
// now trying regex
System.Text.RegularExpressions.Regex regex =
new System.Text.RegularExpressions.Regex ("\\.\\w|\\. \\w|\\?\\w|\\? \\w|\\!\\w|\\! \\w|\\;\\w|\\; \\w|\\:\\w|\\: \\w|\\,\\w|\\, \\w",
System.Text.RegularExpressions.RegexOptions.IgnoreCase | RegexOptions.Compiled|
System.Text.RegularExpressions.RegexOptions.Multiline);
System.Text.RegularExpressions.MatchCollection matches = regex.Matches (RichText.Text, Start);
foreach (System.Text.RegularExpressions.Match match in matches) {
if (match.Index > End)
break; // we exit if already at end
Point pos = RichText.GetPositionFromCharIndex (match.Index);
if (pos.X > -1 && pos.Y > -1) {
int testpos = match.Index + 2;
Color colorToUse = Color.FromArgb(175, Color.Red);
// default is [[facts]] and stuff
// pos = CoreUtilities.General.BuildLocationForOverlayText (pos, DockStyle.Bottom, " ");
// System.Drawing.SolidBrush brush1 = new System.Drawing.SolidBrush( colorToUse);
System.Drawing.Pen pen1 = new Pen(colorToUse);
//myPen.Width = 1;
//myPen.Color = Color.Red;
// int scaler = BuildScaler(RichText.ZoomFactor);
Rectangle rec = GetRectangleForSmallRectangle(g, pos, RichText, match.Index, match.Value, true);// new Rectangle (new Point (pos.X+(int)(scaler*1.5), pos.Y -(5+scaler)), new Size ((int)(scaler * 1.5), (int)(scaler * 1.5)));
//Rectangle rec = new Rectangle (new Point (pos.X+scaler, pos.Y-15), new Size ((int)(scaler * 1.5), (int)(scaler * 0.75)));
// Rectangle rec2 = new Rectangle (new Point (pos.X+20, pos.Y - 25), new Size ((int)(scaler * 1), (int)(scaler * 0.65)));
//g.DrawLine(myPen, pos.X, pos.Y -10, pos.X + 50, pos.Y-10);
//g.FillRectangle (brush1, rec);
//g.FillEllipse(brush1, rec);
rec.Height = 1;
g.DrawRectangle(pen1, rec);
// g.FillEllipse(brush1, rec2);
}
/*
locationInText = locationInText + sParam.Length;
if (locationInText > end)
{
// don't search past visible end
pos = emptyPoint;
}
else
pos = GetPositionForFoundText(sParam, ref locationInText);*/
}
// regex matches
g.Dispose ();
//myPen.Dispose ();
}
示例2: GetCharWidthInTwips
int GetCharWidthInTwips()
{
using (RichTextBox rtb = new RichTextBox())
{
rtb.Font = Font;
rtb.WordWrap = false;
rtb.Text = "XX";
Point p0 = rtb.GetPositionFromCharIndex(0);
Point p1 = rtb.GetPositionFromCharIndex(1);
using (Graphics g = rtb.CreateGraphics())
return (p1.X - p0.X) * 72 * 20 / Convert.ToInt32(g.DpiX);
}
}
示例3: SetTabWidth
public static void SetTabWidth(RichTextBox textBox, int tabWidth)
{
Graphics g = textBox.CreateGraphics();
SendMessage(textBox.Handle, EM_SETTABSTOPS, 1, new int[] { tabWidth * FONT_TO_TEMPLATE_WIDTH_RATIO });
}