Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / February 2007

Tip: Looking for answers? Try searching our database.

Get the color of a control's border

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
stroudpete@gmail.com - 21 Feb 2007 16:00 GMT
I have a control which extends CheckBox where I handle the onpaint
event. I am doing this so that I can make the actual tickbox larger
(and hence the tick), and to change the background color of the
tickbox (but not the text area) when the control is disabled. This is
working properly, but I have one issue outstanding - how do I find out
the current color being used for control borders, eg textbox? I am
using XP Themes. Just in case this is read quickly, can I emphasise I
am looking to detect the theme color in my code - using a color picker
tool to find the RGB and hard-coding it is not an option I would use!

I have searched hard to find the answer to this. The closest I can get
are references to EP_EDITTEXT, but nobody has actually shown the code
necessary to use this. I've found the Microsoft definition page, but
although it has comprehensive definitions, it doesn't show how to use
it. I'm using VB, but I can usually work it out from corresponding C
code!
stroudpete@gmail.com - 22 Feb 2007 12:03 GMT
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!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.