How to get an image of a panel with a drop-down list

I need to capture a panel image.

The problem I am facing is that if the panel contains TCombobox, the text does not appear.

procedure AssignPanelImageToPicture(Panel : TPanel;Image : TImage); var B : TBitmap; begin B := TBitmap.Create; try B.Width := Panel.Width; B.Height := Panel.Height; B.Canvas.Lock; Panel.PaintTo(B.Canvas.Handle,0,0); B.Canvas.Unlock; Image1.Picture.Assign(B); finally B.Free; end; end; 

Using this code, I throw a panel on it with TCombobox. Then enter the value in the text property. I also throw a TImage. Then I add a button to call the above code.

Here is the result:

Imaging of Panel Painting Problem

Is there a better way to capture a true panel image.

+4
source share
1 answer

How to use GetDC and GetDC functions?

 procedure AssignPanelImageToPicture(Panel : TPanel;Image : TImage); var B : TBitmap; SrcDC: HDC; begin B := TBitmap.Create; try B.Width := Panel.Width; B.Height := Panel.Height; SrcDC := GetDC(Panel.Handle); try BitBlt(B.Canvas.Handle, 0, 0, Panel.ClientWidth, Panel.ClientHeight, SrcDC, 0, 0, SRCCOPY); finally ReleaseDC(Panel.Handle, SrcDC); end; Image.Picture.Assign(B); finally B.Free; end; end; 
+10
source

Source: https://habr.com/ru/post/1390543/


All Articles