1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| private void CreateTransparentTask()
{
// Create the screen graphic device
pDisplayDC = WinGDI.CreateDC("DISPLAY", null, null, (System.IntPtr)null);
displayGraphics = Graphics.FromHdc(pDisplayDC);
// Determine the actual size of the dragged image
dragImageSize = new Size(this.Width, this.Height);
// Determine and create the image buffer.
buffer = new Bitmap(dragImageSize.Width + 2, dragImageSize.Height + 2);
bufferGraphics = Graphics.FromImage(buffer);
//this.Parent.Controls.Add(buffer);
pBufferDC = bufferGraphics.GetHdc();
// Copy the rectangluar image from the screen into buffer.
WinGDI.BitBlt(pBufferDC, 0, 0, buffer.Width, buffer.Height, pDisplayDC, this.StartPoint.X, this.StartPoint.Y, WinGDI.SRCCOPY);
// Store the image buffer position for tracking
bufferPos = this.StartPoint;
//Display the image
DrawDragImage(displayGraphics, this.StartPoint.X, this.StartPoint.Y, true);
}
private void DrawDragImage(Graphics g, int x, int y, bool bEnabled)
{
try
{
g.SmoothingMode = SmoothingMode.AntiAlias; // Anti-aliased rendering
Rectangle rect = new Rectangle(x, y, dragImageSize.Width, dragImageSize.Height);
using (Pen p = new Pen(Color.Black))
{
// Semi-Transparent
using (Brush backBrush = new SolidBrush(Color.FromArgb(127, Color.LightSteelBlue)))
{
using (Brush foreBrush = new SolidBrush(Color.Black))
{
g.FillRectangle(backBrush, rect.Left + 1, rect.Top + 1, rect.Width - 2, rect.Height - 2);
g.DrawRectangle(p, rect.Left, rect.Top, rect.Width - 1, rect.Height - 1);
}
}
}
}
catch (SecurityException) { }
} |
Partager