コード例 #1
0
 public CairoAdapter(System.Drawing.Graphics graphic)
 {
     Surface surface = new Win32Surface(graphic.GetHdc());
     this.context = new Context(surface);
     context.LineWidth = 2;
     context.Color = new Color(1, 0, 0);
 }
コード例 #2
0
 /// <summary>
 /// Creates a new Graphics object from the device context handle associated with the Graphics
 /// parameter
 /// </summary>
 /// <param name="oldGraphics">Graphics instance to obtain the parameter from</param>
 /// <returns>A new GDI+ drawing surface</returns>
 public static System.Drawing.Graphics CreateGraphics(System.Drawing.Graphics oldGraphics)
 {
     System.Drawing.Graphics createdGraphics;
     System.IntPtr hdc = oldGraphics.GetHdc();
     createdGraphics = System.Drawing.Graphics.FromHdc(hdc);
     oldGraphics.ReleaseHdc(hdc);
     return createdGraphics;
 }
コード例 #3
0
ファイル: FontHelper.cs プロジェクト: Boerlam001/MonoGame
		public static ABC GetCharWidthABC(char ch, Font font, System.Drawing.Graphics gr)
		{
			ABC[] _temp = new ABC[1];
			IntPtr hDC = gr.GetHdc();
			Font ft = (Font)font.Clone();
			IntPtr hFt = ft.ToHfont();
			SelectObject(hDC, hFt);
			GetCharABCWidthsW(hDC, ch, ch, _temp);
			DeleteObject(hFt);
			gr.ReleaseHdc();

			return _temp[0];
		}
 public void Render(System.Drawing.Graphics target)
 {
     if (target != null)
     {
         IntPtr hdc = target.GetHdc();
         try
         {
             this.RenderInternal(new HandleRef(target, hdc), this);
         }
         finally
         {
             target.ReleaseHdcInternal(hdc);
         }
     }
 }
コード例 #5
0
ファイル: ThemeRenderer2.cs プロジェクト: ChrisMoreton/Test3
		/// <summary>
		/// Draws the part defined by the current renderer onto a specified <see cref="Graphics"/> surface, within the
		/// given clipping bounds.
		/// </summary>
		/// <param name="graphics">The <see cref="Graphics"/> surface on which the part is drawn.</param>
		/// <param name="state">A constant which determines the current state of the part.</param>
		/// <param name="bounds">The bounding rectangle in which the part is drawn.</param>
		/// <param name="clipBounds">The bounding rectangle in which the part is clipped.</param>
		public void Draw(System.Drawing.Graphics graphics, int state, Rectangle bounds, Rectangle clipBounds)
		{
			if (Supported)
			{
				IntPtr hdc = IntPtr.Zero;
				try
				{
					DrawCore(hdc = graphics.GetHdc(), state, bounds, clipBounds);
				}
				finally
				{
					if (hdc != IntPtr.Zero)
						graphics.ReleaseHdc(hdc);
				}
			}
		}
コード例 #6
0
ファイル: GridEntry.cs プロジェクト: JianwenSun/cc
        /// <include file='doc\GridEntry.uex' path='docs/doc[@for="GridEntry.PaintValue"]/*' />
        /// <devdoc>
        /// Paints the value portion of this GridEntry into the given Graphics object.  This
        /// is called by the GridEntry host (the PropertyGridView) when this GridEntry is
        /// to be painted.
        /// </devdoc>
        public virtual void PaintValue(object val, System.Drawing.Graphics g, Rectangle rect, Rectangle clipRect, PaintValueFlags paintFlags) { 
            PropertyGridView gridHost = this.GridEntryHost;
            Debug.Assert(gridHost != null, "No propEntryHost");
            int cPaint = 0;

            Color textColor = gridHost.GetTextColor();
            if (this.ShouldRenderReadOnly) {
                textColor = GridEntryHost.GrayTextColor;
            }
            
            string strValue;
            
            if ((paintFlags & PaintValueFlags.FetchValue) != PaintValueFlags.None) {
               if (cacheItems != null && cacheItems.useValueString) {
                  strValue = cacheItems.lastValueString;
                  val = cacheItems.lastValue;
               }
               else {
                  val = this.PropertyValue;
                  strValue = GetPropertyTextValue(val);
                  if (cacheItems == null) {
                     cacheItems = new CacheItems();
                  }
                  cacheItems.lastValueString = strValue;
                  cacheItems.useValueString = true;
                  cacheItems.lastValueTextWidth = -1;
                  cacheItems.lastValueFont = null;
                  cacheItems.lastValue = val;
               }
            }
            else {
               strValue = GetPropertyTextValue(val);                  
            }

            // paint out the main rect using the appropriate brush
            Brush bkBrush = this.GetBackgroundBrush(g);
            Debug.Assert(bkBrush != null, "We didn't find a good background brush for PaintValue");

            if ((paintFlags & PaintValueFlags.DrawSelected) != PaintValueFlags.None) {
                bkBrush = gridHost.GetSelectedItemWithFocusBackBrush(g);
                textColor = gridHost.GetSelectedItemWithFocusForeColor();
            }

            Brush blank = bkBrush;
#if PBRS_PAINT_DEBUG
            blank = Brushes.Yellow;
#endif
            //g.FillRectangle(blank, rect.X-1, rect.Y, rect.Width+1, rect.Height);
            g.FillRectangle(blank, clipRect);
            
            if (IsCustomPaint) {
                cPaint = gridHost.GetValuePaintIndent();
                Rectangle rectPaint = new Rectangle(rect.X + 1, rect.Y + 1, gridHost.GetValuePaintWidth(), gridHost.GetGridEntryHeight() - 2);
                
                if (!Rectangle.Intersect(rectPaint, clipRect).IsEmpty) {
                   UITypeEditor uie = UITypeEditor;
                   if (uie != null) {
                       uie.PaintValue(new PaintValueEventArgs(this, val, g, rectPaint));
                   }
   
                   // paint a border around the area
                   rectPaint.Width --;
                   rectPaint.Height--;
                   g.DrawRectangle(SystemPens.WindowText, rectPaint);
                }
            }

            rect.X += cPaint + gridHost.GetValueStringIndent();
            rect.Width -= cPaint + 2 * gridHost.GetValueStringIndent();

            // bold the property if we need to persist it (e.g. it's not the default value)
            bool valueModified = ((paintFlags & PaintValueFlags.CheckShouldSerialize) != PaintValueFlags.None) && ShouldSerializePropertyValue();
            
            // If we have text to paint, paint it
            if (strValue != null && strValue.Length > 0) {
                
                Font f = GetFont(valueModified);

                if (strValue.Length > maximumLengthOfPropertyString)
                {
                    strValue = strValue.Substring(0, maximumLengthOfPropertyString);
                }
                int textWidth = GetValueTextWidth(strValue, g, f);
                bool doToolTip = false;
                
                //subhag (66503) To check if text contains multiple lines
                //
                if (textWidth >= rect.Width ||  GetMultipleLines(strValue)) 
                     doToolTip = true;
                               
                if (Rectangle.Intersect(rect, clipRect).IsEmpty) {
                     return;
                }
                
                // Do actual drawing
                
                //strValue = ReplaceCRLF(strValue);
                
                
                 // AS/URT  55015
                // bump the text down 2 pixels and over 1 pixel.
                if ((paintFlags & PaintValueFlags.PaintInPlace) != PaintValueFlags.None) { 
                    rect.Offset(1, 2);
                }
                else {
                    // only go down one pixel when we're painting in the listbox
                    rect.Offset(1, 1);
                } 

                Matrix m = g.Transform;
                IntPtr hdc = g.GetHdc();
                IntNativeMethods.RECT lpRect = IntNativeMethods.RECT.FromXYWH(rect.X + (int)m.OffsetX + 2, rect.Y + (int)m.OffsetY - 1, rect.Width - 4, rect.Height);
                IntPtr hfont = GetHfont(valueModified);
                
                int oldTextColor = 0;
                int oldBkColor = 0;

                Color bkColor = ((paintFlags & PaintValueFlags.DrawSelected) != PaintValueFlags.None) ? GridEntryHost.GetSelectedItemWithFocusBackColor() : GridEntryHost.BackColor;
                
                try {
                    oldTextColor = SafeNativeMethods.SetTextColor(new HandleRef(g, hdc), SafeNativeMethods.RGBToCOLORREF(textColor.ToArgb()));
                    oldBkColor = SafeNativeMethods.SetBkColor(new HandleRef(g, hdc), SafeNativeMethods.RGBToCOLORREF(bkColor.ToArgb()));
                    hfont = SafeNativeMethods.SelectObject(new HandleRef(g, hdc), new HandleRef(null, hfont));
                    int format = IntNativeMethods.DT_EDITCONTROL | IntNativeMethods.DT_EXPANDTABS | IntNativeMethods.DT_NOCLIP | IntNativeMethods.DT_SINGLELINE | IntNativeMethods.DT_NOPREFIX;
                    if (gridHost.DrawValuesRightToLeft) {
                        format |= IntNativeMethods.DT_RIGHT | IntNativeMethods.DT_RTLREADING;
                    }

                    // For password mode, Replace the string value either with * or a bullet, depending on the OS platform
                    if (ShouldRenderPassword) {

                        if (passwordReplaceChar == (char)0) {
                            if (Environment.OSVersion.Version.Major > 4) {
                                passwordReplaceChar = (char)0x25CF; // Bullet is 2022, but edit box uses round circle 25CF
                            }
                            else {
                                passwordReplaceChar = '*';
                            }
                        }

                        strValue = new string(passwordReplaceChar, strValue.Length);
                    }

                    IntUnsafeNativeMethods.DrawText(new HandleRef(g, hdc), strValue, ref lpRect, format);
                }
                finally {
                    SafeNativeMethods.SetTextColor(new HandleRef(g, hdc), oldTextColor);
                    SafeNativeMethods.SetBkColor(new HandleRef(g, hdc), oldBkColor);
                    hfont = SafeNativeMethods.SelectObject(new HandleRef(g, hdc), new HandleRef(null, hfont));
                    g.ReleaseHdcInternal(hdc);
                }
                
                
                #if PBRS_PAINT_DEBUG
                    rect.Width --;
                    rect.Height--;
                    g.DrawRectangle(new Pen(Color.Purple), rect);
               #endif
               
                if (doToolTip) {
                    this.ValueToolTipLocation = new Point(rect.X+2, rect.Y-1);
                }
                else {
                     this.ValueToolTipLocation = InvalidPoint;
                }
            }

            return;
        }
コード例 #7
0
 public void setGraphics(System.Drawing.Graphics g)
 {
     Surface surface = new Win32Surface(g.GetHdc());
     this.context = new Context(surface);
 }
コード例 #8
0
ファイル: ColorComboBox.cs プロジェクト: abhishek-kumar/AIGA
        private void DrawBorder(System.Drawing.Graphics g)
        {
            IntPtr hTheme = UxTheme.OpenThemeData(this.Handle, "EDIT");

            // Makes sure Windows XP is running and
            //  a .manifest file exists for the EXE.
            if (Environment.OSVersion.Version.Major >= 5
                && Environment.OSVersion.Version.Minor > 0
                && System.IO.File.Exists(Application.ExecutablePath + ".manifest")
                && (hTheme != IntPtr.Zero))
            {
                //Get DC
                IntPtr hDC    = g.GetHdc();

                int state = (int) UxTheme.ETS_NORMAL;
                switch (this.m_state)
                {
                    case State.Disabled :
                        state = (int) UxTheme.ETS_DISABLED;
                        break;
                    default:
                        break;
                }

                try
                {
                    RECT r = new RECT(this.ClientRectangle.Left, this.ClientRectangle.Right, this.ClientRectangle.Top, this.ClientRectangle.Bottom);

                    //Render button
                    IntPtr hr = UxTheme.DrawThemeBackground( hTheme, hDC, UxTheme.EP_EDITTEXT, state, r,  null);
                }
                finally
                {
                    //Release DC
                    g.ReleaseHdc(hDC);
                    UxTheme.CloseThemeData(hTheme);
                }
            }
            else
            {
                using (Graphics y = this.CreateGraphics())
                {
                    ControlPaint.DrawBorder(y, ClientRectangle, SystemColors.Control, ButtonBorderStyle.Inset);
                }
            }
        }
コード例 #9
0
ファイル: TrueTypeImporter.cs プロジェクト: numo16/SharpDX
        // Queries APC spacing for the specified character.
        static float? GetCharacterWidth(char character, Font font, System.Drawing.Graphics graphics)
        {
            // Look up the native device context and font handles.
            IntPtr hdc = graphics.GetHdc();

            try
            {
                IntPtr hFont = font.ToHfont();

                try
                {
                    // Select our font into the DC.
                    IntPtr oldFont = NativeMethods.SelectObject(hdc, hFont);

                    try
                    {
                        // Query the character spacing.
                        var result = new NativeMethods.ABCFloat[1];

                        if (NativeMethods.GetCharABCWidthsFloatW(hdc, character, character, result))
                        {
                            return result[0].A + 
                                   result[0].B + 
                                   result[0].C;
                        }
                        else
                        {
                            return null;
                        }
                    }
                    finally
                    {
                        NativeMethods.SelectObject(hdc, oldFont);
                    }
                }
                finally
                {
                    NativeMethods.DeleteObject(hFont);
                }
            }
            finally
            {
                graphics.ReleaseHdc(hdc);
            }
        }
コード例 #10
0
 public static void DrawText(System.Drawing.Graphics graphics, string text, System.Drawing.Font font, System.Drawing.Color foreColor, System.Drawing.Color backColor, System.Drawing.Rectangle bounds, Skybound.Windows.Forms.TextFormatFlags formatFlags)
 {
     if ((text == null) || (text.Length == 0) || (graphics == null) || (font == null) || bounds.Size == System.Drawing.Size.Empty || foreColor.Equals(System.Drawing.Color.Empty) || foreColor.Equals(System.Drawing.Color.Transparent))
         return;
     System.IntPtr intPtr1 = graphics.GetHdc();
     try
     {
         System.IntPtr intPtr2 = Skybound.Windows.Forms.TextRenderer.GetCachedFont(font);
         System.IntPtr intPtr3 = Skybound.Windows.Forms.TextRenderer.SelectObject(intPtr1, intPtr2);
         if (backColor.Equals(System.Drawing.Color.Empty) || backColor.Equals(System.Drawing.Color.Transparent))
         {
             Skybound.Windows.Forms.TextRenderer.SetBkMode(intPtr1, 1);
         }
         else
         {
             Skybound.Windows.Forms.TextRenderer.SetBkMode(intPtr1, 2);
             Skybound.Windows.Forms.TextRenderer.SetBkColor(intPtr1, System.Drawing.ColorTranslator.ToWin32(backColor));
         }
         int i = Skybound.Windows.Forms.TextRenderer.GetTextColor(intPtr1);
         Skybound.Windows.Forms.TextRenderer.SetTextColor(intPtr1, System.Drawing.ColorTranslator.ToWin32(foreColor));
         Skybound.Windows.Forms.TextRenderer.RECT rect = new Skybound.Windows.Forms.TextRenderer.RECT(bounds);
         Skybound.Windows.Forms.TextRenderer.DrawText(intPtr1, text, text.Length, ref rect, (int)formatFlags);
         Skybound.Windows.Forms.TextRenderer.SetTextColor(intPtr1, i);
         Skybound.Windows.Forms.TextRenderer.SelectObject(intPtr1, intPtr3);
     }
     finally
     {
         graphics.ReleaseHdc(intPtr1);
     }
 }
コード例 #11
0
ファイル: GDIPath.cs プロジェクト: shaovoon/outline-text
        public static bool GetStringPath(
            System.Drawing.Graphics pGraphics,
            System.Drawing.Drawing2D.GraphicsPath ppPath,
            string pszText,
            LOGFONT plf,
            System.Drawing.Rectangle rtDraw)
        {
            IntPtr hDC = pGraphics.GetHdc();

            int nPrevMode = SetBkMode(hDC, TRANSPARENT);

            // create and select it
            IntPtr hFont = CreateFontIndirect(plf);
            if (null == hFont)
            return false;
            IntPtr hOldFont = (IntPtr)SelectObject(hDC, hFont);

            RECT rect = new RECT(rtDraw);

            // use a path to record how the text was drawn
               	const uint DT_CENTER = 0x00000001;

            BeginPath(hDC);
            DrawText(hDC, pszText, pszText.Length, ref rect, DT_CENTER);
            EndPath(hDC);

            // Find out how many points are in the path. Note that
            // for long strings or complex fonts, this number might be
            // gigantic!
            int nNumPts = GetPath(hDC, null, null, 0);
            if (nNumPts == 0)
            return false;

            // Allocate memory to hold points and stroke types from
            // the path.
            POINT[] lpPoints = new POINT[nNumPts];
            byte[] lpTypes = new byte[nNumPts];

            // Now that we have the memory, really get the path data.
            nNumPts = GetPath(hDC, lpPoints, lpTypes, nNumPts);

            // If it worked, draw the lines. Win95 and Win98 don't support
            // the PolyDraw API, so we use our own member function to do
            // similar work. If you're targeting only Windows NT, you can
            // use the PolyDraw() API and avoid the COutlineView::PolyDraw()
            // member function.

            if (nNumPts != -1)
            PolyDraw(ppPath, lpPoints, lpTypes, nNumPts);

            // Put back the old font
            SelectObject(hDC, hOldFont);
            DeleteObject(hFont);
            SetBkMode(hDC, nPrevMode);

            pGraphics.ReleaseHdc(hDC);

            return true;
        }