gdi

How do I capture a WinForm window to a bitmap without the caret

南笙酒味 提交于 2019-12-24 01:11:13
问题 I've got window on a WinForm that I want to get the bitmap representation of. For this, I use the following code (where codeEditor is the control I want a bitmap representation of): public Bitmap GetBitmap( ) { IntPtr srcDC = NativeMethods.GetDC( codeEditor.Handle ) ; var bitmap = new Bitmap( codeEditor.Width, codeEditor.Height ) ; Graphics graphics = Graphics.FromImage( bitmap ) ; var deviceContext = graphics.GetHdc( ) ; bool blitted = NativeMethods.BitBlt( deviceContext, 0, 0, bitmap.Width,

Detect mouse location within ContainerControl C#.NET [duplicate]

做~自己de王妃 提交于 2019-12-23 18:27:35
问题 This question already has answers here : Pass-through mouse events to parent control (3 answers) Closed 6 years ago . I am testing the following code: protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); Rectangle leftRect = new Rectangle(0, 0, 32, this.Height); if (leftRect.Contains(e.Location)) { MessageBox.Show("Hello World"); } } The idea is that when the mouse enters a region 32 pixels wide, to the left of the container control, a message appears (OK, in R/L it

Win32 DrawText line height

末鹿安然 提交于 2019-12-23 15:21:39
问题 I'm calling the Win32 DrawText function to output some text into a device context. The text is long and wraps nicely onto a second line. The problem is I need to decrease the space between lines a bit (I guess decrease the line height?). Any ideas on how to do this? I would just call DrawText twice (one for each line) but then I have to do my own word wrap. Is there any other way? Thanks 回答1: One possibility is to put the text into a disabled Rich Edit Control. I think that gives you a lot of

Using AlphaBlend to draw slightly transparent rectangle fails

微笑、不失礼 提交于 2019-12-23 12:18:41
问题 I am attempting to draw a slightly transparent blue rectangle in Native Win32 C++. I am using the function AlphaBlend() but its not drawing anything onto the window, nothing happens. My Problem: When I run my function to draw a slightly transparent rectangle, it doesn't get shown on my window. I have a feeling I am doing this wrong, maybe I should be using a HBITMAP? Can you tell me what I need to do to get my function to draw a slightly transparent rectangle on the window? Also I'm aware of

Determine number of GDI handles and USER objects

夙愿已清 提交于 2019-12-23 10:14:20
问题 We developed a small test suite for our Windows Forms UI rendering engine which allows to measure performance and detect memory leaks while running test cases in an automated manner. Now we would like to check for handle leaks as well. On the desktop platform we can use this code: [DllImport("User32")] private extern static int GetGuiResources(IntPtr hProcess, int uiFlags); using (var process = Process.GetCurrentProcess()) { var gdiHandles = GetGuiResources(process.Handle, 0); var userHandles

What would be a higher quality alternative to StretchBlt for drawing an HBITMAP?

元气小坏坏 提交于 2019-12-23 09:05:04
问题 I don't want to use GDI+'s DrawImage because of speed issues. What other ways are there to draw an image resized with decent quality - at least linear or cubic interpolation? 回答1: You can use SetStretchBltMode with the HALFTONE setting, but you'll probably run into the same speed issues that you faced with GDI+ -- smoothing always comes at a cost. 来源: https://stackoverflow.com/questions/4572886/what-would-be-a-higher-quality-alternative-to-stretchblt-for-drawing-an-hbitmap

Guidelines for Using Brushes and Pens

孤者浪人 提交于 2019-12-23 08:58:51
问题 How expensive is it to create gdi brushes and pens? Should I create them on an add needed basis and wrap them in a using so they are disposed quickly, or should I create a static class similar to System.Drawing.Brushes class? 回答1: IMO, they're efficient enough that you should usually not create long-lived instances that are used over several method calls, but inefficient enough that you should create each one only once within a particular method, instead of creating a new one each time you

How to “Clear” a WinAPI Transparent Window

谁都会走 提交于 2019-12-23 08:57:06
问题 I have created a Transparent Checkbox in Win32 C++. I have made it because as far as I know you cant have a transparent checkbox in native win32 and I need to use this checkbox in a NSIS installer. My Problem: When repainting, I don't know how to erase my transparent background so I can draw on a "clear canvas". This is important when the user changes the text inside the checkbox and I need to repaint it. I guess I have run into the problem everyone must get with transparent windows. What is

LinearGradientBrush does not render correctly

送分小仙女□ 提交于 2019-12-23 08:17:07
问题 Consider the following code from a standard System.Windows.Forms.Form protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Rectangle test = new Rectangle(50, 50, 100, 100); using (LinearGradientBrush brush = new LinearGradientBrush(test, Color.Red, Color.Blue, 0f)) { e.Graphics.DrawRectangle(new Pen(brush, 8), test); } } It produces this result: Why are the red and blue lines showing up in the incorrect order, and how can this be fixed? 回答1: The rendering origin is the problem

How to Draw a Rubber Band Selection Rectangle accurately on a Rotated Canvas?

只愿长相守 提交于 2019-12-23 04:50:46
问题 This is a rubber band selection rectangle drawn on a canvas. My problem is that it is easy to get the correct size of the rectangle provided the canvas contents are not rotated. But as soon as it is rotated the rectangle no longer sizes with the cursor. I need the rubber band to stay parallel with screen var dragPt = new PointF(e.Position.X - G.ReferenceOffset.X, e.Position.Y - G.ReferenceOffset.Y); var rotation = ADEEnvironment.RotateAngle; var width = (dragPt.X - pressPt.X); var height =