469,592 Members | 1,784 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

Label control border color

Is there a quick and easy way to change the color of a label controls border
from the default black to white?

Thank you,
John
Nov 20 '05 #1
31 6445
Hi,

If you want to change the border color you have to override the
WM_NCPAINT message.
Public Class BorderLabel
Inherits Label

Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC" (ByVal
hwnd As IntPtr) _
As IntPtr
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal
hwnd As IntPtr, _
ByVal hdc As IntPtr) As Integer
Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
Const WM_NCPAINT = &H85

If m.Msg = WM_NCPAINT Then
Dim penBorder As New Pen(Color.White, 3)
Dim hdc As IntPtr = GetWindowDC(m.HWnd)
Dim g As Graphics = Graphics.FromHdc(hdc)
Dim rDraw As Rectangle = New Rectangle(0, 0, Me.Width,
Me.Height)

g.DrawRectangle(penBorder, rDraw)

ReleaseDC(Me.Handle, hdc)
Else
MyBase.WndProc(m)

End If

End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub

Public Sub New()
Me.BorderStyle = BorderStyle.FixedSingle
End Sub
End Class

Ken
---------------------------

"jcrouse" <me> wrote in message
news:eC*************@TK2MSFTNGP10.phx.gbl:
Is there a quick and easy way to change the color of a label controls
border
from the default black to white?

Thank you,
John


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004
Nov 20 '05 #2
* Ken Tucker [MVP] <vb***@bellsouth.net> scripsit:
Dim penBorder As New Pen(Color.White, 3)
Dim hdc As IntPtr = GetWindowDC(m.HWnd)
Dim g As Graphics = Graphics.FromHdc(hdc)
Dim rDraw As Rectangle = New Rectangle(0, 0, Me.Width,
Me.Height)

g.DrawRectangle(penBorder, rDraw)

ReleaseDC(Me.Handle, hdc)


Don't forget to dispose the pen 'penBorder' there.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
Ken,
What do I do with this code or where does it need to go. I created a new
project and added one label to the form. Here is the entire code:

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents Label1 As System.Windows.Forms.Label

<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

Me.Label1 = New System.Windows.Forms.Label

Me.SuspendLayout()

'

'Label1

'

Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle

Me.Label1.Location = New System.Drawing.Point(48, 56)

Me.Label1.Name = "Label1"

Me.Label1.Size = New System.Drawing.Size(136, 48)

Me.Label1.TabIndex = 0

Me.Label1.Text = "Label1"

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(292, 273)

Me.Controls.Add(Me.Label1)

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout(False)

End Sub

#End Region
I added it on the end but got nothing. Do I need to call something somehow
or mix pieces of the code in with the above code?

Thanks,
John

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uv*************@TK2MSFTNGP11.phx.gbl...
Hi,

If you want to change the border color you have to override the
WM_NCPAINT message.
Public Class BorderLabel
Inherits Label

Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC" (ByVal
hwnd As IntPtr) _
As IntPtr
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal
hwnd As IntPtr, _
ByVal hdc As IntPtr) As Integer
Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
Const WM_NCPAINT = &H85

If m.Msg = WM_NCPAINT Then
Dim penBorder As New Pen(Color.White, 3)
Dim hdc As IntPtr = GetWindowDC(m.HWnd)
Dim g As Graphics = Graphics.FromHdc(hdc)
Dim rDraw As Rectangle = New Rectangle(0, 0, Me.Width,
Me.Height)

g.DrawRectangle(penBorder, rDraw)

ReleaseDC(Me.Handle, hdc)
Else
MyBase.WndProc(m)

End If

End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub

Public Sub New()
Me.BorderStyle = BorderStyle.FixedSingle
End Sub
End Class

Ken
---------------------------

"jcrouse" <me> wrote in message
news:eC*************@TK2MSFTNGP10.phx.gbl:
Is there a quick and easy way to change the color of a label controls
border
from the default black to white?

Thank you,
John


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004

Nov 20 '05 #4
Hi Ken,

Can you change this in your sample?
Const WM_NCPAINT = &H85

Const WM_NCPAINT As Integer = &H85

:-)

Cor
Nov 20 '05 #5
Hi,

Sure.

Ken
--------------------

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:#u**************@TK2MSFTNGP10.phx.gbl:
Hi Ken,

Can you change this in your sample?
Const WM_NCPAINT = &H85


Const WM_NCPAINT As Integer = &H85

:-)

Cor


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004
Nov 20 '05 #6
Hi John,

Using Kens code I made this class, you can use it by creating a new item
(usercontrol), name it UserLabel, delete all the code, build, and now you
can drag it from your toolbox usercontrols on your form.

Public Class UserLabel
Inherits System.Windows.Forms.Label
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
Private Sub InitializeComponent()
components = New System.ComponentModel.Container
Me.BorderStyle = BorderStyle.FixedSingle
End Sub
Declare Function GetWindowDC Lib "user32" Alias _
"GetWindowDC" (ByVal hwnd As IntPtr) _
As IntPtr
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" _
(ByVal hwnd As IntPtr, _
ByVal hdc As IntPtr) As Integer
Protected Overrides Sub WndProc(ByRef m _
As System.Windows.Forms.Message)
Const WM_NCPAINT As Integer = &H85
If m.Msg = WM_NCPAINT Then
Dim penBorder As New Pen(Color.White, 3)
Dim hdc As IntPtr = GetWindowDC(m.HWnd)
Dim g As Graphics = Graphics.FromHdc(hdc)
Dim rDraw As Rectangle = _
New Rectangle(0, 0, Me.Width, Me.Height)
g.DrawRectangle(penBorder, rDraw)
ReleaseDC(Me.Handle, hdc)
g.Dispose()
Else
MyBase.WndProc(m)
End If
End Sub
End Class

I hope this helps?
(The code is changed from Ken not original from me).

Cor
Nov 20 '05 #7
Hi,

Compile it into a control and add it to your form.
http://www.onteorasoftware.com/downl...hiteborder.zip

Ken
-------------

"jcrouse" <me> wrote in message
news:ei**************@TK2MSFTNGP10.phx.gbl:
Ken,
What do I do with this code or where does it need to go. I created a new

project and added one label to the form. Here is the entire code:

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents Label1 As System.Windows.Forms.Label

<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

Me.Label1 = New System.Windows.Forms.Label

Me.SuspendLayout()

'

'Label1

'

Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle

Me.Label1.Location = New System.Drawing.Point(48, 56)

Me.Label1.Name = "Label1"

Me.Label1.Size = New System.Drawing.Size(136, 48)

Me.Label1.TabIndex = 0

Me.Label1.Text = "Label1"

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(292, 273)

Me.Controls.Add(Me.Label1)

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout(False)

End Sub

#End Region
I added it on the end but got nothing. Do I need to call something somehow

or mix pieces of the code in with the above code?

Thanks,
John

"Ken Tucker [MVP]" <HYPERLINK
"mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message
news:uv*************@TK2MSFTNGP11.phx.gbl...
Hi,

If you want to change the border color you have to override the
WM_NCPAINT message.
Public Class BorderLabel
Inherits Label

Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC"
(ByVal
hwnd As IntPtr) _
As IntPtr
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal
hwnd As IntPtr, _
ByVal hdc As IntPtr) As Integer
Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
Const WM_NCPAINT = &H85

If m.Msg = WM_NCPAINT Then
Dim penBorder As New Pen(Color.White, 3)
Dim hdc As IntPtr = GetWindowDC(m.HWnd)
Dim g As Graphics = Graphics.FromHdc(hdc)
Dim rDraw As Rectangle = New Rectangle(0, 0, Me.Width,
Me.Height)

g.DrawRectangle(penBorder, rDraw)

ReleaseDC(Me.Handle, hdc)
Else
MyBase.WndProc(m)

End If

End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub

Public Sub New()
Me.BorderStyle = BorderStyle.FixedSingle
End Sub
End Class

Ken
---------------------------

"jcrouse" <me> wrote in message
news:eC*************@TK2MSFTNGP10.phx.gbl:

Is there a quick and easy way to change the color of a label
controls
border
from the default black to white?

Thank you,
John

--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004
Nov 20 '05 #8
* Ken Tucker [MVP] <vb***@bellsouth.net> scripsit:
Sure.


.... but in this case not necessary. The value will be treated as
'Int32' automatically.
Const WM_NCPAINT = &H85


Const WM_NCPAINT As Integer = &H85


--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #9
Hi Herfried,

You can be glad that Armin is not active some days I think.

... but in this case not necessary. The value will be treated as
'Int32' automatically.
Const WM_NCPAINT = &H85

Const WM_NCPAINT As Integer = &H85


Do you think I saw this, I was just making a sample for John, while I
thought Ken was not active, when I saw that Ken was I had already made it
and found it a pity not to send it.

Cor
Nov 20 '05 #10
* "Cor Ligthert" <no**********@planet.nl> scripsit:
You can be glad that Armin is not active some days I think.


Why?!
... but in this case not necessary. The value will be treated as
'Int32' automatically.
> Const WM_NCPAINT = &H85

Const WM_NCPAINT As Integer = &H85


Do you think I saw this, I was just making a sample for John, while I
thought Ken was not active, when I saw that Ken was I had already made it
and found it a pity not to send it.


\\\
Const WM_NCPAINT = &H85
MsgBox(WM_NCPAINT.GetType().ToString())
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #11
Option Strict On requires all variable declarations to have an 'As' clause.
As Armin would point out, we should all have Option Strict On

;-)

--
Mick Doherty
http://dotnetrix.co.uk
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2k***********@uni-berlin.de...
* "Cor Ligthert" <no**********@planet.nl> scripsit:
You can be glad that Armin is not active some days I think.


Why?!
... but in this case not necessary. The value will be treated as
'Int32' automatically.

>> Const WM_NCPAINT = &H85
>
> Const WM_NCPAINT As Integer = &H85


Do you think I saw this, I was just making a sample for John, while I
thought Ken was not active, when I saw that Ken was I had already made it and found it a pity not to send it.


\\\
Const WM_NCPAINT = &H85
MsgBox(WM_NCPAINT.GetType().ToString())
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.701 / Virus Database: 458 - Release Date: 07/06/2004
Nov 20 '05 #12
* "Mick Doherty" <EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> scripsit:
Option Strict On requires all variable declarations to have an 'As' clause.
As Armin would point out, we should all have Option Strict On


Yep. I worked with 'Option Strict Off'. The error message is
misleading because it's a constant, not a variable.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #13
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2k***********@uni-berlin.de...
Yep. I worked with 'Option Strict Off'. The error message is
misleading because it's a constant, not a variable.


I agree. Especially since if you put the Constant in an Enum it is
automatically an Int32 unless you specify differently.

--
Mick Doherty
http://dotnetrix.co.uk

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.701 / Virus Database: 458 - Release Date: 07/06/2004
Nov 20 '05 #14
Mick,

* "Mick Doherty" <EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> scripsit:
Yep. I worked with 'Option Strict Off'. The error message is
misleading because it's a constant, not a variable.


I agree. Especially since if you put the Constant in an Enum it is
automatically an Int32 unless you specify differently.


.... there is no error message if there is no type specified for a
constant inside an enum.

;-)

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #15
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2k***********@uni-berlin.de...

... there is no error message if there is no type specified for a
constant inside an enum.


That's what I said.
"if you put the Constant in an Enum it is automatically an Int32 unless you
specify differently"
i.e.
\\\
Enum ByteEnum As Byte
SomeVar = 2
End Enum

Enum Int32Enum
SomeVar = 2
End Enum
///

--
Mick Doherty
http://dotnetrix.co.uk
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.701 / Virus Database: 458 - Release Date: 07/06/2004
Nov 20 '05 #16
Mick,

* "Mick Doherty" <EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> scripsit:
... there is no error message if there is no type specified for a
constant inside an enum.


That's what I said.
"if you put the Constant in an Enum it is automatically an Int32 unless you
specify differently"
i.e.
\\\
Enum ByteEnum As Byte
SomeVar = 2
End Enum

Enum Int32Enum
SomeVar = 2
End Enum
///


OK, yes, you can only specify the type of the enum, not for the
constants (as expected). I wonder too why there is no compile time
error with 'Option Strict On' when implicitly using 'Int32' as base
type.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #17
Well, I finally got a chance to try it out. Nice control. However, I already have two forms and 52 labels and probably 60 pages of code and don't really want to start from scratch. I tried to delete a label, add one of yours and rename it to the original name but quite a bit of the code didn't work. I am actually moving the control at runtime and a few other things.

Thanks alot,
John

"Ken Tucker [MVP]" wrote:
Hi,

Compile it into a control and add it to your form.
http://www.onteorasoftware.com/downl...hiteborder.zip

Ken
-------------

"jcrouse" <me> wrote in message
news:ei**************@TK2MSFTNGP10.phx.gbl:
Ken,
What do I do with this code or where does it need to go. I created a new

project and added one label to the form. Here is the entire code:

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents Label1 As System.Windows.Forms.Label

<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

Me.Label1 = New System.Windows.Forms.Label

Me.SuspendLayout()

'

'Label1

'

Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle

Me.Label1.Location = New System.Drawing.Point(48, 56)

Me.Label1.Name = "Label1"

Me.Label1.Size = New System.Drawing.Size(136, 48)

Me.Label1.TabIndex = 0

Me.Label1.Text = "Label1"

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(292, 273)

Me.Controls.Add(Me.Label1)

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout(False)

End Sub

#End Region
I added it on the end but got nothing. Do I need to call something somehow

or mix pieces of the code in with the above code?

Thanks,
John

"Ken Tucker [MVP]" <HYPERLINK
"mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message
news:uv*************@TK2MSFTNGP11.phx.gbl...
Hi,

If you want to change the border color you have to override the
WM_NCPAINT message.
Public Class BorderLabel
Inherits Label

Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC"
(ByVal
hwnd As IntPtr) _
As IntPtr
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal
hwnd As IntPtr, _
ByVal hdc As IntPtr) As Integer
Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
Const WM_NCPAINT = &H85

If m.Msg = WM_NCPAINT Then
Dim penBorder As New Pen(Color.White, 3)
Dim hdc As IntPtr = GetWindowDC(m.HWnd)
Dim g As Graphics = Graphics.FromHdc(hdc)
Dim rDraw As Rectangle = New Rectangle(0, 0, Me.Width,
Me.Height)

g.DrawRectangle(penBorder, rDraw)

ReleaseDC(Me.Handle, hdc)
Else
MyBase.WndProc(m)

End If

End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub

Public Sub New()
Me.BorderStyle = BorderStyle.FixedSingle
End Sub
End Class

Ken
---------------------------

"jcrouse" <me> wrote in message
news:eC*************@TK2MSFTNGP10.phx.gbl:

> Is there a quick and easy way to change the color of a label
> controls
> border
> from the default black to white?
>
> Thank you,
> John
>

--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004

Nov 20 '05 #18
Hi John,

After sending my message I got the idea of using flatstyle buttons withouth
using the events (maybe a little bit dificult in your situation because we
made those dynamic buttons, however I do not know how far you did implement
that). You can use a label as a button so why not a button as a label.

Cor
Well, I finally got a chance to try it out. Nice control. However, I already have two forms and 52 labels and probably 60 pages of code and don't
really want to start from scratch. I tried to delete a label, add one of
yours and rename it to the original name but quite a bit of the code didn't
work. I am actually moving the control at runtime and a few other things.
Thanks alot,
John

"Ken Tucker [MVP]" wrote:
Hi,

Compile it into a control and add it to your form.
http://www.onteorasoftware.com/downl...hiteborder.zip

Ken
-------------

"jcrouse" <me> wrote in message
news:ei**************@TK2MSFTNGP10.phx.gbl:
Ken,
What do I do with this code or where does it need to go. I created a new
project and added one label to the form. Here is the entire code:

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents Label1 As System.Windows.Forms.Label

<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

Me.Label1 = New System.Windows.Forms.Label

Me.SuspendLayout()

'

'Label1

'

Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle

Me.Label1.Location = New System.Drawing.Point(48, 56)

Me.Label1.Name = "Label1"

Me.Label1.Size = New System.Drawing.Size(136, 48)

Me.Label1.TabIndex = 0

Me.Label1.Text = "Label1"

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(292, 273)

Me.Controls.Add(Me.Label1)

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout(False)

End Sub

#End Region
I added it on the end but got nothing. Do I need to call something somehow
or mix pieces of the code in with the above code?

Thanks,
John

"Ken Tucker [MVP]" <HYPERLINK
"mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message
news:uv*************@TK2MSFTNGP11.phx.gbl...

> Hi,
>
> If you want to change the border color you have to override the
> WM_NCPAINT message.
>
>
> Public Class BorderLabel
> Inherits Label
>
> Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC"
> (ByVal
> hwnd As IntPtr) _
> As IntPtr
> Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal
> hwnd As IntPtr, _
> ByVal hdc As IntPtr) As Integer
>
>
> Protected Overrides Sub WndProc(ByRef m As
> System.Windows.Forms.Message)
> Const WM_NCPAINT = &H85
>
> If m.Msg = WM_NCPAINT Then
> Dim penBorder As New Pen(Color.White, 3)
> Dim hdc As IntPtr = GetWindowDC(m.HWnd)
> Dim g As Graphics = Graphics.FromHdc(hdc)
> Dim rDraw As Rectangle = New Rectangle(0, 0, Me.Width,
> Me.Height)
>
> g.DrawRectangle(penBorder, rDraw)
>
> ReleaseDC(Me.Handle, hdc)
> Else
> MyBase.WndProc(m)
>
> End If
>
> End Sub
>
> Protected Overrides Sub Finalize()
> MyBase.Finalize()
> End Sub
>
> Public Sub New()
> Me.BorderStyle = BorderStyle.FixedSingle
> End Sub
> End Class
>
> Ken
> ---------------------------
>
> "jcrouse" <me> wrote in message
> news:eC*************@TK2MSFTNGP10.phx.gbl:

> > Is there a quick and easy way to change the color of a label
> > controls
> > border
> > from the default black to white?
> >
> > Thank you,
> > John
> >
>

> --
> Outgoing mail is certified Virus Free.
> Checked by AVG Anti-Virus (http://www.grisoft.com).
> Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004
>
>


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004

Nov 20 '05 #19
Sorry if this posts twice. I thought I added this a day or two ago but don't see it. I have 30 some controls and would like to change the existing ones instead of adding new controls. I have LOTS of code to consider. Any ideas how?

Thank you,
John

"jcrouse" wrote:
Is there a quick and easy way to change the color of a label controls border
from the default black to white?

Thank you,
John

Nov 20 '05 #20
Hi,

Here is a class that uses nativewindows to change the border to white.
Create an instance for each label you want to have a white border.
Public Class WhiteBorderChanger
Inherits NativeWindow

Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC"
(ByVal hwnd As IntPtr) _
As IntPtr
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal
hwnd As IntPtr, _
ByVal hdc As IntPtr) As Integer

Private ctrl As Control

Public Sub New(ByVal ctrl As Control)

AssignHandle(ctrl.Handle)
Me.ctrl = ctrl
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
' Listen for operating system messages

Const WM_NCPAINT As Integer = &H85

If m.Msg = WM_NCPAINT Then
Dim hdc As IntPtr = GetWindowDC(m.HWnd)
Dim g As Graphics = Graphics.FromHdc(hdc)

Dim pXp As Pen = New Pen(Color.White, 3)

g.DrawRectangle(pXp, 0, 0, ctrl.Width - 1, ctrl.Height -
1)
ReleaseDC(Me.Handle, hdc)
Else
MyBase.WndProc(m)

End If
End Sub

Protected Overrides Sub Finalize()
ReleaseHandle()
MyBase.Finalize()
End Sub
End Class

Ken
-------------------

"jcrouse" <jc*****@discussions.microsoft.com> wrote in message
news:F3**********************************@microsof t.com:
Sorry if this posts twice. I thought I added this a day or two ago but
don't see it. I have 30 some controls and would like to change the existing
ones instead of adding new controls. I have LOTS of code to consider. Any
ideas how?

Thank you,
John

"jcrouse" wrote:

Is there a quick and easy way to change the color of a label controls
border
from the default black to white?

Thank you,
John


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004
Nov 20 '05 #21
This is ask due to my VB ignorance, sorry. Where should I put the code?
Also, if I need an instance for each label, what is the piece the associates
an instance with a particular label?

Thank you very much,
John
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:e9**************@TK2MSFTNGP10.phx.gbl...
Hi,

Here is a class that uses nativewindows to change the border to white.
Create an instance for each label you want to have a white border.
Public Class WhiteBorderChanger
Inherits NativeWindow

Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC"
(ByVal hwnd As IntPtr) _
As IntPtr
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal
hwnd As IntPtr, _
ByVal hdc As IntPtr) As Integer

Private ctrl As Control

Public Sub New(ByVal ctrl As Control)

AssignHandle(ctrl.Handle)
Me.ctrl = ctrl
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
' Listen for operating system messages

Const WM_NCPAINT As Integer = &H85

If m.Msg = WM_NCPAINT Then
Dim hdc As IntPtr = GetWindowDC(m.HWnd)
Dim g As Graphics = Graphics.FromHdc(hdc)

Dim pXp As Pen = New Pen(Color.White, 3)

g.DrawRectangle(pXp, 0, 0, ctrl.Width - 1, ctrl.Height -
1)
ReleaseDC(Me.Handle, hdc)
Else
MyBase.WndProc(m)

End If
End Sub

Protected Overrides Sub Finalize()
ReleaseHandle()
MyBase.Finalize()
End Sub
End Class

Ken
-------------------

"jcrouse" <jc*****@discussions.microsoft.com> wrote in message
news:F3**********************************@microsof t.com:
Sorry if this posts twice. I thought I added this a day or two ago but
don't see it. I have 30 some controls and would like to change the existing ones instead of adding new controls. I have LOTS of code to consider. Any ideas how?

Thank you,
John

"jcrouse" wrote:

Is there a quick and easy way to change the color of a label controls
border
from the default black to white?

Thank you,
John


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004

Nov 20 '05 #22
Hi,

Sorry should have posted some code.

Dim arLabelBorderChanger As New ArrayList

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
AddLabel(Me.Controls)
End Sub

Private Sub AddLabel(ByVal ctrls As Control.ControlCollection)
For Each ctrl As Control In ctrls
If TypeOf ctrl Is Label Then
DirectCast(ctrl, Label).BorderStyle =
BorderStyle.FixedSingle
arLabelBorderChanger.Add(New WhiteBorderChanger(ctrl))
End If
AddLabel(ctrl.Controls) ' add a child controls to list
Next
End Sub

Ken
------------------------------------

"jcrouse" <me> wrote in message
news:#b**************@TK2MSFTNGP09.phx.gbl:
This is ask due to my VB ignorance, sorry. Where should I put the code?
Also, if I need an instance for each label, what is the piece the
associates
an instance with a particular label?

Thank you very much,
John
"Ken Tucker [MVP]" <HYPERLINK
"mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message
news:e9**************@TK2MSFTNGP10.phx.gbl...
Hi,

Here is a class that uses nativewindows to change the border to white.
Create an instance for each label you want to have a white border.
Public Class WhiteBorderChanger
Inherits NativeWindow

Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC"
(ByVal hwnd As IntPtr) _
As IntPtr
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC"
(ByVal
hwnd As IntPtr, _
ByVal hdc As IntPtr) As Integer

Private ctrl As Control

Public Sub New(ByVal ctrl As Control)

AssignHandle(ctrl.Handle)
Me.ctrl = ctrl
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
' Listen for operating system messages

Const WM_NCPAINT As Integer = &H85

If m.Msg = WM_NCPAINT Then
Dim hdc As IntPtr = GetWindowDC(m.HWnd)
Dim g As Graphics = Graphics.FromHdc(hdc)

Dim pXp As Pen = New Pen(Color.White, 3)

g.DrawRectangle(pXp, 0, 0, ctrl.Width - 1, ctrl.Height
-
1)
ReleaseDC(Me.Handle, hdc)
Else
MyBase.WndProc(m)

End If
End Sub

Protected Overrides Sub Finalize()
ReleaseHandle()
MyBase.Finalize()
End Sub
End Class

Ken
-------------------

"jcrouse" <HYPERLINK
"mailto:jc*****@discussions.microsoft.com"jc*****@ discussions.microsoft.com>
wrote in message
news:F3**********************************@microsof t.com:

Sorry if this posts twice. I thought I added this a day or two ago
but
don't see it. I have 30 some controls and would like to change the
existing
ones instead of adding new controls. I have LOTS of code to
consider.
Any
ideas how?

Thank you,
John

"jcrouse" wrote:

Is there a quick and easy way to change the color of a label
> controls
> border
> from the default black to white?
>
> Thank you,
> John
>
>
>

--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004
Nov 20 '05 #23
Ken,
Well, this is embarassing, but here goes. Unfortunately I do NOT have my
controls in an array. I may move them to one later but for now they are not.
It has really made the coding much more difficult than it should have been.
Right now I am learning the code and shooting for functionality. I will
clean things up later. Anyways, when my form loads the labels are already on
the form. I am trying to modify your code to work with this arrangement.
Here's what I have so far. We are working with a label named lblP1JoyUp.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
DirectCast(lblP1JoyUp, Label).BorderStyle =
BorderStyle.FixedSingle
arLabelBorderChanger.Add(New WhiteBorderChanger(ctrl))
End Sub

I'm not sure if the WhiteBorderChanger Class needs modified either?

What do I need to do here?

Thank you,

John

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
Hi,

Sorry should have posted some code.

Dim arLabelBorderChanger As New ArrayList

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
AddLabel(Me.Controls)
End Sub

Private Sub AddLabel(ByVal ctrls As Control.ControlCollection)
For Each ctrl As Control In ctrls
If TypeOf ctrl Is Label Then
DirectCast(ctrl, Label).BorderStyle =
BorderStyle.FixedSingle
arLabelBorderChanger.Add(New WhiteBorderChanger(ctrl))
End If
AddLabel(ctrl.Controls) ' add a child controls to list
Next
End Sub

Ken
------------------------------------

"jcrouse" <me> wrote in message
news:#b**************@TK2MSFTNGP09.phx.gbl:
This is ask due to my VB ignorance, sorry. Where should I put the code?
Also, if I need an instance for each label, what is the piece the
associates
an instance with a particular label?

Thank you very much,
John
"Ken Tucker [MVP]" <HYPERLINK
"mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message
news:e9**************@TK2MSFTNGP10.phx.gbl...
Hi,

Here is a class that uses nativewindows to change the border to white.
Create an instance for each label you want to have a white border.
Public Class WhiteBorderChanger
Inherits NativeWindow

Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC"
(ByVal hwnd As IntPtr) _
As IntPtr
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC"
(ByVal
hwnd As IntPtr, _
ByVal hdc As IntPtr) As Integer

Private ctrl As Control

Public Sub New(ByVal ctrl As Control)

AssignHandle(ctrl.Handle)
Me.ctrl = ctrl
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
' Listen for operating system messages

Const WM_NCPAINT As Integer = &H85

If m.Msg = WM_NCPAINT Then
Dim hdc As IntPtr = GetWindowDC(m.HWnd)
Dim g As Graphics = Graphics.FromHdc(hdc)

Dim pXp As Pen = New Pen(Color.White, 3)

g.DrawRectangle(pXp, 0, 0, ctrl.Width - 1, ctrl.Height
-
1)
ReleaseDC(Me.Handle, hdc)
Else
MyBase.WndProc(m)

End If
End Sub

Protected Overrides Sub Finalize()
ReleaseHandle()
MyBase.Finalize()
End Sub
End Class

Ken
-------------------

"jcrouse" <HYPERLINK
"mailto:jc*****@discussions.microsoft.com"jc*****@ discussions.microsoft.com> wrote in message
news:F3**********************************@microsof t.com:

> Sorry if this posts twice. I thought I added this a day or two ago
> but
> don't see it. I have 30 some controls and would like to change the


existing
> ones instead of adding new controls. I have LOTS of code to
> consider.


Any
> ideas how?
>
> Thank you,
> John
>
> "jcrouse" wrote:
>
>

> > Is there a quick and easy way to change the color of a label
> > controls
> > border
> > from the default black to white?
> >
> > Thank you,
> > John
> >
> >
> >
>

--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004

Nov 20 '05 #24
Hi,

Sure you do. All controls are added to the forms control collection.
The code I posted will loop through all the controls on the form and if
the control is a label it will add a new whiteborderchanger to the
Arraylist. It also changes the border to a fixed single to make sure the
white border will draw.
Ken
-------------

"jcrouse" <me> wrote in message
news:uo**************@tk2msftngp13.phx.gbl:
Ken,
Well, this is embarassing, but here goes. Unfortunately I do NOT have my

controls in an array. I may move them to one later but for now they are
not.
It has really made the coding much more difficult than it should have
been.
Right now I am learning the code and shooting for functionality. I will
clean things up later. Anyways, when my form loads the labels are already
on
the form. I am trying to modify your code to work with this arrangement.

Here's what I have so far. We are working with a label named lblP1JoyUp.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
DirectCast(lblP1JoyUp, Label).BorderStyle =
BorderStyle.FixedSingle
arLabelBorderChanger.Add(New WhiteBorderChanger(ctrl))
End Sub

I'm not sure if the WhiteBorderChanger Class needs modified either?

What do I need to do here?

Thank you,

John

"Ken Tucker [MVP]" <HYPERLINK
"mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
Hi,

Sorry should have posted some code.

Dim arLabelBorderChanger As New ArrayList

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
AddLabel(Me.Controls)
End Sub

Private Sub AddLabel(ByVal ctrls As Control.ControlCollection)
For Each ctrl As Control In ctrls
If TypeOf ctrl Is Label Then
DirectCast(ctrl, Label).BorderStyle =
BorderStyle.FixedSingle
arLabelBorderChanger.Add(New WhiteBorderChanger(ctrl))
End If
AddLabel(ctrl.Controls) ' add a child controls to list
Next
End Sub

Ken
------------------------------------

"jcrouse" <me> wrote in message
news:#b**************@TK2MSFTNGP09.phx.gbl:

This is ask due to my VB ignorance, sorry. Where should I put the
code?
Also, if I need an instance for each label, what is the piece the
associates
an instance with a particular label?

Thank you very much,
John
"Ken Tucker [MVP]" <HYPERLINK
"mailto:vb***@bellsouth.net"HYPERLINK
"mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message
news:e9**************@TK2MSFTNGP10.phx.gbl...
Hi,
>
> Here is a class that uses nativewindows to change the border to
> white.
> Create an instance for each label you want to have a white border.
>
>
> Public Class WhiteBorderChanger
> Inherits NativeWindow
>
> Declare Function GetWindowDC Lib "user32" Alias
> "GetWindowDC"
> (ByVal hwnd As IntPtr) _
> As IntPtr
> Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC"
> (ByVal
> hwnd As IntPtr, _
> ByVal hdc As IntPtr) As Integer
>
> Private ctrl As Control
>
> Public Sub New(ByVal ctrl As Control)
>
> AssignHandle(ctrl.Handle)
> Me.ctrl = ctrl
> End Sub
>
>
> Protected Overrides Sub WndProc(ByRef m As Message)
> ' Listen for operating system messages
>
> Const WM_NCPAINT As Integer = &H85
>
> If m.Msg = WM_NCPAINT Then
> Dim hdc As IntPtr = GetWindowDC(m.HWnd)
> Dim g As Graphics = Graphics.FromHdc(hdc)
>
> Dim pXp As Pen = New Pen(Color.White, 3)
>
> g.DrawRectangle(pXp, 0, 0, ctrl.Width - 1,
> ctrl.Height
> -
> 1)
> ReleaseDC(Me.Handle, hdc)
> Else
> MyBase.WndProc(m)
>
> End If
> End Sub
>
> Protected Overrides Sub Finalize()
> ReleaseHandle()
> MyBase.Finalize()
> End Sub
> End Class
>
>
>
> Ken
> -------------------
>
> "jcrouse" <HYPERLINK
>
"mailto:jc*****@discussions.microsoft.com"HYPERLIN K
"mailto:jc*****@discussions.microsoft.com"jc*****@ discussions.microsoft.com>

wrote in message
> news:F3**********************************@microsof t.com:
> Sorry if this posts twice. I thought I added this a day or two
> > ago
> > but
> > don't see it. I have 30 some controls and would like to change
> > the
existing
> ones instead of adding new controls. I have LOTS of code to
> > consider.
Any
> ideas how?
> >
> > Thank you,
> > John
> >
> > "jcrouse" wrote:
> >
> >
> > Is there a quick and easy way to change the color of a label
> > > controls
> > > border
> > > from the default black to white?
> > >
> > > Thank you,
> > > John
> > >
> > >
> > >
> >
>
--
> Outgoing mail is certified Virus Free.
> Checked by AVG Anti-Virus (http://www.grisoft.com).
> Version: 7.0.230 / Virus Database: 263.3.6 - Release Date:
> 6/25/2004
>
>

--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004
Nov 20 '05 #25
Ken,
Well that worked great. However (I say that alot), I need to give you
more of the story. My application is somewhat like the GDI in VB. I show a
frmMain that has 32 labels on it. The labels are there but hidden
(visible.false). Also, the labels by defaul have NO border (borderstyle =
borderstyle.none). I then have a second form, frmAddLabels. It lists the
name of the 32 labels with a checkbox for each label. The user can toggle
the visible property using the checkboxes. Thats pretty simple. Howerer, if
I remove (visible = false) a label the add it again it redisplays with the
standard black border. Now for the tricky part. I allow the user to select
the labels with a mouse click event at runtime. They can select multiple
labels at once using the crtl key. Once the labels are selected they can
perform the following functions, back color, fole color, size, font and the
such. Here's where it may get trick. I set the label to borderstyle =
borderstyle.fixedsingle to let the user see that the label is selected. When
the label properties are finished being set the user the unselects the
labels and this turns off the borders. Also, on top of all this, I use
mouse_down, mouse_move and mouse_up event so the user can reposition the
label on the screen where he needs it.

As for your code the first time I display a label using your code it has
a whiter border. This is awesome. But, if I remove (visible = false) the
border then redisplay it (visible = true) it comes back with a black border.
Also, when I add the label it automaticall displays with a white border and
I would like them to be added with the border set to borderstyle =
borderstyle.none. The user then needs to select them to perform an action.
When they are then selected they need to display your white border.

The white border is needed because the user is allowed to also add their
own background image and most images will be of a nature of a darker color
and the balck borders don't show up well. After I get this working (with
your help), I will probably add an option to my tools/options menu to allow
the user to select his own color for the highlighted border but that will
come later. I think I will just be able to plac the color in a variable and
use the variable name in your code in place of "white". I may also want to
play with the width of the border at some point.

So where do I go from here?

Thank you,
John
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:eY**************@TK2MSFTNGP11.phx.gbl...
Hi,

Sure you do. All controls are added to the forms control collection.
The code I posted will loop through all the controls on the form and if
the control is a label it will add a new whiteborderchanger to the
Arraylist. It also changes the border to a fixed single to make sure the
white border will draw.
Ken
-------------

"jcrouse" <me> wrote in message
news:uo**************@tk2msftngp13.phx.gbl:
Ken,
Well, this is embarassing, but here goes. Unfortunately I do NOT have my

controls in an array. I may move them to one later but for now they are
not.
It has really made the coding much more difficult than it should have
been.
Right now I am learning the code and shooting for functionality. I will
clean things up later. Anyways, when my form loads the labels are already on
the form. I am trying to modify your code to work with this arrangement.

Here's what I have so far. We are working with a label named lblP1JoyUp.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
DirectCast(lblP1JoyUp, Label).BorderStyle =
BorderStyle.FixedSingle
arLabelBorderChanger.Add(New WhiteBorderChanger(ctrl))
End Sub

I'm not sure if the WhiteBorderChanger Class needs modified either?

What do I need to do here?

Thank you,

John

"Ken Tucker [MVP]" <HYPERLINK
"mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
Hi,

Sorry should have posted some code.

Dim arLabelBorderChanger As New ArrayList

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
AddLabel(Me.Controls)
End Sub

Private Sub AddLabel(ByVal ctrls As Control.ControlCollection)
For Each ctrl As Control In ctrls
If TypeOf ctrl Is Label Then
DirectCast(ctrl, Label).BorderStyle =
BorderStyle.FixedSingle
arLabelBorderChanger.Add(New WhiteBorderChanger(ctrl))
End If
AddLabel(ctrl.Controls) ' add a child controls to list
Next
End Sub

Ken
------------------------------------

"jcrouse" <me> wrote in message
news:#b**************@TK2MSFTNGP09.phx.gbl:

> This is ask due to my VB ignorance, sorry. Where should I put the
> code?
> Also, if I need an instance for each label, what is the piece the
> associates
> an instance with a particular label?
>
> Thank you very much,
> John
>
>
> "Ken Tucker [MVP]" <HYPERLINK
> "mailto:vb***@bellsouth.net"HYPERLINK
> "mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message
> news:e9**************@TK2MSFTNGP10.phx.gbl...
>

> > Hi,
> >
> > Here is a class that uses nativewindows to change the border to
> > white.
> > Create an instance for each label you want to have a white border.
> >
> >
> > Public Class WhiteBorderChanger
> > Inherits NativeWindow
> >
> > Declare Function GetWindowDC Lib "user32" Alias
> > "GetWindowDC"
> > (ByVal hwnd As IntPtr) _
> > As IntPtr
> > Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC"
> > (ByVal
> > hwnd As IntPtr, _
> > ByVal hdc As IntPtr) As Integer
> >
> > Private ctrl As Control
> >
> > Public Sub New(ByVal ctrl As Control)
> >
> > AssignHandle(ctrl.Handle)
> > Me.ctrl = ctrl
> > End Sub
> >
> >
> > Protected Overrides Sub WndProc(ByRef m As Message)
> > ' Listen for operating system messages
> >
> > Const WM_NCPAINT As Integer = &H85
> >
> > If m.Msg = WM_NCPAINT Then
> > Dim hdc As IntPtr = GetWindowDC(m.HWnd)
> > Dim g As Graphics = Graphics.FromHdc(hdc)
> >
> > Dim pXp As Pen = New Pen(Color.White, 3)
> >
> > g.DrawRectangle(pXp, 0, 0, ctrl.Width - 1,
> > ctrl.Height
> > -
> > 1)
> > ReleaseDC(Me.Handle, hdc)
> > Else
> > MyBase.WndProc(m)
> >
> > End If
> > End Sub
> >
> > Protected Overrides Sub Finalize()
> > ReleaseHandle()
> > MyBase.Finalize()
> > End Sub
> > End Class
> >
> >
> >
> > Ken
> > -------------------
> >
> > "jcrouse" <HYPERLINK
> >


"mailto:jc*****@discussions.microsoft.com"HYPERLIN K
"mailto:jc*****@discussions.microsoft.com"jc*****@ discussions.microsoft.com>
> > wrote in message
> > news:F3**********************************@microsof t.com:
>

> > > Sorry if this posts twice. I thought I added this a day or two
> > > ago
> > > but
> > > don't see it. I have 30 some controls and would like to change
> > > the
>

> existing
>

> > > ones instead of adding new controls. I have LOTS of code to
> > > consider.
>

> Any
>

> > > ideas how?
> > >
> > > Thank you,
> > > John
> > >
> > > "jcrouse" wrote:
> > >
> > >
>

> > > > Is there a quick and easy way to change the color of a label
> > > > controls
> > > > border
> > > > from the default black to white?
> > > >
> > > > Thank you,
> > > > John
> > > >
> > > >
> > > >
> > >
> >
>

> > --
> > Outgoing mail is certified Virus Free.
> > Checked by AVG Anti-Virus (http://www.grisoft.com).
> > Version: 7.0.230 / Virus Database: 263.3.6 - Release Date:
> > 6/25/2004
> >
> >
>

--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004

Nov 20 '05 #26
Well Ken. I got them to both display and redisplay (after toggling them off)
with the white border. i added the following code to the OK button on my
frmAddLabels:

frm1.AddLabel(frm1.Controls)

Pretty straight forward. I am now trying to figure out how keep the white
when I select and deselect them with this code.

Private Sub lblP1JoyUp_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lblP1JoyUp.Click

If bMouseMove = False Then

If bCtrlKey = True Then

If lblP1JoyUp.BorderStyle = BorderStyle.None Then

lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle

bLabelSelected = True

ElseIf lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle Then

lblP1JoyUp.BorderStyle = BorderStyle.None

bLabelSelected = False

End If

End If

End If

End Sub
What do you think?

John

"jcrouse" <me> wrote in message
news:uD**************@TK2MSFTNGP11.phx.gbl...
Ken,
Well that worked great. However (I say that alot), I need to give you
more of the story. My application is somewhat like the GDI in VB. I show a
frmMain that has 32 labels on it. The labels are there but hidden
(visible.false). Also, the labels by defaul have NO border (borderstyle =
borderstyle.none). I then have a second form, frmAddLabels. It lists the
name of the 32 labels with a checkbox for each label. The user can toggle
the visible property using the checkboxes. Thats pretty simple. Howerer, if I remove (visible = false) a label the add it again it redisplays with the
standard black border. Now for the tricky part. I allow the user to select
the labels with a mouse click event at runtime. They can select multiple
labels at once using the crtl key. Once the labels are selected they can
perform the following functions, back color, fole color, size, font and the such. Here's where it may get trick. I set the label to borderstyle =
borderstyle.fixedsingle to let the user see that the label is selected. When the label properties are finished being set the user the unselects the
labels and this turns off the borders. Also, on top of all this, I use
mouse_down, mouse_move and mouse_up event so the user can reposition the
label on the screen where he needs it.

As for your code the first time I display a label using your code it has a whiter border. This is awesome. But, if I remove (visible = false) the
border then redisplay it (visible = true) it comes back with a black border. Also, when I add the label it automaticall displays with a white border and I would like them to be added with the border set to borderstyle =
borderstyle.none. The user then needs to select them to perform an action.
When they are then selected they need to display your white border.

The white border is needed because the user is allowed to also add their own background image and most images will be of a nature of a darker color
and the balck borders don't show up well. After I get this working (with
your help), I will probably add an option to my tools/options menu to allow the user to select his own color for the highlighted border but that will
come later. I think I will just be able to plac the color in a variable and use the variable name in your code in place of "white". I may also want to
play with the width of the border at some point.

So where do I go from here?

Thank you,
John
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:eY**************@TK2MSFTNGP11.phx.gbl...
Hi,

Sure you do. All controls are added to the forms control collection.
The code I posted will loop through all the controls on the form and if
the control is a label it will add a new whiteborderchanger to the
Arraylist. It also changes the border to a fixed single to make sure the
white border will draw.
Ken
-------------

"jcrouse" <me> wrote in message
news:uo**************@tk2msftngp13.phx.gbl:
Ken,
Well, this is embarassing, but here goes. Unfortunately I do NOT have my
controls in an array. I may move them to one later but for now they are not.
It has really made the coding much more difficult than it should have
been.
Right now I am learning the code and shooting for functionality. I will clean things up later. Anyways, when my form loads the labels are already on
the form. I am trying to modify your code to work with this arrangement.
Here's what I have so far. We are working with a label named lblP1JoyUp.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
DirectCast(lblP1JoyUp, Label).BorderStyle =
BorderStyle.FixedSingle
arLabelBorderChanger.Add(New WhiteBorderChanger(ctrl))
End Sub

I'm not sure if the WhiteBorderChanger Class needs modified either?

What do I need to do here?

Thank you,

John

"Ken Tucker [MVP]" <HYPERLINK
"mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...

> Hi,
>
> Sorry should have posted some code.
>
> Dim arLabelBorderChanger As New ArrayList
>
> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> AddLabel(Me.Controls)
> End Sub
>
> Private Sub AddLabel(ByVal ctrls As Control.ControlCollection)
> For Each ctrl As Control In ctrls
> If TypeOf ctrl Is Label Then
> DirectCast(ctrl, Label).BorderStyle =
> BorderStyle.FixedSingle
> arLabelBorderChanger.Add(New WhiteBorderChanger(ctrl)) > End If
> AddLabel(ctrl.Controls) ' add a child controls to list
> Next
> End Sub
>
> Ken
> ------------------------------------
>
> "jcrouse" <me> wrote in message
> news:#b**************@TK2MSFTNGP09.phx.gbl:

> > This is ask due to my VB ignorance, sorry. Where should I put the
> > code?
> > Also, if I need an instance for each label, what is the piece the
> > associates
> > an instance with a particular label?
> >
> > Thank you very much,
> > John
> >
> >
> > "Ken Tucker [MVP]" <HYPERLINK
> > "mailto:vb***@bellsouth.net"HYPERLINK
> > "mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message
> > news:e9**************@TK2MSFTNGP10.phx.gbl...
> >

> > > Hi,
> > >
> > > Here is a class that uses nativewindows to change the border to
> > > white.
> > > Create an instance for each label you want to have a white border. > > >
> > >
> > > Public Class WhiteBorderChanger
> > > Inherits NativeWindow
> > >
> > > Declare Function GetWindowDC Lib "user32" Alias
> > > "GetWindowDC"
> > > (ByVal hwnd As IntPtr) _
> > > As IntPtr
> > > Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" > > > (ByVal
> > > hwnd As IntPtr, _
> > > ByVal hdc As IntPtr) As Integer
> > >
> > > Private ctrl As Control
> > >
> > > Public Sub New(ByVal ctrl As Control)
> > >
> > > AssignHandle(ctrl.Handle)
> > > Me.ctrl = ctrl
> > > End Sub
> > >
> > >
> > > Protected Overrides Sub WndProc(ByRef m As Message)
> > > ' Listen for operating system messages
> > >
> > > Const WM_NCPAINT As Integer = &H85
> > >
> > > If m.Msg = WM_NCPAINT Then
> > > Dim hdc As IntPtr = GetWindowDC(m.HWnd)
> > > Dim g As Graphics = Graphics.FromHdc(hdc)
> > >
> > > Dim pXp As Pen = New Pen(Color.White, 3)
> > >
> > > g.DrawRectangle(pXp, 0, 0, ctrl.Width - 1,
> > > ctrl.Height
> > > -
> > > 1)
> > > ReleaseDC(Me.Handle, hdc)
> > > Else
> > > MyBase.WndProc(m)
> > >
> > > End If
> > > End Sub
> > >
> > > Protected Overrides Sub Finalize()
> > > ReleaseHandle()
> > > MyBase.Finalize()
> > > End Sub
> > > End Class
> > >
> > >
> > >
> > > Ken
> > > -------------------
> > >
> > > "jcrouse" <HYPERLINK
> > >

"mailto:jc*****@discussions.microsoft.com"HYPERLIN K

"mailto:jc*****@discussions.microsoft.com"jc*****@ discussions.microsoft.com>


> > > wrote in message
> > > news:F3**********************************@microsof t.com:
> >

> > > > Sorry if this posts twice. I thought I added this a day or two
> > > > ago
> > > > but
> > > > don't see it. I have 30 some controls and would like to change
> > > > the
> >

> > existing
> >

> > > > ones instead of adding new controls. I have LOTS of code to
> > > > consider.
> >

> > Any
> >

> > > > ideas how?
> > > >
> > > > Thank you,
> > > > John
> > > >
> > > > "jcrouse" wrote:
> > > >
> > > >
> >

> > > > > Is there a quick and easy way to change the color of a label
> > > > > controls
> > > > > border
> > > > > from the default black to white?
> > > > >
> > > > > Thank you,
> > > > > John
> > > > >
> > > > >
> > > > >
> > > >
> > >
> >

> > > --
> > > Outgoing mail is certified Virus Free.
> > > Checked by AVG Anti-Virus (http://www.grisoft.com).
> > > Version: 7.0.230 / Virus Database: 263.3.6 - Release Date:
> > > 6/25/2004
> > >
> > >
> >
>

> --
> Outgoing mail is certified Virus Free.
> Checked by AVG Anti-Virus (http://www.grisoft.com).
> Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004
>
>


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004


Nov 20 '05 #27
Hi John,

Did you ever tried it like this?

\\\
Private Sub lblP1JoyUp_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lblP1JoyUp.Click
If bMouseMove = False Then
If bCtrlKey = True Then
If lblP1JoyUp.BorderStyle = BorderStyle.None Xor
BorderStyle.FixedSingle
bLabelSelected = bLabelSelected Xor True
end it
end if
end sub
///

I hope this helps?

Cor
Nov 20 '05 #28
Hi,

For now Cor's solution looks good. I will look into it more.

Ken
------------

"jcrouse" <me> wrote in message
news:eB**************@TK2MSFTNGP12.phx.gbl:
Well Ken. I got them to both display and redisplay (after toggling them
off)
with the white border. i added the following code to the OK button on my

frmAddLabels:

frm1.AddLabel(frm1.Controls)

Pretty straight forward. I am now trying to figure out how keep the white

when I select and deselect them with this code.

Private Sub lblP1JoyUp_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lblP1JoyUp.Click

If bMouseMove = False Then

If bCtrlKey = True Then

If lblP1JoyUp.BorderStyle = BorderStyle.None Then

lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle

bLabelSelected = True

ElseIf lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle Then

lblP1JoyUp.BorderStyle = BorderStyle.None

bLabelSelected = False

End If

End If

End If

End Sub
What do you think?

John

"jcrouse" <me> wrote in message
news:uD**************@TK2MSFTNGP11.phx.gbl...
Ken,
Well that worked great. However (I say that alot), I need to give
you
more of the story. My application is somewhat like the GDI in VB. I show
a
frmMain that has 32 labels on it. The labels are there but hidden
(visible.false). Also, the labels by defaul have NO border (borderstyle
=
borderstyle.none). I then have a second form, frmAddLabels. It lists
the
name of the 32 labels with a checkbox for each label. The user can
toggle
the visible property using the checkboxes. Thats pretty simple.
Howerer,


if
I remove (visible = false) a label the add it again it redisplays with
the
standard black border. Now for the tricky part. I allow the user to
select
the labels with a mouse click event at runtime. They can select
multiple
labels at once using the crtl key. Once the labels are selected they
can
perform the following functions, back color, fole color, size, font
and


the
such. Here's where it may get trick. I set the label to borderstyle =
borderstyle.fixedsingle to let the user see that the label is
selected.


When
the label properties are finished being set the user the unselects the
labels and this turns off the borders. Also, on top of all this, I use
mouse_down, mouse_move and mouse_up event so the user can reposition
the
label on the screen where he needs it.

As for your code the first time I display a label using your code
it


has
a whiter border. This is awesome. But, if I remove (visible = false)
the
border then redisplay it (visible = true) it comes back with a black


border.
Also, when I add the label it automaticall displays with a white
border


and
I would like them to be added with the border set to borderstyle =
borderstyle.none. The user then needs to select them to perform an
action.
When they are then selected they need to display your white border.

The white border is needed because the user is allowed to also add


their
own background image and most images will be of a nature of a darker
color
and the balck borders don't show up well. After I get this working
(with
your help), I will probably add an option to my tools/options menu to


allow
the user to select his own color for the highlighted border but that
will
come later. I think I will just be able to plac the color in a
variable


and
use the variable name in your code in place of "white". I may also want
to
play with the width of the border at some point.

So where do I go from here?

Thank you,
John
"Ken Tucker [MVP]" <HYPERLINK
"mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message
news:eY**************@TK2MSFTNGP11.phx.gbl...

Hi,

Sure you do. All controls are added to the forms control
collection.
The code I posted will loop through all the controls on the form and
if
the control is a label it will add a new whiteborderchanger to the
Arraylist. It also changes the border to a fixed single to make sure
the
white border will draw.
Ken
-------------

"jcrouse" <me> wrote in message
news:uo**************@tk2msftngp13.phx.gbl: Ken,
> Well, this is embarassing, but here goes. Unfortunately I do NOT
> have
my

> controls in an array. I may move them to one later but for now
> they
are
not.
> It has really made the coding much more difficult than it should
> have
> been.
> Right now I am learning the code and shooting for functionality. I
will
clean things up later. Anyways, when my form loads the labels are
already

on
> the form. I am trying to modify your code to work with this
arrangement.

> Here's what I have so far. We are working with a label named
lblP1JoyUp.

>
> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> DirectCast(lblP1JoyUp, Label).BorderStyle =
> BorderStyle.FixedSingle
> arLabelBorderChanger.Add(New WhiteBorderChanger(ctrl))
> End Sub
>
>
>
> I'm not sure if the WhiteBorderChanger Class needs modified
> either?
>
>
>
> What do I need to do here?
>
>
>
> Thank you,
>
> John
>
>
>
> "Ken Tucker [MVP]" <HYPERLINK
> "mailto:vb***@bellsouth.net"HYPERLINK
> "mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message
> news:%2******************@TK2MSFTNGP09.phx.gbl...
> > Hi,
> >
> > Sorry should have posted some code.
> >
> > Dim arLabelBorderChanger As New ArrayList
> >
> > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e
> > As
> > System.EventArgs) Handles MyBase.Load
> > AddLabel(Me.Controls)
> > End Sub
> >
> > Private Sub AddLabel(ByVal ctrls As
> > Control.ControlCollection)
> > For Each ctrl As Control In ctrls
> > If TypeOf ctrl Is Label Then
> > DirectCast(ctrl, Label).BorderStyle =
> > BorderStyle.FixedSingle
> > arLabelBorderChanger.Add(New
WhiteBorderChanger(ctrl))
> End If
> > AddLabel(ctrl.Controls) ' add a child controls to
> > list
> > Next
> > End Sub
> >
> > Ken
> > ------------------------------------
> >
> > "jcrouse" <me> wrote in message
> > news:#b**************@TK2MSFTNGP09.phx.gbl:
> > > This is ask due to my VB ignorance, sorry. Where should I put
> > > the
> > > code?
> > > Also, if I need an instance for each label, what is the piece
> > > the
> > > associates
> > > an instance with a particular label?
> > >
> > > Thank you very much,
> > > John
> > >
> > >
> > > "Ken Tucker [MVP]" <HYPERLINK
> > > "mailto:vb***@bellsouth.net"HYPERLINK
> > > "mailto:vb***@bellsouth.net"HYPERLINK
> > > "mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message
> > > news:e9**************@TK2MSFTNGP10.phx.gbl...
> > >
> > > > Hi,
> > > >
> > > > Here is a class that uses nativewindows to change the border
> > > > to
> > > > white.
> > > > Create an instance for each label you want to have a white
border.
> > >
> > > >
> > > > Public Class WhiteBorderChanger
> > > > Inherits NativeWindow
> > > >
> > > > Declare Function GetWindowDC Lib "user32" Alias
> > > > "GetWindowDC"
> > > > (ByVal hwnd As IntPtr) _
> > > > As IntPtr
> > > > Declare Function ReleaseDC Lib "user32" Alias
"ReleaseDC"
> > > (ByVal
> > > > hwnd As IntPtr, _
> > > > ByVal hdc As IntPtr) As Integer
> > > >
> > > > Private ctrl As Control
> > > >
> > > > Public Sub New(ByVal ctrl As Control)
> > > >
> > > > AssignHandle(ctrl.Handle)
> > > > Me.ctrl = ctrl
> > > > End Sub
> > > >
> > > >
> > > > Protected Overrides Sub WndProc(ByRef m As Message)
> > > > ' Listen for operating system messages
> > > >
> > > > Const WM_NCPAINT As Integer = &H85
> > > >
> > > > If m.Msg = WM_NCPAINT Then
> > > > Dim hdc As IntPtr = GetWindowDC(m.HWnd)
> > > > Dim g As Graphics = Graphics.FromHdc(hdc)
> > > >
> > > > Dim pXp As Pen = New Pen(Color.White, 3)
> > > >
> > > > g.DrawRectangle(pXp, 0, 0, ctrl.Width - 1,
> > > > ctrl.Height
> > > > -
> > > > 1)
> > > > ReleaseDC(Me.Handle, hdc)
> > > > Else
> > > > MyBase.WndProc(m)
> > > >
> > > > End If
> > > > End Sub
> > > >
> > > > Protected Overrides Sub Finalize()
> > > > ReleaseHandle()
> > > > MyBase.Finalize()
> > > > End Sub
> > > > End Class
> > > >
> > > >
> > > >
> > > > Ken
> > > > -------------------
> > > >
> > > > "jcrouse" <HYPERLINK
> > > >
> "mailto:jc*****@discussions.microsoft.com"HYPERLIN K
>


"mailto:jc*****@discussions.microsoft.com"HYPERLIN K
"mailto:jc*****@discussions.microsoft.com"jc*****@ discussions.microsoft.com>
> > > > wrote in message
> > > > news:F3**********************************@microsof t.com:
> > >
> > > > > Sorry if this posts twice. I thought I added this a day or
> > > > > two
> > > > > ago
> > > > > but
> > > > > don't see it. I have 30 some controls and would like to
> > > > > change
> > > > > the
> > >
> > > existing
> > >
> > > > > ones instead of adding new controls. I have LOTS of code
> > > > > to
> > > > > consider.
> > >
> > > Any
> > >
> > > > > ideas how?
> > > > >
> > > > > Thank you,
> > > > > John
> > > > >
> > > > > "jcrouse" wrote:
> > > > >
> > > > >
> > >
> > > > > > Is there a quick and easy way to change the color of a
> > > > > > label
> > > > > > controls
> > > > > > border
> > > > > > from the default black to white?
> > > > > >
> > > > > > Thank you,
> > > > > > John
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> > > > --
> > > > Outgoing mail is certified Virus Free.
> > > > Checked by AVG Anti-Virus (http://www.grisoft.com).
> > > > Version: 7.0.230 / Virus Database: 263.3.6 - Release Date:
> > > > 6/25/2004
> > > >
> > > >
> > >
> >
> > --
> > Outgoing mail is certified Virus Free.
> > Checked by AVG Anti-Virus (http://www.grisoft.com).
> > Version: 7.0.230 / Virus Database: 263.3.6 - Release Date:
> > 6/25/2004
> >
> >
>
--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004



--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.9 - Release Date: 7/2/2004
Nov 20 '05 #29
I seem to have gotten it by calling the sub in a few places and then
refreshing the form.

Thanks Ken,
John

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:eu**************@TK2MSFTNGP10.phx.gbl...
Hi,

For now Cor's solution looks good. I will look into it more.

Ken
------------

"jcrouse" <me> wrote in message
news:eB**************@TK2MSFTNGP12.phx.gbl:
Well Ken. I got them to both display and redisplay (after toggling them
off)
with the white border. i added the following code to the OK button on my

frmAddLabels:

frm1.AddLabel(frm1.Controls)

Pretty straight forward. I am now trying to figure out how keep the white
when I select and deselect them with this code.

Private Sub lblP1JoyUp_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lblP1JoyUp.Click

If bMouseMove = False Then

If bCtrlKey = True Then

If lblP1JoyUp.BorderStyle = BorderStyle.None Then

lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle

bLabelSelected = True

ElseIf lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle Then

lblP1JoyUp.BorderStyle = BorderStyle.None

bLabelSelected = False

End If

End If

End If

End Sub
What do you think?

John

"jcrouse" <me> wrote in message
news:uD**************@TK2MSFTNGP11.phx.gbl...
Ken,
Well that worked great. However (I say that alot), I need to give
you
more of the story. My application is somewhat like the GDI in VB. I show a
frmMain that has 32 labels on it. The labels are there but hidden
(visible.false). Also, the labels by defaul have NO border (borderstyle =
borderstyle.none). I then have a second form, frmAddLabels. It lists
the
name of the 32 labels with a checkbox for each label. The user can
toggle
the visible property using the checkboxes. Thats pretty simple.
Howerer,


if
I remove (visible = false) a label the add it again it redisplays with
the
standard black border. Now for the tricky part. I allow the user to
select
the labels with a mouse click event at runtime. They can select
multiple
labels at once using the crtl key. Once the labels are selected they
can
perform the following functions, back color, fole color, size, font
and


the
such. Here's where it may get trick. I set the label to borderstyle =
borderstyle.fixedsingle to let the user see that the label is
selected.


When
the label properties are finished being set the user the unselects the
labels and this turns off the borders. Also, on top of all this, I use
mouse_down, mouse_move and mouse_up event so the user can reposition
the
label on the screen where he needs it.

As for your code the first time I display a label using your code
it


has
a whiter border. This is awesome. But, if I remove (visible = false)
the
border then redisplay it (visible = true) it comes back with a black


border.
Also, when I add the label it automaticall displays with a white
border


and
I would like them to be added with the border set to borderstyle =
borderstyle.none. The user then needs to select them to perform an
action.
When they are then selected they need to display your white border.

The white border is needed because the user is allowed to also add


their
own background image and most images will be of a nature of a darker
color
and the balck borders don't show up well. After I get this working
(with
your help), I will probably add an option to my tools/options menu to


allow
the user to select his own color for the highlighted border but that
will
come later. I think I will just be able to plac the color in a
variable


and
use the variable name in your code in place of "white". I may also want to
play with the width of the border at some point.

So where do I go from here?

Thank you,
John
"Ken Tucker [MVP]" <HYPERLINK
"mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message
news:eY**************@TK2MSFTNGP11.phx.gbl...

> Hi,
>
> Sure you do. All controls are added to the forms control
> collection.
> The code I posted will loop through all the controls on the form and
> if
> the control is a label it will add a new whiteborderchanger to the
> Arraylist. It also changes the border to a fixed single to make sure
> the
> white border will draw.
>
>
> Ken
> -------------
>
> "jcrouse" <me> wrote in message
> news:uo**************@tk2msftngp13.phx.gbl:

> > Ken,
> > Well, this is embarassing, but here goes. Unfortunately I do NOT
> > have


my
> >
> > controls in an array. I may move them to one later but for now
> > they


are
> > not.
> > It has really made the coding much more difficult than it should
> > have
> > been.
> > Right now I am learning the code and shooting for functionality. I


will
> > clean things up later. Anyways, when my form loads the labels are

already

> > on
> > the form. I am trying to modify your code to work with this


arrangement.
> >
> > Here's what I have so far. We are working with a label named


lblP1JoyUp.
> >
> >
> > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles MyBase.Load
> > DirectCast(lblP1JoyUp, Label).BorderStyle =
> > BorderStyle.FixedSingle
> > arLabelBorderChanger.Add(New WhiteBorderChanger(ctrl))
> > End Sub
> >
> >
> >
> > I'm not sure if the WhiteBorderChanger Class needs modified
> > either?
> >
> >
> >
> > What do I need to do here?
> >
> >
> >
> > Thank you,
> >
> > John
> >
> >
> >
> > "Ken Tucker [MVP]" <HYPERLINK
> > "mailto:vb***@bellsouth.net"HYPERLINK
> > "mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message
> > news:%2******************@TK2MSFTNGP09.phx.gbl...
> >

> > > Hi,
> > >
> > > Sorry should have posted some code.
> > >
> > > Dim arLabelBorderChanger As New ArrayList
> > >
> > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e > > > As
> > > System.EventArgs) Handles MyBase.Load
> > > AddLabel(Me.Controls)
> > > End Sub
> > >
> > > Private Sub AddLabel(ByVal ctrls As
> > > Control.ControlCollection)
> > > For Each ctrl As Control In ctrls
> > > If TypeOf ctrl Is Label Then
> > > DirectCast(ctrl, Label).BorderStyle =
> > > BorderStyle.FixedSingle
> > > arLabelBorderChanger.Add(New


WhiteBorderChanger(ctrl))
> > > End If
> > > AddLabel(ctrl.Controls) ' add a child controls to
> > > list
> > > Next
> > > End Sub
> > >
> > > Ken
> > > ------------------------------------
> > >
> > > "jcrouse" <me> wrote in message
> > > news:#b**************@TK2MSFTNGP09.phx.gbl:
> >

> > > > This is ask due to my VB ignorance, sorry. Where should I put
> > > > the
> > > > code?
> > > > Also, if I need an instance for each label, what is the piece
> > > > the
> > > > associates
> > > > an instance with a particular label?
> > > >
> > > > Thank you very much,
> > > > John
> > > >
> > > >
> > > > "Ken Tucker [MVP]" <HYPERLINK
> > > > "mailto:vb***@bellsouth.net"HYPERLINK
> > > > "mailto:vb***@bellsouth.net"HYPERLINK
> > > > "mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message > > > > news:e9**************@TK2MSFTNGP10.phx.gbl...
> > > >
> >

> > > > > Hi,
> > > > >
> > > > > Here is a class that uses nativewindows to change the border
> > > > > to
> > > > > white.
> > > > > Create an instance for each label you want to have a white


border.
> > > > >
> > > > >
> > > > > Public Class WhiteBorderChanger
> > > > > Inherits NativeWindow
> > > > >
> > > > > Declare Function GetWindowDC Lib "user32" Alias
> > > > > "GetWindowDC"
> > > > > (ByVal hwnd As IntPtr) _
> > > > > As IntPtr
> > > > > Declare Function ReleaseDC Lib "user32" Alias


"ReleaseDC"
> > > > > (ByVal
> > > > > hwnd As IntPtr, _
> > > > > ByVal hdc As IntPtr) As Integer
> > > > >
> > > > > Private ctrl As Control
> > > > >
> > > > > Public Sub New(ByVal ctrl As Control)
> > > > >
> > > > > AssignHandle(ctrl.Handle)
> > > > > Me.ctrl = ctrl
> > > > > End Sub
> > > > >
> > > > >
> > > > > Protected Overrides Sub WndProc(ByRef m As Message)
> > > > > ' Listen for operating system messages
> > > > >
> > > > > Const WM_NCPAINT As Integer = &H85
> > > > >
> > > > > If m.Msg = WM_NCPAINT Then
> > > > > Dim hdc As IntPtr = GetWindowDC(m.HWnd)
> > > > > Dim g As Graphics = Graphics.FromHdc(hdc)
> > > > >
> > > > > Dim pXp As Pen = New Pen(Color.White, 3)
> > > > >
> > > > > g.DrawRectangle(pXp, 0, 0, ctrl.Width - 1,
> > > > > ctrl.Height
> > > > > -
> > > > > 1)
> > > > > ReleaseDC(Me.Handle, hdc)
> > > > > Else
> > > > > MyBase.WndProc(m)
> > > > >
> > > > > End If
> > > > > End Sub
> > > > >
> > > > > Protected Overrides Sub Finalize()
> > > > > ReleaseHandle()
> > > > > MyBase.Finalize()
> > > > > End Sub
> > > > > End Class
> > > > >
> > > > >
> > > > >
> > > > > Ken
> > > > > -------------------
> > > > >
> > > > > "jcrouse" <HYPERLINK
> > > > >
> >

> > "mailto:jc*****@discussions.microsoft.com"HYPERLIN K
> >



"mailto:jc*****@discussions.microsoft.com"HYPERLIN K
"mailto:jc*****@discussions.microsoft.com"jc*****@ discussions.microsoft.com>
> >
> >

> > > > > wrote in message
> > > > > news:F3**********************************@microsof t.com:
> > > >
> >

> > > > > > Sorry if this posts twice. I thought I added this a day or
> > > > > > two
> > > > > > ago
> > > > > > but
> > > > > > don't see it. I have 30 some controls and would like to
> > > > > > change
> > > > > > the
> > > >
> >

> > > > existing
> > > >
> >

> > > > > > ones instead of adding new controls. I have LOTS of code
> > > > > > to
> > > > > > consider.
> > > >
> >

> > > > Any
> > > >
> >

> > > > > > ideas how?
> > > > > >
> > > > > > Thank you,
> > > > > > John
> > > > > >
> > > > > > "jcrouse" wrote:
> > > > > >
> > > > > >
> > > >
> >

> > > > > > > Is there a quick and easy way to change the color of a
> > > > > > > label
> > > > > > > controls
> > > > > > > border
> > > > > > > from the default black to white?
> > > > > > >
> > > > > > > Thank you,
> > > > > > > John
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> >

> > > > > --
> > > > > Outgoing mail is certified Virus Free.
> > > > > Checked by AVG Anti-Virus (http://www.grisoft.com).
> > > > > Version: 7.0.230 / Virus Database: 263.3.6 - Release Date:
> > > > > 6/25/2004
> > > > >
> > > > >
> > > >
> > >
> >

> > > --
> > > Outgoing mail is certified Virus Free.
> > > Checked by AVG Anti-Virus (http://www.grisoft.com).
> > > Version: 7.0.230 / Virus Database: 263.3.6 - Release Date:
> > > 6/25/2004
> > >
> > >
> >
>

> --
> Outgoing mail is certified Virus Free.
> Checked by AVG Anti-Virus (http://www.grisoft.com).
> Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004
>
>



--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.9 - Release Date: 7/2/2004

Nov 20 '05 #30
Last question (on this issue). Why can't I seem to make the width of the
highlighted line a little thicker. I believe the label may be covering up
some of the line but I'm not sure. I've tried changing the numbers and
nothing happens.

John

"jcrouse" <me> wrote in message
news:e0**************@tk2msftngp13.phx.gbl...
I seem to have gotten it by calling the sub in a few places and then
refreshing the form.

Thanks Ken,
John

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:eu**************@TK2MSFTNGP10.phx.gbl...
Hi,

For now Cor's solution looks good. I will look into it more.

Ken
------------

"jcrouse" <me> wrote in message
news:eB**************@TK2MSFTNGP12.phx.gbl:
Well Ken. I got them to both display and redisplay (after toggling them off)
with the white border. i added the following code to the OK button on my
frmAddLabels:

frm1.AddLabel(frm1.Controls)

Pretty straight forward. I am now trying to figure out how keep the white
when I select and deselect them with this code.

Private Sub lblP1JoyUp_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lblP1JoyUp.Click

If bMouseMove = False Then

If bCtrlKey = True Then

If lblP1JoyUp.BorderStyle = BorderStyle.None Then

lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle

bLabelSelected = True

ElseIf lblP1JoyUp.BorderStyle = BorderStyle.FixedSingle Then

lblP1JoyUp.BorderStyle = BorderStyle.None

bLabelSelected = False

End If

End If

End If

End Sub
What do you think?

John

"jcrouse" <me> wrote in message
news:uD**************@TK2MSFTNGP11.phx.gbl...

> Ken,
> Well that worked great. However (I say that alot), I need to give > you
> more of the story. My application is somewhat like the GDI in VB. I show > a
> frmMain that has 32 labels on it. The labels are there but hidden
> (visible.false). Also, the labels by defaul have NO border (borderstyle > =
> borderstyle.none). I then have a second form, frmAddLabels. It lists
> the
> name of the 32 labels with a checkbox for each label. The user can
> toggle
> the visible property using the checkboxes. Thats pretty simple.
> Howerer,

if

> I remove (visible = false) a label the add it again it redisplays with > the
> standard black border. Now for the tricky part. I allow the user to
> select
> the labels with a mouse click event at runtime. They can select
> multiple
> labels at once using the crtl key. Once the labels are selected they
> can
> perform the following functions, back color, fole color, size, font
> and

the

> such. Here's where it may get trick. I set the label to borderstyle = > borderstyle.fixedsingle to let the user see that the label is
> selected.

When

> the label properties are finished being set the user the unselects the > labels and this turns off the borders. Also, on top of all this, I use > mouse_down, mouse_move and mouse_up event so the user can reposition
> the
> label on the screen where he needs it.
>
> As for your code the first time I display a label using your code > it

has

> a whiter border. This is awesome. But, if I remove (visible = false)
> the
> border then redisplay it (visible = true) it comes back with a black

border.

> Also, when I add the label it automaticall displays with a white
> border

and

> I would like them to be added with the border set to borderstyle =
> borderstyle.none. The user then needs to select them to perform an
> action.
> When they are then selected they need to display your white border.
>
> The white border is needed because the user is allowed to also add
their

> own background image and most images will be of a nature of a darker
> color
> and the balck borders don't show up well. After I get this working
> (with
> your help), I will probably add an option to my tools/options menu to
allow

> the user to select his own color for the highlighted border but that
> will
> come later. I think I will just be able to plac the color in a
> variable

and

> use the variable name in your code in place of "white". I may also want > to
> play with the width of the border at some point.
>
> So where do I go from here?
>
> Thank you,
> John
>
>
> "Ken Tucker [MVP]" <HYPERLINK
> "mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message
> news:eY**************@TK2MSFTNGP11.phx.gbl...

> > Hi,
> >
> > Sure you do. All controls are added to the forms control
> > collection.
> > The code I posted will loop through all the controls on the form and > > if
> > the control is a label it will add a new whiteborderchanger to the
> > Arraylist. It also changes the border to a fixed single to make sure > > the
> > white border will draw.
> >
> >
> > Ken
> > -------------
> >
> > "jcrouse" <me> wrote in message
> > news:uo**************@tk2msftngp13.phx.gbl:

> > > Ken,
> > > Well, this is embarassing, but here goes. Unfortunately I do NOT
> > > have

my

> > >
> > > controls in an array. I may move them to one later but for now
> > > they

are

> > > not.
> > > It has really made the coding much more difficult than it should
> > > have
> > > been.
> > > Right now I am learning the code and shooting for functionality. I
will

> > > clean things up later. Anyways, when my form loads the labels are
> already

> > > on
> > > the form. I am trying to modify your code to work with this

arrangement.

> > >
> > > Here's what I have so far. We are working with a label named

lblP1JoyUp.

> > >
> > >
> > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> > > System.EventArgs) Handles MyBase.Load
> > > DirectCast(lblP1JoyUp, Label).BorderStyle =
> > > BorderStyle.FixedSingle
> > > arLabelBorderChanger.Add(New WhiteBorderChanger(ctrl))
> > > End Sub
> > >
> > >
> > >
> > > I'm not sure if the WhiteBorderChanger Class needs modified
> > > either?
> > >
> > >
> > >
> > > What do I need to do here?
> > >
> > >
> > >
> > > Thank you,
> > >
> > > John
> > >
> > >
> > >
> > > "Ken Tucker [MVP]" <HYPERLINK
> > > "mailto:vb***@bellsouth.net"HYPERLINK
> > > "mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in message > > > news:%2******************@TK2MSFTNGP09.phx.gbl...
> > >

> > > > Hi,
> > > >
> > > > Sorry should have posted some code.
> > > >
> > > > Dim arLabelBorderChanger As New ArrayList
> > > >
> > > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal
e
> > > > As
> > > > System.EventArgs) Handles MyBase.Load
> > > > AddLabel(Me.Controls)
> > > > End Sub
> > > >
> > > > Private Sub AddLabel(ByVal ctrls As
> > > > Control.ControlCollection)
> > > > For Each ctrl As Control In ctrls
> > > > If TypeOf ctrl Is Label Then
> > > > DirectCast(ctrl, Label).BorderStyle =
> > > > BorderStyle.FixedSingle
> > > > arLabelBorderChanger.Add(New

WhiteBorderChanger(ctrl))

> > > > End If
> > > > AddLabel(ctrl.Controls) ' add a child controls
to > > > > list
> > > > Next
> > > > End Sub
> > > >
> > > > Ken
> > > > ------------------------------------
> > > >
> > > > "jcrouse" <me> wrote in message
> > > > news:#b**************@TK2MSFTNGP09.phx.gbl:
> > >

> > > > > This is ask due to my VB ignorance, sorry. Where should I put > > > > > the
> > > > > code?
> > > > > Also, if I need an instance for each label, what is the piece > > > > > the
> > > > > associates
> > > > > an instance with a particular label?
> > > > >
> > > > > Thank you very much,
> > > > > John
> > > > >
> > > > >
> > > > > "Ken Tucker [MVP]" <HYPERLINK
> > > > > "mailto:vb***@bellsouth.net"HYPERLINK
> > > > > "mailto:vb***@bellsouth.net"HYPERLINK
> > > > > "mailto:vb***@bellsouth.net"vb***@bellsouth.ne t> wrote in

message > > > > > news:e9**************@TK2MSFTNGP10.phx.gbl...
> > > > >
> > >

> > > > > > Hi,
> > > > > >
> > > > > > Here is a class that uses nativewindows to change the border > > > > > > to
> > > > > > white.
> > > > > > Create an instance for each label you want to have a white

border.

> > > > > >
> > > > > >
> > > > > > Public Class WhiteBorderChanger
> > > > > > Inherits NativeWindow
> > > > > >
> > > > > > Declare Function GetWindowDC Lib "user32" Alias
> > > > > > "GetWindowDC"
> > > > > > (ByVal hwnd As IntPtr) _
> > > > > > As IntPtr
> > > > > > Declare Function ReleaseDC Lib "user32" Alias

"ReleaseDC"

> > > > > > (ByVal
> > > > > > hwnd As IntPtr, _
> > > > > > ByVal hdc As IntPtr) As Integer
> > > > > >
> > > > > > Private ctrl As Control
> > > > > >
> > > > > > Public Sub New(ByVal ctrl As Control)
> > > > > >
> > > > > > AssignHandle(ctrl.Handle)
> > > > > > Me.ctrl = ctrl
> > > > > > End Sub
> > > > > >
> > > > > >
> > > > > > Protected Overrides Sub WndProc(ByRef m As Message) > > > > > > ' Listen for operating system messages
> > > > > >
> > > > > > Const WM_NCPAINT As Integer = &H85
> > > > > >
> > > > > > If m.Msg = WM_NCPAINT Then
> > > > > > Dim hdc As IntPtr = GetWindowDC(m.HWnd)
> > > > > > Dim g As Graphics = Graphics.FromHdc(hdc)
> > > > > >
> > > > > > Dim pXp As Pen = New Pen(Color.White, 3)
> > > > > >
> > > > > > g.DrawRectangle(pXp, 0, 0, ctrl.Width - 1,
> > > > > > ctrl.Height
> > > > > > -
> > > > > > 1)
> > > > > > ReleaseDC(Me.Handle, hdc)
> > > > > > Else
> > > > > > MyBase.WndProc(m)
> > > > > >
> > > > > > End If
> > > > > > End Sub
> > > > > >
> > > > > > Protected Overrides Sub Finalize()
> > > > > > ReleaseHandle()
> > > > > > MyBase.Finalize()
> > > > > > End Sub
> > > > > > End Class
> > > > > >
> > > > > >
> > > > > >
> > > > > > Ken
> > > > > > -------------------
> > > > > >
> > > > > > "jcrouse" <HYPERLINK
> > > > > >
> > >

> > > "mailto:jc*****@discussions.microsoft.com"HYPERLIN K
> > >

>

"mailto:jc*****@discussions.microsoft.com"HYPERLIN K

"mailto:jc*****@discussions.microsoft.com"jc*****@ discussions.microsoft.com>


> > >
> > >

> > > > > > wrote in message
> > > > > > news:F3**********************************@microsof t.com:
> > > > >
> > >

> > > > > > > Sorry if this posts twice. I thought I added this a day or > > > > > > > two
> > > > > > > ago
> > > > > > > but
> > > > > > > don't see it. I have 30 some controls and would like to
> > > > > > > change
> > > > > > > the
> > > > >
> > >

> > > > > existing
> > > > >
> > >

> > > > > > > ones instead of adding new controls. I have LOTS of code
> > > > > > > to
> > > > > > > consider.
> > > > >
> > >

> > > > > Any
> > > > >
> > >

> > > > > > > ideas how?
> > > > > > >
> > > > > > > Thank you,
> > > > > > > John
> > > > > > >
> > > > > > > "jcrouse" wrote:
> > > > > > >
> > > > > > >
> > > > >
> > >

> > > > > > > > Is there a quick and easy way to change the color of a
> > > > > > > > label
> > > > > > > > controls
> > > > > > > > border
> > > > > > > > from the default black to white?
> > > > > > > >
> > > > > > > > Thank you,
> > > > > > > > John
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > >

> > > > > > --
> > > > > > Outgoing mail is certified Virus Free.
> > > > > > Checked by AVG Anti-Virus (http://www.grisoft.com).
> > > > > > Version: 7.0.230 / Virus Database: 263.3.6 - Release Date:
> > > > > > 6/25/2004
> > > > > >
> > > > > >
> > > > >
> > > >
> > >

> > > > --
> > > > Outgoing mail is certified Virus Free.
> > > > Checked by AVG Anti-Virus (http://www.grisoft.com).
> > > > Version: 7.0.230 / Virus Database: 263.3.6 - Release Date:
> > > > 6/25/2004
> > > >
> > > >
> > >
> >

> > --
> > Outgoing mail is certified Virus Free.
> > Checked by AVG Anti-Virus (http://www.grisoft.com).
> > Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004 > >
> >
>

>


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.9 - Release Date: 7/2/2004


Nov 20 '05 #31
Hi,

When you are drawing a border only a small amount of the control is
invalidated. Unfortunately you can only draw in the invalidated
sections. Any code to draw outside the invalidated region is ignored.
Add code to draw more in the controls paint event.

Public Class WhiteBorderChanger
Inherits NativeWindow

Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC" (ByVal
hwnd As IntPtr) _
As IntPtr
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal
hwnd As IntPtr, _
ByVal hdc As IntPtr) As Integer

Private WithEvents ctrl As Control

Public Sub New(ByVal ctrl As Control)

AssignHandle(ctrl.Handle)
Me.ctrl = ctrl
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
' Listen for operating system messages

Const WM_NCPAINT As Integer = &H85

If m.Msg = WM_NCPAINT Then
Dim hdc As IntPtr = GetWindowDC(m.HWnd)
Dim g As Graphics = Graphics.FromHdc(hdc)

Dim pXp As Pen = New Pen(Color.White, 19)
Dim rDraw As Rectangle = ctrl.ClientRectangle

g.DrawRectangle(pXp, rDraw)

g.DrawRectangle(pXp, rDraw)
ReleaseDC(Me.Handle, hdc)
Else
MyBase.WndProc(m)

End If
End Sub

Protected Overrides Sub Finalize()
ReleaseHandle()
MyBase.Finalize()
End Sub

Private Sub ctrl_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles ctrl.Paint
Dim pDraw As New Pen(Color.White, 5)
e.Graphics.DrawRectangle(pDraw, ctrl.ClientRectangle)
End Sub
End Class
Ken

---------------------

"jcrouse" <me> wrote in message
news:Oi*************@tk2msftngp13.phx.gbl:
Last question (on this issue). Why can't I seem to make the width of the

highlighted line a little thicker. I believe the label may be covering up

some of the line but I'm not sure. I've tried changing the numbers and
nothing happens.

John

"jcrouse" <me> wrote in message
news:e0**************@tk2msftngp13.phx.gbl...
I seem to have gotten it by calling the sub in a few places and then
refreshing the form.

Thanks Ken,
John

--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.9 - Release Date: 7/2/2004
Nov 20 '05 #32

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Stuart Norris | last post: by
3 posts views Thread by Dude | last post: by
2 posts views Thread by John Holmes | last post: by
1 post views Thread by Jameel | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.