本文整理汇总了C#中System.Windows.Forms.IDeviceContext类的典型用法代码示例。如果您正苦于以下问题:C# IDeviceContext类的具体用法?C# IDeviceContext怎么用?C# IDeviceContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IDeviceContext类属于System.Windows.Forms命名空间,在下文中一共展示了IDeviceContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SizeDialog
public static Size SizeDialog(IDeviceContext dc, string mainInstruction, string content, Screen screen, Font mainInstructionFallbackFont, Font contentFallbackFont, int horizontalSpacing, int verticalSpacing, int minimumWidth, int textMinimumHeight)
{
int width = minimumWidth - horizontalSpacing;
int height = GetTextHeight(dc, mainInstruction, content, mainInstructionFallbackFont, contentFallbackFont, width);
while( height > width )
{
int area = height * width;
width = (int)(Math.Sqrt(area) * 1.1);
height = GetTextHeight(dc, mainInstruction, content, mainInstructionFallbackFont, contentFallbackFont, width);
}
if( height < textMinimumHeight )
height = textMinimumHeight;
int newWidth = width + horizontalSpacing;
int newHeight = height + verticalSpacing;
Rectangle workingArea = screen.WorkingArea;
if( newHeight > 0.9 * workingArea.Height )
{
int area = height * width;
newHeight = (int)(0.9 * workingArea.Height);
height = newHeight - verticalSpacing;
width = area / height;
newWidth = width + horizontalSpacing;
}
// If this happens the text won't display correctly, but even at 800x600 you need
// to put so much text in the input box for this to happen that I don't care.
if( newWidth > 0.9 * workingArea.Width )
newWidth = (int)(0.9 * workingArea.Width);
return new Size(newWidth, newHeight);
}
开发者ID:RogovaTatiana,项目名称:FilesSync,代码行数:35,代码来源:DialogHelper.cs
示例2: DrawText
/// <include file='doc\TextRenderer.uex' path='docs/doc[@for="TextRenderer.DrawText1"]/*' />
public static void DrawText(IDeviceContext dc, string text, Font font, Point pt, Color foreColor, Color backColor)
{
if (dc == null)
{
throw new ArgumentNullException("dc");
}
WindowsFontQuality fontQuality = WindowsFont.WindowsFontQualityFromTextRenderingHint(dc as Graphics);
IntPtr hdc = dc.GetHdc();
try
{
using( WindowsGraphics wg = WindowsGraphics.FromHdc( hdc ))
{
using (WindowsFont wf = WindowsGraphicsCacheManager.GetWindowsFont(font, fontQuality)) {
wg.DrawText(text, wf, pt, foreColor, backColor);
}
}
}
finally
{
dc.ReleaseHdc();
}
}
开发者ID:JianwenSun,项目名称:cc,代码行数:26,代码来源:TextRenderer.cs
示例3: GetTextHeight
public static int GetTextHeight(IDeviceContext dc, string mainInstruction, string content, Font mainInstructionFallbackFont, Font contentFallbackFont, int width)
{
// compute the height the text needs at the current dialog width.
Point location = Point.Empty;
DrawText(dc, mainInstruction, content, ref location, mainInstructionFallbackFont, contentFallbackFont, true, width);
return location.Y;
}
开发者ID:RogovaTatiana,项目名称:FilesSync,代码行数:7,代码来源:DialogHelper.cs
示例4: DrawEdge
public Rectangle DrawEdge(IDeviceContext dc, Rectangle bounds, Edges edges, EdgeStyle style, EdgeEffects effects)
{
if (dc == null)
{
throw new ArgumentNullException("dc");
}
if (!System.Windows.Forms.ClientUtils.IsEnumValid_Masked(edges, (int) edges, 0x1f))
{
throw new InvalidEnumArgumentException("edges", (int) edges, typeof(Edges));
}
if (!System.Windows.Forms.ClientUtils.IsEnumValid_NotSequential(style, (int) style, new int[] { 5, 10, 6, 9 }))
{
throw new InvalidEnumArgumentException("style", (int) style, typeof(EdgeStyle));
}
if (!System.Windows.Forms.ClientUtils.IsEnumValid_Masked(effects, (int) effects, 0xd800))
{
throw new InvalidEnumArgumentException("effects", (int) effects, typeof(EdgeEffects));
}
System.Windows.Forms.NativeMethods.COMRECT pContentRect = new System.Windows.Forms.NativeMethods.COMRECT();
using (WindowsGraphicsWrapper wrapper = new WindowsGraphicsWrapper(dc, TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping))
{
HandleRef hdc = new HandleRef(wrapper, wrapper.WindowsGraphics.DeviceContext.Hdc);
this.lastHResult = System.Windows.Forms.SafeNativeMethods.DrawThemeEdge(new HandleRef(this, this.Handle), hdc, this.part, this.state, new System.Windows.Forms.NativeMethods.COMRECT(bounds), (int) style, ((int) (edges | ((Edges) ((int) effects)))) | 0x2000, pContentRect);
}
return Rectangle.FromLTRB(pContentRect.left, pContentRect.top, pContentRect.right, pContentRect.bottom);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:26,代码来源:VisualStyleRenderer.cs
示例5: DrawCloseButton
public static void DrawCloseButton(IDeviceContext dc, Rectangle rect, Padding padding, ToolTipBalloonCloseButtonState buttonState)
{
VisualStyleElement btn = GetCloseButtonVS(buttonState);
VisualStyleRenderer renderer = new VisualStyleRenderer(btn);
Rectangle btnRect = GetCloseButtonRect(dc, rect, padding, buttonState);
renderer.DrawBackground(dc, btnRect);
}
开发者ID:fiftin,项目名称:WinFormsPopupAlerts,代码行数:7,代码来源:ToolTipBalloonDrawingHelper.cs
示例6: Draw
public static void Draw(IDeviceContext dc, Size minSize, Size maxSize, string title, string text, Rectangle titleRect, Rectangle rect, ToolTipIcon icon, Padding padding)
{
if (Application.RenderWithVisualStyles)
{
VisualStyleRenderer titleRenderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.BalloonTitle.Normal);
VisualStyleRenderer balloonRenderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.Balloon.Normal);
balloonRenderer.DrawBackground(dc, rect);
if (icon == ToolTipIcon.None)
{
titleRenderer.DrawText(dc, new Rectangle(padding.Left, padding.Top, rect.Width - (padding.Left + padding.Right), titleRect.Height),
title, false, TextFormatFlags.Left | TextFormatFlags.WordEllipsis | TextFormatFlags.VerticalCenter);
Rectangle balloonTextBounds = new Rectangle(padding.Left, padding.Top + titleRect.Height, rect.Width - (padding.Left + padding.Right), rect.Height - (padding.Top + titleRect.Height + padding.Bottom));
balloonRenderer.DrawText(dc, balloonTextBounds,
text, false, TextFormatFlags.Left | TextFormatFlags.WordBreak | TextFormatFlags.VerticalCenter);
}
else
{
throw new NotImplementedException();
}
}
else
{
throw new NotImplementedException();
}
}
开发者ID:fiftin,项目名称:WinFormsPopupAlerts,代码行数:28,代码来源:ToolTipBalloonDrawingHelper.cs
示例7: BuildLookupList
private static void BuildLookupList(IDeviceContext g, Font font, ref SizeF[] size)
{
size = new SizeF[char.MaxValue];
for (var i = (char)0; i < (char)256; i++)
{
size[i] = MeasureString(g, font, i.ToString());
}
}
开发者ID:duyisu,项目名称:MissionPlanner,代码行数:8,代码来源:MeasureString.cs
示例8: DrawThemeBackground
private static void DrawThemeBackground(IDeviceContext dc, VisualStyleElement element, Rectangle bounds, Rectangle clipRectangle)
{
if( DialogHelper.IsTaskDialogThemeSupported )
{
VisualStyleRenderer renderer = new VisualStyleRenderer(element);
renderer.DrawBackground(dc, bounds, clipRectangle);
}
}
开发者ID:Xtremrules,项目名称:dot42,代码行数:8,代码来源:InputDialogForm.cs
示例9: WindowsGraphicsWrapper
public WindowsGraphicsWrapper( IDeviceContext idc, TextFormatFlags flags)
{
if( idc is Graphics )
{
ApplyGraphicsProperties properties = ApplyGraphicsProperties.None;
if( (flags & TextFormatFlags.PreserveGraphicsClipping) != 0)
{
properties |= ApplyGraphicsProperties.Clipping;
}
if( (flags & TextFormatFlags.PreserveGraphicsTranslateTransform) != 0)
{
properties |= ApplyGraphicsProperties.TranslateTransform;
}
// Create the WindowsGraphics from the Grahpics object only if Graphics properties need
// to be reapplied to the DC wrapped by the WindowsGraphics.
if( properties != ApplyGraphicsProperties.None )
{
this.wg = WindowsGraphics.FromGraphics( idc as Graphics, properties);
}
}
else
{
// If passed-in IDeviceContext object is a WindowsGraphics we can use it directly.
this.wg = idc as WindowsGraphics;
if( this.wg != null )
{
// In this case we cache the idc to compare it against the wg in the Dispose method to avoid
// disposing of the wg.
this.idc = idc;
}
}
if( this.wg == null )
{
// The IDeviceContext object is not a WindowsGraphics, or it is a custom IDeviceContext, or
// it is a Graphics object but we did not need to re-apply Graphics propertiesto the hdc.
// So create the WindowsGraphics from the hdc directly.
// Cache the IDC so the hdc can be released on dispose.
this.idc = idc;
this.wg = WindowsGraphics.FromHdc( idc.GetHdc() );
}
// Set text padding on the WindowsGraphics (if any).
if( (flags & TextFormatFlags.LeftAndRightPadding) != 0 )
{
wg.TextPadding = TextPaddingOptions.LeftAndRightPadding;
}
else if ((flags & TextFormatFlags.NoPadding) != 0 )
{
wg.TextPadding = TextPaddingOptions.NoPadding;
}
// else wg.TextPadding = TextPaddingOptions.GlyphOverhangPadding - the default value.
}
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:57,代码来源:WindowsGraphicsWrapper.cs
示例10: MeasureString
private static SizeF MeasureString(IDeviceContext g, IList text, Font font, FontData data)
{
SizeF ans = new SizeF();
foreach (char chr in text)
{
SizeF temp = MeasureString(g, chr, font, data);
ans = new SizeF(ans.Width + temp.Width, temp.Height);
}
return ans;
}
开发者ID:duyisu,项目名称:MissionPlanner,代码行数:10,代码来源:MeasureString.cs
示例11: DrawText
//
// Summary:
// Draws the specified text at the specified location using the specified device
// context, font, color, and formatting instructions.
//
// Parameters:
// foreColor:
// The System.Drawing.Color to apply to the drawn text.
//
// font:
// The System.Drawing.Font to apply to the drawn text.
//
// dc:
// The device context in which to draw the text.
//
// pt:
// The System.Drawing.Point that represents the upper-left corner of the drawn
// text.
//
// flags:
// A bitwise combination of the System.Drawing.GDI.TextFormatFlags values.
//
// text:
// The text to draw.
//
// Exceptions:
// System.ArgumentNullException:
// dc is null.
public static void DrawText(IDeviceContext dc, string text, Font font, Rectangle rc, Color foreColor, TextFormatFlags flags)
{
Graphics grfx = dc as Graphics;
if (grfx != null)
{
rc.X += (int) grfx.Transform.OffsetX;
rc.Y += (int) grfx.Transform.OffsetY;
}
TextRenderer.DrawText(dc, text, font, rc, foreColor, flags);
}
开发者ID:CecleCW,项目名称:ProductMan,代码行数:39,代码来源:TextRendererEx.cs
示例12: DrawText
public static void DrawText(IDeviceContext dc, string mainInstruction, string content, ref Point location, Font mainInstructionFallbackFont, Font contentFallbackFont, bool measureOnly, int width)
{
if( !string.IsNullOrEmpty(mainInstruction) )
DrawText(dc, mainInstruction, AdditionalVisualStyleElements.TextStyle.MainInstruction, mainInstructionFallbackFont, ref location, measureOnly, width);
if( !string.IsNullOrEmpty(content) )
{
if( !string.IsNullOrEmpty(mainInstruction) )
content = Environment.NewLine + content;
DrawText(dc, content, AdditionalVisualStyleElements.TextStyle.BodyText, contentFallbackFont, ref location, measureOnly, width);
}
}
开发者ID:GamehubDev,项目名称:Nin_Online_Unity,代码行数:13,代码来源:DialogHelper.cs
示例13: DrawBackground
public void DrawBackground(IDeviceContext dc, Rectangle bounds, Rectangle clipRectangle)
{
if (dc == null)
{
throw new ArgumentNullException("dc");
}
if (((bounds.Width >= 0) && (bounds.Height >= 0)) && ((clipRectangle.Width >= 0) && (clipRectangle.Height >= 0)))
{
using (WindowsGraphicsWrapper wrapper = new WindowsGraphicsWrapper(dc, TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping))
{
HandleRef hdc = new HandleRef(wrapper, wrapper.WindowsGraphics.DeviceContext.Hdc);
this.lastHResult = System.Windows.Forms.SafeNativeMethods.DrawThemeBackground(new HandleRef(this, this.Handle), hdc, this.part, this.state, new System.Windows.Forms.NativeMethods.COMRECT(bounds), new System.Windows.Forms.NativeMethods.COMRECT(clipRectangle));
}
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:15,代码来源:VisualStyleRenderer.cs
示例14: WindowsGraphicsWrapper
public WindowsGraphicsWrapper(IDeviceContext idc, TextFormatFlags flags)
{
if (idc is Graphics)
{
ApplyGraphicsProperties none = ApplyGraphicsProperties.None;
if ((flags & TextFormatFlags.PreserveGraphicsClipping) != TextFormatFlags.Default)
{
none |= ApplyGraphicsProperties.Clipping;
}
if ((flags & TextFormatFlags.PreserveGraphicsTranslateTransform) != TextFormatFlags.Default)
{
none |= ApplyGraphicsProperties.TranslateTransform;
}
if (none != ApplyGraphicsProperties.None)
{
this.wg = System.Windows.Forms.Internal.WindowsGraphics.FromGraphics(idc as Graphics, none);
}
}
else
{
this.wg = idc as System.Windows.Forms.Internal.WindowsGraphics;
if (this.wg != null)
{
this.idc = idc;
}
}
if (this.wg == null)
{
this.idc = idc;
this.wg = System.Windows.Forms.Internal.WindowsGraphics.FromHdc(idc.GetHdc());
}
if ((flags & TextFormatFlags.LeftAndRightPadding) != TextFormatFlags.Default)
{
this.wg.TextPadding = TextPaddingOptions.LeftAndRightPadding;
}
else if ((flags & TextFormatFlags.NoPadding) != TextFormatFlags.Default)
{
this.wg.TextPadding = TextPaddingOptions.NoPadding;
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:40,代码来源:WindowsGraphicsWrapper.cs
示例15: DrawText
public static void DrawText(IDeviceContext dc, string text, VisualStyleElement element, Font fallbackFont, ref Point location, bool measureOnly, int width)
{
// For Windows 2000, using Int32.MaxValue for the height doesn't seem to work, so we'll just pick another arbitrary large value
// that does work.
Rectangle textRect = new Rectangle(location.X, location.Y, width, NativeMethods.IsWindowsXPOrLater ? Int32.MaxValue : 100000);
TextFormatFlags flags = TextFormatFlags.WordBreak;
if( IsTaskDialogThemeSupported )
{
VisualStyleRenderer renderer = new VisualStyleRenderer(element);
Rectangle textSize = renderer.GetTextExtent(dc, textRect, text, flags);
location = location + new Size(0, textSize.Height);
if( !measureOnly )
renderer.DrawText(dc, textSize, text, false, flags);
}
else
{
if( !measureOnly )
TextRenderer.DrawText(dc, text, fallbackFont, textRect, SystemColors.WindowText, flags);
Size textSize = TextRenderer.MeasureText(dc, text, fallbackFont, new Size(textRect.Width, textRect.Height), flags);
location = location + new Size(0, textSize.Height);
}
}
开发者ID:RogovaTatiana,项目名称:FilesSync,代码行数:22,代码来源:DialogHelper.cs
示例16: DrawText
public static void DrawText(IDeviceContext dc, string text, Font font, Rectangle bounds, Color foreColor)
{
if (dc == null)
{
throw new ArgumentNullException("dc");
}
WindowsFontQuality fontQuality = WindowsFont.WindowsFontQualityFromTextRenderingHint(dc as Graphics);
IntPtr hdc = dc.GetHdc();
try
{
using (WindowsGraphics graphics = WindowsGraphics.FromHdc(hdc))
{
using (WindowsFont font2 = WindowsGraphicsCacheManager.GetWindowsFont(font, fontQuality))
{
graphics.DrawText(text, font2, bounds, foreColor);
}
}
}
finally
{
dc.ReleaseHdc();
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:23,代码来源:TextRenderer.cs
示例17: GetBodyRect
public static Rectangle GetBodyRect(IDeviceContext dc, Size minSize, Size maxSize, string text, Rectangle titleRect, ToolTipIcon icon, Padding padding)
{
Rectangle ret;
if (text == null)
{
ret = new Rectangle(new Point(0, 0), minSize);
}
else
{
ret = new Rectangle(new Point(0, 0), maxSize);
ret.Width -= padding.Horizontal;
if (Application.RenderWithVisualStyles)
{
VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.Balloon.Normal);
Rectangle rect = renderer.GetTextExtent(dc, ret, text, TextFormatFlags.Left | TextFormatFlags.WordBreak | TextFormatFlags.VerticalCenter);
if (rect.Width + padding.Horizontal > maxSize.Width)
ret.Width = maxSize.Width;
else if (rect.Width + padding.Horizontal < minSize.Width)
ret.Width = minSize.Width;
else
ret.Width = rect.Width;
if (rect.Height > maxSize.Height)
ret.Height = maxSize.Height;
else
ret.Height = rect.Height;
}
else
{
throw new NotImplementedException();
}
}
return ret;
}
开发者ID:fiftin,项目名称:WinFormsPopupAlerts,代码行数:37,代码来源:ToolTipBalloonDrawingHelper.cs
示例18: DrawStringDisabled
public static void DrawStringDisabled(IDeviceContext dc, string s, Font font, Color color, Rectangle layoutRectangle, TextFormatFlags format)
{
if (dc == null)
{
throw new ArgumentNullException("dc");
}
layoutRectangle.Offset(1, 1);
Color foreColor = LightLight(color);
TextRenderer.DrawText(dc, s, font, layoutRectangle, foreColor, format);
layoutRectangle.Offset(-1, -1);
foreColor = Dark(color);
TextRenderer.DrawText(dc, s, font, layoutRectangle, foreColor, format);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:13,代码来源:ControlPaint.cs
示例19: CopyPixels
internal static void CopyPixels(IntPtr sourceHwnd, IDeviceContext targetDC, Point sourceLocation, Point destinationLocation, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
{
int width = blockRegionSize.Width;
int height = blockRegionSize.Height;
DeviceContext context = DeviceContext.FromHwnd(sourceHwnd);
HandleRef hDC = new HandleRef(null, targetDC.GetHdc());
HandleRef hSrcDC = new HandleRef(null, context.Hdc);
try
{
if (!System.Windows.Forms.SafeNativeMethods.BitBlt(hDC, destinationLocation.X, destinationLocation.Y, width, height, hSrcDC, sourceLocation.X, sourceLocation.Y, (int) copyPixelOperation))
{
throw new Win32Exception();
}
}
finally
{
targetDC.ReleaseHdc();
context.Dispose();
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:20,代码来源:ControlPaint.cs
示例20: TryGetCaptured
public unsafe bool TryGetCaptured(IDeviceContext context, IntRectangle clientRectangle, FrameType frameType, int colorDiffThreshold, int mostDetailedMip, out GpuRawFrame capturedFrame)
{
stopwatch.Restart();
var result = texturePool.Extract(clientRectangle.Width, clientRectangle.Height);
var resultTexture = result.Item;
d3dDevice.GetFrontBufferData(0, d3dSurface1);
var sdxRectangle = new Rectangle(clientRectangle.X, clientRectangle.Y, clientRectangle.X + clientRectangle.Width, clientRectangle.Y + clientRectangle.Height);
var lockedRectangle = d3dSurface1.LockRectangle(sdxRectangle, LockFlags.ReadOnly);
var mappedSubresource = context.Map(resultTexture, 0, MapType.WriteDiscard, MapFlags.None);
{
int commonRowPitch = Math.Min(mappedSubresource.RowPitch, lockedRectangle.Pitch);
Parallel.For(0, clientRectangle.Height, i =>
Memory.CopyBulk(
(byte*)mappedSubresource.Data + i * mappedSubresource.RowPitch,
(byte*)lockedRectangle.DataPointer + i * lockedRectangle.Pitch,
commonRowPitch));
}
context.Unmap(resultTexture, 0);
d3dSurface1.UnlockRectangle();
var frameInfo = new FrameInfo(frameType, (float)Stopwatch.GetTimestamp() / Stopwatch.Frequency,
mostDetailedMip, colorDiffThreshold, clientRectangle.Width, clientRectangle.Height,
Cursor.Position.X - clientRectangle.X, Cursor.Position.Y - clientRectangle.Y);
capturedFrame = new GpuRawFrame(frameInfo, result);
stopwatch.Stop();
statistics.OnCapture(stopwatch.Elapsed.TotalMilliseconds);
return true;
}
开发者ID:Zulkir,项目名称:RAVC,代码行数:33,代码来源:ScreenCaptor9.cs
注:本文中的System.Windows.Forms.IDeviceContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论