I'll answer my own question, as this kept nagging at me and I HAD to
find an answer! Posting my solution might just help someone else.
First I should state this isn't an ideal solution. I'd like to do this
without drawing anything, as it could then all be done in my control
library, without resorting to an exposed property through which the
color is provided. As it is, I've taken advantage of the fact that the
first thing a user has to do in my application is go through a user
login form, and on the form is a standard textbox. I've captured the
color that way.
' default value
Public AppBorderColor As Color = Color.Black
Private Sub getControlBorderColor()
' on the form is a Panel control, and in the panel is a
TextBox (UserNameTxt)
Dim bm As Bitmap = renderImageFromControl(Panel1)
AppBorderColor = bm.GetPixel(UserNameTxt.Location.X,
UserNameTxt.Location.Y)
End Sub
Private Function renderImageFromControl(ByVal control As
System.Windows.Forms.Control) As System.Drawing.Bitmap
' Get this form's Graphics object.
Dim me_gr As System.Drawing.Graphics =
control.CreateGraphics()
' Me._axFramerControl.CreateGraphics
' Make a Bitmap to hold the image.
Dim bm As New System.Drawing.Bitmap(control.ClientSize.Width,
control.ClientSize.Height)
Dim bm_gr As System.Drawing.Graphics =
System.Drawing.Graphics.FromImage(bm)
Dim bm_hdc As IntPtr = bm_gr.GetHdc
' Get the form's hDC. We must do this after
' creating the new Bitmap, which uses me_gr.
Dim me_hdc As IntPtr = me_gr.GetHdc
' BitBlt the form's image onto the Bitmap.
BitBlt(bm_hdc, 0, 0, control.ClientSize.Width,
control.ClientSize.Height, me_hdc, 0, 0, SRCCOPY)
me_gr.ReleaseHdc(me_hdc)
bm_gr.ReleaseHdc(bm_hdc)
' Return the result.
Return bm
End Function
Private Declare Auto Function BitBlt Lib "gdi32.dll" (ByVal
hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer,
ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As
IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As
System.Int32) As Boolean
Private Const SRCCOPY As Integer = &HCC0020
If anyone has a solution that gets the value directly, without
resorting to screen capturing, I'd still be interested!