本文整理汇总了C#中System.Windows.Forms.Control.CreateGraphics方法的典型用法代码示例。如果您正苦于以下问题:C# Control.CreateGraphics方法的具体用法?C# Control.CreateGraphics怎么用?C# Control.CreateGraphics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Control
的用法示例。
在下文中一共展示了Control.CreateGraphics方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisibleSurface
public VisibleSurface(Control surface)
: base(surface.Width, surface.Height)
{
base.DC = surface.CreateGraphics();
base.Buffer = new Backbuffer(this);
this.RedrawDirtyRectangleOnly = true;
}
示例2: GetImage
public static Image GetImage(Control c_)
{
Graphics g = null;
Image ret = null;
try
{
if (c_ is Form)
c_.BringToFront();
else
c_.FindForm().BringToFront();
Application.DoEvents();
g = c_.CreateGraphics();
ret = new Bitmap(c_.ClientRectangle.Width, c_.ClientRectangle.Height, g);
Graphics g2 = Graphics.FromImage(ret);
IntPtr dc1 = g.GetHdc();
IntPtr dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0, c_.ClientRectangle.Width, c_.ClientRectangle.Height, dc1, 0, 0, 13369376);
g.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
}
finally
{
if (g != null)
g.Dispose();
}
return ret;
}
示例3: GetCompactPath
public static string GetCompactPath(this FileSystemInfo info, int newWidth, Font drawFont)
{
using (Control ctrl = new Control())
{
Graphics g = ctrl.CreateGraphics();
string longPath = info.FullName;
int width = g.MeasureString(longPath, drawFont).ToSize().Width;
if (width <= newWidth)
return longPath;
int aveCharWidth = width / longPath.Length;
int charCount = newWidth / aveCharWidth;
StringBuilder builder = new StringBuilder();
builder.Append(longPath);
builder.EnsureCapacity(charCount);
while (g.MeasureString(builder.ToString(), drawFont).Width > newWidth)
{
if (!NativeMethods.PathCompactPathEx(builder, longPath,
(uint)charCount--, 0))
{
return string.Empty;
}
}
return builder.ToString();
}
}
示例4: XmlSerialize
public void XmlSerialize(XmlWriter writer, Control detailView)
{
writer.WriteStartElement("DetailView");
int dpiX = 0x60;
int dpiY = 0x60;
if (true)
{
Graphics graphics = detailView.CreateGraphics();
dpiX = (int) graphics.DpiX;
dpiY = (int) graphics.DpiY;
graphics.Dispose();
graphics = null;
}
writer.WriteAttributeString("DpiX", Convert.ToString(dpiX));
writer.WriteAttributeString("DpiY", Convert.ToString(dpiY));
this.SerializeDetailViewProperties(writer, detailView);
IList propertyValue = (IList) ReflectionHelper.GetPropertyValue(detailView, "Items");
foreach (object obj2 in propertyValue)
{
writer.WriteStartElement("Item");
Type type = obj2.GetType();
if (type.Assembly.ManifestModule.Name.ToLower().StartsWith("resco.detailview"))
{
writer.WriteAttributeString("Type", type.FullName);
}
else
{
writer.WriteAttributeString("Type", type.AssemblyQualifiedName);
}
this.SerializeProperties(writer, obj2);
writer.WriteEndElement();
}
}
示例5: CalculateGraphicsProportion
/// <summary>
/// Returns relation between current graphics resolution and default DpiY (96.0).
/// Can be used when arranging controls and resizing forms.
/// </summary>
/// <param name="control"></param>
/// <returns></returns>
public static float CalculateGraphicsProportion(Control control)
{
Graphics graphics = control.CreateGraphics();
float proportion = (float)(graphics.DpiY / 96.0);
graphics.Dispose();
return proportion;
}
示例6: IsClientRectangleVisible
/// <summary>
/// Returns true if any part of the client based rectangle is visible.
/// </summary>
/// <param name="control">Control to check.</param>
/// <param name="rectangleToCheck">Client based rectangle to check.</param>
public static bool IsClientRectangleVisible( Control control, Rectangle rectangleToCheck )
{
if( !control.IsHandleCreated )
{
return false;
}
Utility.Win32.Common.RECT rcClip, rcClient = new Utility.Win32.Common.RECT( rectangleToCheck );
using( Graphics grfx = control.CreateGraphics() )
{
IntPtr hdc = IntPtr.Zero;
try
{
hdc = grfx.GetHdc();
RegionValue result = (RegionValue) Gdi.GetClipBox( hdc, out rcClip );
return result != RegionValue.NULLREGION;
}
finally
{
if( hdc != IntPtr.Zero )
{
grfx.ReleaseHdc( hdc );
}
}
}
}
示例7: GetTextWidth
/// <summary>
/// This method provides the width of a given text, with the given font
///
/// </summary>
/// <param name="text"></param>
/// <param name="size"></param>
/// <returns>Text width</returns>
protected int GetTextWidth(string text, Control control)
{
float textwidth=0;
Graphics g = control.CreateGraphics();
textwidth = (int)g.MeasureString(text, control.Font).Width;
g.Dispose();
return (int)Math.Ceiling(textwidth);
}
示例8: GenerateBackground
public void GenerateBackground(Control control)
{
Graphics g = control.CreateGraphics();
Size size = control.ClientSize;
GenerateBackground(g, size);
g.Dispose();
}
示例9: TextGeometry
public TextGeometry(Control control)
{
this.control = control;
g = control.CreateGraphics();
stringFormat.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
charWidth = MeasureString("_");
lineHeight = Font.Height;
}
示例10: Graphics
/// <summary>
/// Instantiates a new <see cref="Graphics"/> object with the specified
/// <paramref name="control"/>.
/// </summary>
/// <param name="control">The desired value of
/// <see cref="Control"/>.</param>
/// <exception cref="ArgumentNullException"><paramref name="control"/>
/// is <c>null</c>.</exception>
public Graphics(Control control)
{
if (ReferenceEquals(control, null))
{
throw new ArgumentNullException(nameof(control));
}
Control = control;
native = Control.CreateGraphics();
}
示例11: LoadDeviceScaling
private static void LoadDeviceScaling()
{
using (var control = new Control())
{
using (var graphics = control.CreateGraphics())
{
_deviceScaleX = 96.0 / graphics.DpiX;
_deviceScaleY = 96.0 / graphics.DpiY;
}
}
}
示例12: ObjectNet
public ObjectNet(string name, ObjectSequence inObj, ObjectSequence outObj, Control _ControlHandle)
{
netName = name;
inputObject = inObj;
inputObject.UpdatePosition += new ObjectSequence.ObjectPosistionMove(inputObject_UpdatePosition);
outputObject = outObj;
outputObject.UpdatePosition += new ObjectSequence.ObjectPosistionMove(outputObject_UpdatePosition);
canvas = _ControlHandle.CreateGraphics();
}
示例13: AnimateGradient
public AnimateGradient(Control control, Color color1, Color color2, float gradientAngle, Control label)
{
_timer.Interval = 100;
_timer.Tick += _timer_Tick;
_control = control;
_clientRectangle = control.ClientRectangle;
_graphics = control.CreateGraphics();
_angle = gradientAngle;
_color1 = color1;
_color2 = color2;
_label = label;
}
示例14: CaptureScreen
public Bitmap CaptureScreen(Control con, int fromX, int fromY)
{
Size size = con.Size;
Graphics g = con.CreateGraphics();
Bitmap image = new Bitmap(size.Width - fromX, size.Height - fromY, g);
Graphics graphics2 = Graphics.FromImage(image);
IntPtr hdc = g.GetHdc();
IntPtr hdcDest = graphics2.GetHdc();
BitBlt(hdcDest, 0, 0, con.ClientRectangle.Width - fromX, con.ClientRectangle.Height - fromY, hdc, fromX, fromY, 0xcc0020);
g.ReleaseHdc(hdc);
graphics2.ReleaseHdc(hdcDest);
return image;
}
示例15: smethod_0
// Token: 0x060025F9 RID: 9721
// RVA: 0x000E3B88 File Offset: 0x000E1D88
internal static float smethod_0(Control control_0, bool bool_0)
{
if (!bool_0 && Class611.float_0 > 0f)
{
return Class611.float_0;
}
float result;
using (Graphics graphics = control_0.CreateGraphics())
{
result = (Class611.float_0 = graphics.DpiX);
}
return result;
}