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


C# Graphics.ReleaseHdcInternal方法代码示例

本文整理汇总了C#中System.Drawing.Graphics.ReleaseHdcInternal方法的典型用法代码示例。如果您正苦于以下问题:C# Graphics.ReleaseHdcInternal方法的具体用法?C# Graphics.ReleaseHdcInternal怎么用?C# Graphics.ReleaseHdcInternal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Graphics的用法示例。


在下文中一共展示了Graphics.ReleaseHdcInternal方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AllocBuffer

 private BufferedGraphics AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
 {
     if (Interlocked.CompareExchange(ref this.busy, 1, 0) != 0)
     {
         return this.AllocBufferInTempManager(targetGraphics, targetDC, targetRectangle);
     }
     this.targetLoc = new Point(targetRectangle.X, targetRectangle.Y);
     try
     {
         Graphics graphics;
         if (targetGraphics != null)
         {
             IntPtr hdc = targetGraphics.GetHdc();
             try
             {
                 graphics = this.CreateBuffer(hdc, -this.targetLoc.X, -this.targetLoc.Y, targetRectangle.Width, targetRectangle.Height);
             }
             finally
             {
                 targetGraphics.ReleaseHdcInternal(hdc);
             }
         }
         else
         {
             graphics = this.CreateBuffer(targetDC, -this.targetLoc.X, -this.targetLoc.Y, targetRectangle.Width, targetRectangle.Height);
         }
         this.buffer = new BufferedGraphics(graphics, this, targetGraphics, targetDC, this.targetLoc, this.virtualSize);
     }
     catch
     {
         this.busy = 0;
         throw;
     }
     return this.buffer;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:35,代码来源:BufferedGraphicsContext.cs

示例2: Draw

 /// <include file='doc\ImageList.uex' path='docs/doc[@for="ImageList.Draw2"]/*' />
 /// <devdoc>
 ///     Draw the image indicated by the given index using the location, size
 ///     and raster op code specified.  The image is stretched or compressed as
 ///     necessary to fit the bounds provided.
 /// </devdoc>
 public void Draw(Graphics g, int x, int y, int width, int height, int index) {
     if (index < 0 || index >= Images.Count)
         throw new ArgumentOutOfRangeException("index", SR.GetString(SR.InvalidArgument, "index", index.ToString(CultureInfo.CurrentCulture)));
     IntPtr dc = g.GetHdc();
     try {
         SafeNativeMethods.ImageList_DrawEx(new HandleRef(this, Handle), index, new HandleRef(g, dc), x, y,
                                width, height, NativeMethods.CLR_NONE, NativeMethods.CLR_NONE, NativeMethods.ILD_TRANSPARENT);
     }
     finally {
         g.ReleaseHdcInternal(dc);
     }
 }
开发者ID:mind0n,项目名称:hive,代码行数:18,代码来源:ImageList.cs

示例3: PaintValue


//.........这里部分代码省略.........
     {
         backgroundBrush = SystemBrushes.Highlight;
         textColor = SystemColors.HighlightText;
     }
     Brush brush = backgroundBrush;
     g.FillRectangle(brush, clipRect);
     if (this.IsCustomPaint)
     {
         valuePaintIndent = gridEntryHost.GetValuePaintIndent();
         Rectangle a = new Rectangle(rect.X + 1, rect.Y + 1, gridEntryHost.GetValuePaintWidth(), gridEntryHost.GetGridEntryHeight() - 2);
         if (!Rectangle.Intersect(a, clipRect).IsEmpty)
         {
             System.Drawing.Design.UITypeEditor uITypeEditor = this.UITypeEditor;
             if (uITypeEditor != null)
             {
                 uITypeEditor.PaintValue(new PaintValueEventArgs(this, val, g, a));
             }
             a.Width--;
             a.Height--;
             g.DrawRectangle(SystemPens.WindowText, a);
         }
     }
     rect.X += valuePaintIndent + gridEntryHost.GetValueStringIndent();
     rect.Width -= valuePaintIndent + (2 * gridEntryHost.GetValueStringIndent());
     bool boldFont = ((paintFlags & PaintValueFlags.CheckShouldSerialize) != PaintValueFlags.None) && this.ShouldSerializePropertyValue();
     if ((lastValueString != null) && (lastValueString.Length > 0))
     {
         Font f = this.GetFont(boldFont);
         if (lastValueString.Length > 0x3e8)
         {
             lastValueString = lastValueString.Substring(0, 0x3e8);
         }
         int num2 = this.GetValueTextWidth(lastValueString, g, f);
         bool flag2 = false;
         if ((num2 >= rect.Width) || this.GetMultipleLines(lastValueString))
         {
             flag2 = true;
         }
         if (!Rectangle.Intersect(rect, clipRect).IsEmpty)
         {
             if ((paintFlags & PaintValueFlags.PaintInPlace) != PaintValueFlags.None)
             {
                 rect.Offset(1, 2);
             }
             else
             {
                 rect.Offset(1, 1);
             }
             Matrix transform = g.Transform;
             IntPtr hdc = g.GetHdc();
             IntNativeMethods.RECT lpRect = IntNativeMethods.RECT.FromXYWH((rect.X + ((int) transform.OffsetX)) + 2, (rect.Y + ((int) transform.OffsetY)) - 1, rect.Width - 4, rect.Height);
             IntPtr hfont = this.GetHfont(boldFont);
             int crColor = 0;
             int clr = 0;
             Color color2 = ((paintFlags & PaintValueFlags.DrawSelected) != PaintValueFlags.None) ? SystemColors.Highlight : this.GridEntryHost.BackColor;
             try
             {
                 crColor = System.Windows.Forms.SafeNativeMethods.SetTextColor(new HandleRef(g, hdc), System.Windows.Forms.SafeNativeMethods.RGBToCOLORREF(textColor.ToArgb()));
                 clr = System.Windows.Forms.SafeNativeMethods.SetBkColor(new HandleRef(g, hdc), System.Windows.Forms.SafeNativeMethods.RGBToCOLORREF(color2.ToArgb()));
                 hfont = System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(g, hdc), new HandleRef(null, hfont));
                 int nFormat = 0x2960;
                 if (gridEntryHost.DrawValuesRightToLeft)
                 {
                     nFormat |= 0x20002;
                 }
                 if (this.ShouldRenderPassword)
                 {
                     if (passwordReplaceChar == '\0')
                     {
                         if (Environment.OSVersion.Version.Major > 4)
                         {
                             passwordReplaceChar = '●';
                         }
                         else
                         {
                             passwordReplaceChar = '*';
                         }
                     }
                     lastValueString = new string(passwordReplaceChar, lastValueString.Length);
                 }
                 IntUnsafeNativeMethods.DrawText(new HandleRef(g, hdc), lastValueString, ref lpRect, nFormat);
             }
             finally
             {
                 System.Windows.Forms.SafeNativeMethods.SetTextColor(new HandleRef(g, hdc), crColor);
                 System.Windows.Forms.SafeNativeMethods.SetBkColor(new HandleRef(g, hdc), clr);
                 hfont = System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(g, hdc), new HandleRef(null, hfont));
                 g.ReleaseHdcInternal(hdc);
             }
             if (flag2)
             {
                 this.ValueToolTipLocation = new Point(rect.X + 2, rect.Y - 1);
             }
             else
             {
                 this.ValueToolTipLocation = InvalidPoint;
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:GridEntry.cs

示例4: AllocBuffer

        private BufferedGraphics AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle) {

            int oldBusy = Interlocked.CompareExchange(ref busy, BUFFER_BUSY_PAINTING, BUFFER_FREE);

            // In the case were we have contention on the buffer - i.e. two threads 
            // trying to use the buffer at the same time, we just create a temp 
            // buffermanager and have the buffer dispose of it when it is done.
            //
            if (oldBusy != BUFFER_FREE) {
                Debug.WriteLineIf(DoubleBuffering.TraceWarning, "Attempt to have two buffers for a buffer manager... allocating temp buffer manager");
                return AllocBufferInTempManager(targetGraphics, targetDC, targetRectangle);
            }

            #if DEBUG
            if (DoubleBuffering.TraceVerbose) {
                stackAtBusy = new StackTrace().ToString();
            }
            #endif

            Graphics surface;
            this.targetLoc = new Point(targetRectangle.X, targetRectangle.Y);

            try {
                if (targetGraphics != null) {
                    IntPtr destDc = targetGraphics.GetHdc();
                    try {
                        surface = CreateBuffer(destDc, -targetLoc.X, -targetLoc.Y, targetRectangle.Width, targetRectangle.Height);
                    }
                    finally {
                        targetGraphics.ReleaseHdcInternal(destDc);
                    }
                }
                else {
                    surface = CreateBuffer(targetDC, -targetLoc.X, -targetLoc.Y, targetRectangle.Width, targetRectangle.Height);
                }

                this.buffer = new BufferedGraphics(surface, this, targetGraphics, targetDC, targetLoc, virtualSize);
            }
            catch {
                this.busy = BUFFER_FREE; // free the buffer so it can be disposed.
                throw;
            }
            return this.buffer;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:44,代码来源:BufferedGraphicsContext.cs

示例5: DrawImageCore


//.........这里部分代码省略.........
        /// </devdoc>
        // This method is way more powerful than what we expose, but I'll leave it in place.
        private void DrawImageCore(Graphics graphics, Rectangle imageRect, Rectangle targetRect, bool stretch) {
            // Support GDI+ Translate method
            targetRect.X += (int) graphics.Transform.OffsetX;
            targetRect.Y += (int) graphics.Transform.OffsetY;

            int rop = 0xcc0020; // RasterOp.SOURCE.GetRop();
            IntPtr dc = graphics.GetHdc();

            try { // want finally clause to release dc
                int imageX = 0;
                int imageY = 0;
                int imageWidth;
                int imageHeight;
                int targetX = 0;
                int targetY = 0;
                int targetWidth = 0;
                int targetHeight = 0;

                Size cursorSize = Size;

                // compute the dimensions of the icon, if needed
                //
                if (!imageRect.IsEmpty) {
                    imageX = imageRect.X;
                    imageY = imageRect.Y;
                    imageWidth = imageRect.Width;
                    imageHeight = imageRect.Height;
                }
                else {
                    imageWidth = cursorSize.Width;
                    imageHeight = cursorSize.Height;
                }

                if (!targetRect.IsEmpty) {
                    targetX = targetRect.X;
                    targetY = targetRect.Y;
                    targetWidth = targetRect.Width;
                    targetHeight = targetRect.Height;
                }
                else {
                    targetWidth = cursorSize.Width;
                    targetHeight = cursorSize.Height;
                }

                int drawWidth, drawHeight;
                int clipWidth, clipHeight;

                if (stretch) {
                    // Short circuit the simple case of blasting an icon to the
                    // screen
                    //
                    if (targetWidth == imageWidth && targetHeight == imageHeight
                        && imageX == 0 && imageY == 0 && rop == NativeMethods.SRCCOPY
                        && imageWidth == cursorSize.Width && imageHeight == cursorSize.Height) {
                        SafeNativeMethods.DrawIcon(new HandleRef(graphics, dc), targetX, targetY, new HandleRef(this, handle));
                        return;
                    }

                    drawWidth = cursorSize.Width * targetWidth / imageWidth;
                    drawHeight = cursorSize.Height * targetHeight / imageHeight;
                    clipWidth = targetWidth;
                    clipHeight = targetHeight;
                }
                else {
                    // Short circuit the simple case of blasting an icon to the
                    // screen
                    //
                    if (imageX == 0 && imageY == 0 && rop == NativeMethods.SRCCOPY
                        && cursorSize.Width <= targetWidth && cursorSize.Height <= targetHeight
                        && cursorSize.Width == imageWidth && cursorSize.Height == imageHeight) {
                        SafeNativeMethods.DrawIcon(new HandleRef(graphics, dc), targetX, targetY, new HandleRef(this, handle));
                        return;
                    }

                    drawWidth = cursorSize.Width;
                    drawHeight = cursorSize.Height;
                    clipWidth = targetWidth < imageWidth ? targetWidth : imageWidth;
                    clipHeight = targetHeight < imageHeight ? targetHeight : imageHeight;
                }

                if (rop == NativeMethods.SRCCOPY) {
                    // The ROP is SRCCOPY, so we can be simple here and take
                    // advantage of clipping regions.  Drawing the cursor
                    // is merely a matter of offsetting and clipping.
                    //
                    SafeNativeMethods.IntersectClipRect(new HandleRef(this, Handle), targetX, targetY, targetX+clipWidth, targetY+clipHeight);
                    SafeNativeMethods.DrawIconEx(new HandleRef(graphics, dc), targetX - imageX, targetY - imageY,
                                       new HandleRef(this, handle), drawWidth, drawHeight, 0, NativeMethods.NullHandleRef, NativeMethods.DI_NORMAL);
                    // Let GDI+ restore clipping
                    return;
                }

                Debug.Fail("Cursor.Draw does not support raster ops.  How did you even pass one in?");
            }
            finally {
                graphics.ReleaseHdcInternal(dc);
            }
        }
开发者ID:salim18,项目名称:DemoProject2,代码行数:101,代码来源:Cursor.cs

示例6: Render

        public void Render(Graphics target) {
            if (target != null) {
                IntPtr targetDC = target.GetHdc();

                try {
                    RenderInternal(new HandleRef(target, targetDC), this);
                }
                finally {
                    target.ReleaseHdcInternal(targetDC);
                }
            }
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:12,代码来源:BufferedGraphics.cs

示例7: DrawImageCore

 private void DrawImageCore(Graphics graphics, Rectangle imageRect, Rectangle targetRect, bool stretch)
 {
     targetRect.X += (int) graphics.Transform.OffsetX;
     targetRect.Y += (int) graphics.Transform.OffsetY;
     int num = 0xcc0020;
     IntPtr hdc = graphics.GetHdc();
     try
     {
         int width;
         int height;
         int num10;
         int num11;
         int num12;
         int num13;
         int num2 = 0;
         int num3 = 0;
         int x = 0;
         int y = 0;
         int num8 = 0;
         int num9 = 0;
         System.Drawing.Size size = this.Size;
         if (!imageRect.IsEmpty)
         {
             num2 = imageRect.X;
             num3 = imageRect.Y;
             width = imageRect.Width;
             height = imageRect.Height;
         }
         else
         {
             width = size.Width;
             height = size.Height;
         }
         if (!targetRect.IsEmpty)
         {
             x = targetRect.X;
             y = targetRect.Y;
             num8 = targetRect.Width;
             num9 = targetRect.Height;
         }
         else
         {
             num8 = size.Width;
             num9 = size.Height;
         }
         if (stretch)
         {
             if ((((num8 == width) && (num9 == height)) && ((num2 == 0) && (num3 == 0))) && (((num == 0xcc0020) && (width == size.Width)) && (height == size.Height)))
             {
                 System.Windows.Forms.SafeNativeMethods.DrawIcon(new HandleRef(graphics, hdc), x, y, new HandleRef(this, this.handle));
                 return;
             }
             num10 = (size.Width * num8) / width;
             num11 = (size.Height * num9) / height;
             num12 = num8;
             num13 = num9;
         }
         else
         {
             if ((((num2 == 0) && (num3 == 0)) && ((num == 0xcc0020) && (size.Width <= num8))) && (((size.Height <= num9) && (size.Width == width)) && (size.Height == height)))
             {
                 System.Windows.Forms.SafeNativeMethods.DrawIcon(new HandleRef(graphics, hdc), x, y, new HandleRef(this, this.handle));
                 return;
             }
             num10 = size.Width;
             num11 = size.Height;
             num12 = (num8 < width) ? num8 : width;
             num13 = (num9 < height) ? num9 : height;
         }
         if (num == 0xcc0020)
         {
             System.Windows.Forms.SafeNativeMethods.IntersectClipRect(new HandleRef(this, this.Handle), x, y, x + num12, y + num13);
             System.Windows.Forms.SafeNativeMethods.DrawIconEx(new HandleRef(graphics, hdc), x - num2, y - num3, new HandleRef(this, this.handle), num10, num11, 0, System.Windows.Forms.NativeMethods.NullHandleRef, 3);
         }
     }
     finally
     {
         graphics.ReleaseHdcInternal(hdc);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:80,代码来源:Cursor.cs

示例8: DrawNoResizeHandle

 public static void DrawNoResizeHandle(Graphics graphics, Rectangle bounds, bool isPrimary, Glyph glyph)
 {
     IntPtr hdc = graphics.GetHdc();
     try
     {
         IntPtr handle = System.Design.SafeNativeMethods.SelectObject(new HandleRef(glyph, hdc), new HandleRef(glyph, isPrimary ? grabHandleFillBrushPrimary : grabHandleFillBrush));
         IntPtr ptr3 = System.Design.SafeNativeMethods.SelectObject(new HandleRef(glyph, hdc), new HandleRef(glyph, grabHandlePenPrimary));
         System.Design.SafeNativeMethods.Rectangle(new HandleRef(glyph, hdc), bounds.Left, bounds.Top, bounds.Right, bounds.Bottom);
         System.Design.SafeNativeMethods.SelectObject(new HandleRef(glyph, hdc), new HandleRef(glyph, handle));
         System.Design.SafeNativeMethods.SelectObject(new HandleRef(glyph, hdc), new HandleRef(glyph, ptr3));
     }
     finally
     {
         graphics.ReleaseHdcInternal(hdc);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:16,代码来源:DesignerUtils.cs

示例9: DrawLockedHandle

 public static void DrawLockedHandle(Graphics graphics, Rectangle bounds, bool isPrimary, Glyph glyph)
 {
     IntPtr hdc = graphics.GetHdc();
     try
     {
         IntPtr handle = System.Design.SafeNativeMethods.SelectObject(new HandleRef(glyph, hdc), new HandleRef(glyph, grabHandlePenPrimary));
         IntPtr ptr3 = System.Design.SafeNativeMethods.SelectObject(new HandleRef(glyph, hdc), new HandleRef(glyph, grabHandleFillBrushPrimary));
         System.Design.SafeNativeMethods.RoundRect(new HandleRef(glyph, hdc), bounds.Left + LOCKHANDLEUPPER_OFFSET, bounds.Top, (bounds.Left + LOCKHANDLEUPPER_OFFSET) + LOCKHANDLESIZE_UPPER, bounds.Top + LOCKHANDLESIZE_UPPER, 2, 2);
         System.Design.SafeNativeMethods.SelectObject(new HandleRef(glyph, hdc), new HandleRef(glyph, isPrimary ? grabHandleFillBrushPrimary : grabHandleFillBrush));
         System.Design.SafeNativeMethods.Rectangle(new HandleRef(glyph, hdc), bounds.Left, bounds.Top + LOCKHANDLELOWER_OFFSET, bounds.Right, bounds.Bottom);
         System.Design.SafeNativeMethods.SelectObject(new HandleRef(glyph, hdc), new HandleRef(glyph, ptr3));
         System.Design.SafeNativeMethods.SelectObject(new HandleRef(glyph, hdc), new HandleRef(glyph, handle));
     }
     finally
     {
         graphics.ReleaseHdcInternal(hdc);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:18,代码来源:DesignerUtils.cs

示例10: Draw

 public void Draw(Graphics g, int x, int y, int width, int height, int index)
 {
     if ((index < 0) || (index >= this.Images.Count))
     {
         throw new ArgumentOutOfRangeException("index", System.Windows.Forms.SR.GetString("InvalidArgument", new object[] { "index", index.ToString(CultureInfo.CurrentCulture) }));
     }
     IntPtr hdc = g.GetHdc();
     try
     {
         System.Windows.Forms.SafeNativeMethods.ImageList_DrawEx(new HandleRef(this, this.Handle), index, new HandleRef(g, hdc), x, y, width, height, -1, -1, 1);
     }
     finally
     {
         g.ReleaseHdcInternal(hdc);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:16,代码来源:ImageList.cs


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