public static float GetWindowsScaling() { Graphics currentGraphics = Graphics.FromHwnd(IntPtr.Zero); double dpixRatio = currentGraphics.DpiX / 96; print("------------------" + currentGraphics.DpiX / 96 + " " + currentGraphics.DpiY / 96); return(currentGraphics.DpiX / 96); }
/// <summary> /// Function to create the double buffer surface resources. /// </summary> /// <param name="displayControl">The control that will be used as the display.</param> private void CreateDoubleBufferSurface(Control displayControl) { _graphics = DrawingGraphics.FromHwnd(displayControl.Handle); _mouseImage = new Bitmap(displayControl.ClientSize.Width, displayControl.ClientSize.Height, PixelFormat.Format32bppArgb); _imageGraphics = DrawingGraphics.FromImage(_mouseImage); _graphicsContext = BufferedGraphicsManager.Current; _buffer = _graphicsContext.Allocate(_imageGraphics, new Rectangle(0, 0, _mouseImage.Width, _mouseImage.Height)); }
public Radar(Form1 form) { this.settings = form.radarSettings.settings; this.settings.TransparencyKey = form.TransparencyKey; this.createBuffer(); this.gForm = Graphics.FromHwnd(form.Handle); Timer timer = new Timer(); timer.Interval = 100; timer.Tick += timer_Tick; timer.Start(); }
/// <summary> /// Function to allocate resources for our graphics. /// </summary> /// <param name="clearDrawing"><b>true</b> to clear the drawing, <b>false</b> to leave alone.</param> private void GetResources(bool clearDrawing) { CleanUp(clearDrawing); _surfaceBuffer = new Bitmap(_control.ClientSize.Width, _control.ClientSize.Height, PixelFormat.Format32bppArgb); _controlGraphics = DrawingGraphics.FromHwnd(_control.Handle); _surfaceGraphics = DrawingGraphics.FromImage(_surfaceBuffer); _context = BufferedGraphicsManager.Current; _buffer = _context.Allocate(_surfaceGraphics, _control.ClientRectangle); if (!clearDrawing) { return; } _drawing = new Bitmap(_control.ClientSize.Width, _control.ClientSize.Height, PixelFormat.Format32bppArgb); _imageGraphics = DrawingGraphics.FromImage(_drawing); }