标签控制边框颜色 [英] Label control border color

查看:55
本文介绍了标签控制边框颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种快速简便的方法可以更改标签控件边框的颜色

从默认的黑色到白色?


谢谢,

John

解决方案




如果你想改变边框颜色你必须覆盖

WM_NCPAINT消息。

公共类BorderLabel

继承标签


声明函数GetWindowDC Lib" user32"别名GetWindowDC (ByVal

hwnd As IntPtr)_

As IntPtr

声明函数ReleaseDC Lib" user32"别名ReleaseDC (ByVal

hwnd As IntPtr,_

ByVal hdc As IntPtr)作为整数

受保护的覆盖子WndProc(ByRef m As

System.Windows.Forms.Message)

Const WM_NCPAINT =& H85


如果m.Msg = WM_NCPAINT那么

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)


结束如果


结束子


受保护覆盖​​Sub Finalize()

MyBase.Finalize()

End Sub


Public Sub New()

Me.BorderStyle = BorderStyle.FixedSingle

结束次级

结束班级




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


" jcrouse" < ME>在消息中写道

新闻:eC ************* @ TK2MSFTNGP10.phx.gbl:

有没有快速简便的方法更改标签控件的颜色
边框从默认的黑色到白色?

谢谢,
John



-

外发邮件经过无病毒认证。

由AVG Anti-Virus检查( http://www.grisoft.com)

版本:7.0.230 /病毒库:263.3.6 - 发布日期:2004年6月25日


* 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)




别忘了在那里处理笔''penBorder'。


-

Herfried K. Wagner [MVP]

< URL:http://dotnet.mvps.org/>


Ken,

如何处理此代码或需要执行哪些操作。我创建了一个新的

项目,并在表单中添加了一个标签。以下是整个代码:


公共类Form1

继承System.Windows.Forms.Form


#地区 Windows窗体设计器生成的代码


Public Sub New()


MyBase.New()


''Windows窗体设计器需要此调用。

InitializeComponent()


''在InitializeComponent之后添加任何初始化()致电


结束子


''表格覆盖处理以清理组件列表。


受保护的重载覆盖子处理(ByVal处理为布尔值)


如果处置则


如果不是(组件无效)则


components.Dispose()


结束如果


结束如果


MyBase.Dispose(处理)


结束子


''Windows窗体设计师要求


私有组件As System.ComponentModel.IContainer


''注意:Windows窗体设计器需要以下步骤


''可以使用Windows窗体设计器修改它。


''不要使用代码编辑器修改它。


Friend WithEvents Label1 As System.Windows.Forms.Label


< System.Diagnostics.DebuggerStepThrough()> Private Sub

InitializeComponent()


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


Me .SpendpendLayout()


''


''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"
< br $>
''


''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 Region

我最后加了它但什么也没得到。我是否需要以某种方式调用某些内容

或使用上述代码混合代码?


谢谢,

John


" Ken Tucker [MVP]" < VB *** @ bellsouth.net>在留言中写道

新闻:uv ************* @ TK2MSFTNGP11.phx.gbl ...



如果你想改变边框颜色你必须覆盖
WM_NCPAINT消息。

公共类BorderLabel
继承标签

声明函数GetWindowDC Lib" user32"别名GetWindowDC (ByVal
hwnd As IntPtr)_
作为IntPtr
声明函数ReleaseDC Lib" user32"别名ReleaseDC (ByVal
hwnd作为IntPtr,_
ByVal hdc作为IntPtr)作为整数

受保护的覆盖子WndProc(ByRef m As
System.Windows.Forms.Message)
Const WM_NCPAINT =& H85

如果m.Msg = WM_NCPAINT那么
Dim penBorder作为新笔(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)< br.>
g.DrawRectangle(penBorder,rDraw)

ReleaseDC(Me.Handle,hdc)
其他
MyBase.WndProc(m)

结束如果

结束子

受保护的覆盖子终结()
MyBase.Finalize()
结束子

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

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

" jcrouse" < ME>在消息中写道
新闻:eC ************* @ TK2MSFTNGP10.phx.gbl:

有没有一种快速简便的方法来改变颜色一个标签控制边框
从默认的黑色到白色?

谢谢你,
John



- <发送邮件经过无病毒认证。
由AVG Anti-Virus检查( http: //www.grisoft.com)
版本:7.0.230 /病毒库:263.3.6 - 发布日期:2004年6月25日



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

解决方案

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


* 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/>


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



这篇关于标签控制边框颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆