当前位置: 首页>>代码示例>>C#>>正文


C# Forms.IDeviceContext类代码示例

本文整理汇总了C#中System.Windows.Forms.IDeviceContext的典型用法代码示例。如果您正苦于以下问题:C# IDeviceContext类的具体用法?C# IDeviceContext怎么用?C# IDeviceContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IDeviceContext类属于System.Windows.Forms命名空间,在下文中一共展示了IDeviceContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的System.Windows.Forms.IDeviceContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。