View Full Version : سوال: عوض كردن رنگ Border يك كنترل
مهدی فرزاد
دوشنبه 24 تیر 1387, 12:42 عصر
باسلام
چطوري ميشه رنگ Border يك كنترل مثلا Textbox رو عوض كرد ؟(در VB.Net 2005)
پيشاپيش از راهنمايي شما سپاس گذارم
morteza_261
دوشنبه 24 تیر 1387, 13:37 عصر
سلام
در پست شماره 103 در http://barnamenevis.org/forum/showthread.php?t=58718&page=11
برای Textbox یه کد هست
مهدی فرزاد
دوشنبه 24 تیر 1387, 20:14 عصر
سلام دوست عزيز
اين كدها رو بايد كجا و چه جوري استفاده كنم؟؟
parsavb
سه شنبه 25 تیر 1387, 11:48 صبح
از این کد ها می تونی استفاده کنی
Button1.FlatAppearance.BorderColor = Color.GreenYellow
Button1.FlatAppearance.MouseDownBackColor = Color.Blue
مهدی فرزاد
سه شنبه 25 تیر 1387, 12:54 عصر
اين كد ها فقط در مورد Button جواب ميده. كدي مخوام كه براي TextBox و GroupBox جواب بده
Dariuosh
سه شنبه 25 تیر 1387, 14:34 عصر
Imports System.Runtime.InteropServices
Public Class MyTextBox
Inherits Windows.Forms.TextBox
Private _Color As Color
Private Shared WM_NCPAINT As Integer = &H85
Private Shared WM_ERASEBKGND As Integer = &H14
Private Shared WM_PAINT As Integer = &HF
Public Property BorderColor() As Color
Get
Return _Color
End Get
Set(ByVal value As Color)
_Color = value
End Set
End Property
<DllImport("user32.dll")> _
Shared Function GetDCEx(ByVal hwnd As IntPtr, ByVal hrgnclip As IntPtr, ByVal fdwOptions As UInt32) As IntPtr
End Function
<DllImport("user32.dll")> _
Shared Function ReleaseDC(ByVal hwnd As IntPtr, ByVal hDC As IntPtr) As Integer
End Function
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
If m.Msg = WM_NCPAINT Or m.Msg = WM_ERASEBKGND Or m.Msg = WM_PAINT Then
Dim hdc As IntPtr = GetDCEx(m.HWnd, CType(1, IntPtr), 1 Or &H20)
If (hdc <> IntPtr.Zero) Then
Dim graphics As Graphics = graphics.FromHdc(hdc)
Dim rectangle As Rectangle = New Rectangle(0, 0, Me.Width, Me.Height)
ControlPaint.DrawBorder(graphics, rectangle, BorderColor, ButtonBorderStyle.Solid)
m.Result = CType(1, IntPtr)
ReleaseDC(m.HWnd, hdc)
End If
End If
End Sub
End Class
مهدی فرزاد
سه شنبه 25 تیر 1387, 15:20 عصر
daruosh جان اين كلاس رو ايجاد كردم حالا چطوري بايد ازش براي تغيير رنگ Textbox فرمم استفاده كنم؟
Dariuosh
سه شنبه 25 تیر 1387, 20:28 عصر
daruosh جان اين كلاس رو ايجاد كردم حالا چطوري بايد ازش براي تغيير رنگ Textbox فرمم استفاده كنم؟
الان يه کنترل به نامه کلاسي که درست کردي به نواره ابزارت اضافه شده
اونو بنداز رو Formات ، حالا يه Property داره به نامه BorderColor .......
مهدی فرزاد
جمعه 28 تیر 1387, 20:05 عصر
مرسي مشكلم حل شد ، براي GroupBox هم چيزي هست؟
Dariuosh
شنبه 29 تیر 1387, 09:06 صبح
مرسي مشكلم حل شد ، براي GroupBox هم چيزي هست؟
فقط کافي بود به جايه TextBox از GroupBox ارث بري کني
Imports System.Runtime.InteropServices
Public Class MyGroupBox
Inherits Windows.Forms.GroupBox
Private _Color As Color
Private Shared WM_NCPAINT As Integer = &H85
Private Shared WM_ERASEBKGND As Integer = &H14
Private Shared WM_PAINT As Integer = &HF
Public Property BorderColor() As Color
Get
Return _Color
End Get
Set(ByVal value As Color)
_Color = value
End Set
End Property
<DllImport("user32.dll")> _
Shared Function GetDCEx(ByVal hwnd As IntPtr, ByVal hrgnclip As IntPtr, ByVal fdwOptions As UInt32) As IntPtr
End Function
<DllImport("user32.dll")> _
Shared Function ReleaseDC(ByVal hwnd As IntPtr, ByVal hDC As IntPtr) As Integer
End Function
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
If m.Msg = WM_NCPAINT Or m.Msg = WM_ERASEBKGND Or m.Msg = WM_PAINT Then
Dim hdc As IntPtr = GetDCEx(m.HWnd, CType(1, IntPtr), 1 Or &H20)
If (hdc <> IntPtr.Zero) Then
Dim graphics As Graphics = graphics.FromHdc(hdc)
Dim rectangle As Rectangle = New Rectangle(0, 0, Me.Width, Me.Height)
ControlPaint.DrawBorder(graphics, rectangle, BorderColor, ButtonBorderStyle.Solid)
m.Result = CType(1, IntPtr)
ReleaseDC(m.HWnd, hdc)
End If
End If
End Sub
End Class
مهدی فرزاد
شنبه 29 تیر 1387, 23:03 عصر
عالي بود ، دست شما درد نكنه.
parsavb
یک شنبه 30 تیر 1387, 08:45 صبح
یه راه خیلی راحتتر هم من براتون میزارم
Private Sub form1_Paint(ByVal sender As Object, _
ByVal e As PaintEventArgs) Handles MyBase.Paint
Dim g As Graphics = e.Graphics
Dim pen As New Pen(Color.Red, 2.0)
For Each ctr As Control In Me.Controls
If TypeOf ctr Is TextBox Then
g.DrawRectangle(pen, New _
Rectangle(ctr.Location, ctr.Size))
End If
Next
pen.Dispose()
End Sub
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.