تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
هل يمكن تغيير لون الخط في الزر
#1
هل يمكن تغيير لون خط الزر ؛ لأنني حاولت بأكثر من كود وفشل
إذا طُعِنتَ من الخلفِ فاعلمْ أنك في المقدمةِ
الرد }}}
تم الشكر بواسطة:
#2
خاصية اللون لخط أي أداة بالعادة تكون (ForeColor) فإن لم توجد ، فيعني أنه لا يمكن استخدامها ..

الأفضل أن لا تعتمد على أدوات خارجية غير الأدوات القياسية ..
فإن كان لابد .. فـ في المرفقات أداة زر إحترافية .. فيك تغير شكلها لأكثر من نمط وكلذلك لون الخط.
اعتمدت عليها كثيرا في مشاريعي الأولى .. قبل أن أرجع للفكر القديم بأن لا أعتمد على أي أدوات خارجية ..







أو طريقة من خلال الكود (فيك تغير ألوان خطوط الأزارا):

أفتح مودل جديد  (Module1) وضع في الكود التالي :

كود :
Private colButtons  As New Collection
Private Const KeyConst = "K"
Private Const PROP_COLOR = "SMDColor"
Private Const PROP_HWNDPARENT = "SMDhWndParent"
Private Const PROP_LPWNDPROC = "SMDlpWndProc"
Private Const GWL_WNDPROC As Long = (-4)
Private Const ODA_SELECT As Long = &H2
Private Const ODS_SELECTED As Long = &H1
Private Const ODS_FOCUS As Long = &H10
Private Const ODS_BUTTONDOWN As Long = ODS_FOCUS Or ODS_SELECTED
Private Const WM_DESTROY As Long = &H2
Private Const WM_DRAWITEM As Long = &H2B
Private Const VER_PLATFORM_WIN32_NT As Long = 2

Private Type RECT
  Left        As Long
  Top         As Long
  Right       As Long
  Bottom      As Long
End Type

Private Type SIZE
  cx          As Long
  cy          As Long
End Type

Private Type DRAWITEMSTRUCT
  CtlType     As Long
  CtlID       As Long
  itemID      As Long
  itemAction  As Long
  itemState   As Long
  hWndItem    As Long
  hDC         As Long
  rcItem      As RECT
  itemData    As Long
End Type

Private Type OSVERSIONINFO
 OSVSize         As Long
 dwVerMajor      As Long
 dwVerMinor      As Long
 dwBuildNumber   As Long
 PlatformID      As Long
 szCSDVersion    As String * 128
End Type

Private Declare Function CallWindowProc Lib "user32" _
   Alias "CallWindowProcA" _
  (ByVal lpPrevWndFunc As Long, _
   ByVal hWnd As Long, _
   ByVal msg As Long, _
   ByVal wParam As Long, _
   lParam As DRAWITEMSTRUCT) As Long

Private Declare Function GetParent Lib "user32" _
   (ByVal hWnd As Long) As Long

Private Declare Function GetProp Lib "user32" _
   Alias "GetPropA" _
  (ByVal hWnd As Long, _
   ByVal lpString As String) As Long

Private Declare Function GetTextExtentPoint32 Lib "gdi32" _
   Alias "GetTextExtentPoint32A" _
  (ByVal hDC As Long, _
   ByVal lpSz As String, _
   ByVal cbString As Long, _
   lpSize As SIZE) As Long

Private Declare Function RemoveProp Lib "user32" _
   Alias "RemovePropA" _
  (ByVal hWnd As Long, _
   ByVal lpString As String) As Long

Private Declare Function SetProp Lib "user32" _
   Alias "SetPropA" _
  (ByVal hWnd As Long, _
   ByVal lpString As String, _
   ByVal hData As Long) As Long

Private Declare Function SetTextColor Lib "gdi32" _
   (ByVal hDC As Long, _
   ByVal crColor As Long) As Long

Private Declare Function SetWindowLong Lib "user32" _
   Alias "SetWindowLongA" _
  (ByVal hWnd As Long, _
   ByVal nIndex As Long, _
   ByVal dwNewLong As Long) As Long

Private Declare Function TextOut Lib "gdi32" _
   Alias "TextOutA" _
  (ByVal hDC As Long, _
   ByVal x As Long, _
   ByVal y As Long, _
   ByVal lpString As String, _
   ByVal nCount As Long) As Long
   
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
 (lpVersionInformation As Any) As Long
   


Private Function FindButton(sKey As String) As Boolean

  Dim cmdButton As CommandButton
 
  On Error Resume Next
  Set cmdButton = colButtons.Item(sKey)
  FindButton = (Err.Number = 0)

End Function


Private Function GetKey(hWnd As Long) As String

  GetKey = KeyConst & hWnd

End Function


Private Function ProcessButton(ByVal hWnd As Long, _
                              ByVal uMsg As Long, _
                              ByVal wParam As Long, _
                              lParam As DRAWITEMSTRUCT, _
                              sKey As String) As Long

  Dim cmdButton       As CommandButton
  Dim bRC             As Boolean
  Dim lRC             As Long
  Dim x               As Long
  Dim y               As Long
  Dim lpWndProC       As Long
  Dim lButtonWidth    As Long
  Dim lButtonHeight   As Long
  Dim lPrevColor      As Long
  Dim lColor          As Long
  Dim TextSize        As SIZE
  Dim sCaption        As String
 
  Const PushOffset = 2
 
  Set cmdButton = colButtons.Item(sKey)
  sCaption = cmdButton.Caption
 
  lColor = GetProp(cmdButton.hWnd, PROP_COLOR)
  lPrevColor = SetTextColor(lParam.hDC, lColor)
 
 'in Pixels/Logical Units
  lRC = GetTextExtentPoint32(lParam.hDC, sCaption, Len(sCaption), TextSize)
 
 'in Pixels/Logical Units
  lButtonHeight = lParam.rcItem.Bottom - lParam.rcItem.Top
  lButtonWidth = lParam.rcItem.Right - lParam.rcItem.Left
 
 'the button is pressed! Offset the text
 'so it looks like the button is pushed
   If ((lParam.itemState And ODS_BUTTONDOWN) = ODS_BUTTONDOWN) Then
       cmdButton.SetFocus
       DoEvents   'unneeded on XP - could use If Not IsWinXPPlus() Then DoEvents
       x = (lButtonWidth - TextSize.cx + PushOffset) \ 2
       y = (lButtonHeight - TextSize.cy + PushOffset) \ 2
   Else
       x = (lButtonWidth - TextSize.cx) \ 2
       y = (lButtonHeight - TextSize.cy) \ 2
   End If
 
 'get the default WndProc address
  lpWndProC = GetProp(hWnd, PROP_LPWNDPROC)
 
 'do the default button processing
  ProcessButton = CallWindowProc(lpWndProC, hWnd, uMsg, wParam, lParam)
 
 'put our text on the button
  bRC = TextOut(lParam.hDC, x, y, sCaption, Len(sCaption))
 
 'Restore the device context to the original color
  lRC = SetTextColor(lParam.hDC, lPrevColor)
 
ProcessButton_Exit:
  Set cmdButton = Nothing

End Function


Private Sub RemoveForm(hWndParent As Long)

  Dim hWndButton As Long
  Dim cnt As Integer
 
  UnsubclassForm hWndParent
 
  On Error GoTo RemoveForm_Exit
 
  For cnt = colButtons.Count - 1 To 0 Step -1
 
     hWndButton = colButtons(cnt).hWnd
     
     If GetProp(hWndButton, PROP_HWNDPARENT) = hWndParent Then
        RemoveProp hWndButton, PROP_COLOR
        RemoveProp hWndButton, PROP_HWNDPARENT
        colButtons.Remove cnt
     End If
     
  Next cnt
 
RemoveForm_Exit:

End Sub


Private Function UnsubclassForm(hWnd As Long) As Boolean

  Dim lpWndProC As Long
 
  lpWndProC = GetProp(hWnd, PROP_LPWNDPROC)
 
  If lpWndProC = 0 Then
 
     UnsubclassForm = False
     
  Else
 
     Call SetWindowLong(hWnd, GWL_WNDPROC, lpWndProC)
     RemoveProp hWnd, PROP_LPWNDPROC
     UnsubclassForm = True
     
  End If

End Function


Private Function ButtonColorProc(ByVal hWnd As Long, _
                                ByVal uMsg As Long, _
                                ByVal wParam As Long, _
                                lParam As DRAWITEMSTRUCT) As Long

  Dim lpWndProC       As Long
  Dim bProcessButton  As Boolean
  Dim sButtonKey      As String

  bProcessButton = False      'Assume default processing

  If (uMsg = WM_DRAWITEM) Then
 
    'Do we have this button? To find out, just
    'try to reference the item in the collection.
    'If it's there, we own the button.  If it's
    'not there, we'll get an error.
     sButtonKey = GetKey(lParam.hWndItem)
     bProcessButton = FindButton(sButtonKey)
 
  End If
 
 
  If bProcessButton Then
 
     ProcessButton hWnd, uMsg, wParam, lParam, sButtonKey
     
  Else
 
     lpWndProC = GetProp(hWnd, PROP_LPWNDPROC)
     ButtonColorProc = CallWindowProc(lpWndProC, hWnd, uMsg, wParam, lParam)

     If uMsg = WM_DESTROY Then RemoveForm hWnd
     
  End If

End Function


Public Function RegisterButton(Button As CommandButton, _
                              Forecolor As Long) As Boolean

  Dim hWndParent      As Long
  Dim lpWndProC       As Long
  Dim sButtonKey      As String

 'Make the colButtons key for the button
  sButtonKey = GetKey(Button.hWnd)
 
 'If we already own the button, just change the
 'color otherwise we need to process the whole thing.
  If FindButton(sButtonKey) Then
 
     SetProp Button.hWnd, PROP_COLOR, Forecolor
     Button.Refresh
     
  Else
 
    'Get the handle to the buttons parent form.
     hWndParent = GetParent(Button.hWnd)
 
    'If we can't find a parent form, report a
    'problem and get out.
     If (hWndParent = 0) Then
        RegisterButton = False
        Exit Function
     End If
 
    'found the parent, gather all of the necessary
    'button values and add it to the collection.
     colButtons.Add Button, sButtonKey
     SetProp Button.hWnd, PROP_COLOR, Forecolor
     SetProp Button.hWnd, PROP_HWNDPARENT, hWndParent
     
    'Determine if we've already subclassed this form.
     lpWndProC = GetProp(hWndParent, PROP_LPWNDPROC)
 
    'It's a new form.  Subclass it and add the
    'Window proc address to the collection.
     If (lpWndProC = 0) Then
        lpWndProC = SetWindowLong(hWndParent, _
        GWL_WNDPROC, AddressOf ButtonColorProc)
        SetProp hWndParent, PROP_LPWNDPROC, lpWndProC
     End If
 
  End If
 
  RegisterButton = True

End Function


Public Function UnregisterButton(Button As CommandButton) As Boolean

  Dim hWndParent As Long
  Dim sKeyButton As String

  sKeyButton = GetKey(Button.hWnd)

  If (FindButton(sKeyButton) = False) Then
     UnregisterButton = False
     Exit Function
  End If

  hWndParent = GetProp(Button.hWnd, PROP_HWNDPARENT)
  UnregisterButton = UnsubclassForm(hWndParent)

  colButtons.Remove sKeyButton
  RemoveProp Button.hWnd, PROP_COLOR
  RemoveProp Button.hWnd, PROP_HWNDPARENT
 
End Function


Private Function IsWinXPPlus() As Boolean

 'returns True if running WinXP (NT5.1) or later
  Dim osv As OSVERSIONINFO

  osv.OSVSize = Len(osv)

  If GetVersionEx(osv) = 1 Then
 
     IsWinXPPlus = (osv.PlatformID = VER_PLATFORM_WIN32_NT) And _
                   (osv.dwVerMajor >= 5 And osv.dwVerMinor >= 1)

  End If

End Function



و في صفحة كود النافذة  (Form1) التي تريد تغيير ألوان خط الأزرار  فيها ..  :
أنسخ إليها الكود التالي :


كود :
Const vbDarkRed = &H90&
Const vbDarkBlue = &H900000

'consts for the Command1 button control array
Const nDefault = 0
Const nRed = 1
Const nGreen = 2
Const nBlue = 3
Const nYellow = 4
Const nMagenta = 5
Const nCyan = 6
Const nWhite = 7
Const nDkBlue = 8
Const nDkRed = 9

Private Sub Form_Load()
    RegisterButton Command1, &H80C0FF       ' أي زر تريد تغيير لونه أكتبه بهذه الطريقة إما رقم اللون
    RegisterButton Command2, vbBlue         ' أو اسم اللون
    ' لكن في البداية عليك الذهاب إلى خصائص الزر وتغيير خاصية
    ' Style = 1 - Graphical
    
End Sub


الملفات المرفقة
.zip   lvButtons.zip (الحجم : 45.08 ك ب / التحميلات : 28)
قال صلى الله عليه وسلم: 
«كلمتان خفيفتان على اللسان 
ثقيلتان في الميزان،حبيبتان إلى الرحمن: 
سبحان الله وبحمده، سبحان الله العظيم».
الرد }}}
تم الشكر بواسطة: مصمم هاوي
#3
بارك الله فيك أستاذ طه.
ويعلم الله تعالى أنني أستفيد كثيرا بتوجيهاتك الرائعة
وأنا أيضا أحاول قدر الإمكان عدم استخدام أدوات خارجية
إذا طُعِنتَ من الخلفِ فاعلمْ أنك في المقدمةِ
الرد }}}
تم الشكر بواسطة: Taha Okla


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  [سؤال] هل يمكن جمع عمود فى datagride mohamed125 2 1,894 07-12-24, 02:27 AM
آخر رد: عبدالمؤمن
  كيف يمكن عمل clear لل datagrid haitham Muhammed 1 286 13-11-24, 12:42 AM
آخر رد: السيد الغالي
Question [vb6.0] كيف يمكن إدراج الاسم الذي موجود في الصورة في Label1 برمجياً ؟ Microformt 2 288 02-10-24, 06:01 PM
آخر رد: Microformt
Question [vb6.0] هل يمكن عرض اسماء الاصناف في الرسم البياني في جهة اليمين بشرط ياخد الاسماء من قاعدة Microformt 0 230 14-08-24, 06:42 PM
آخر رد: Microformt
  كيف يمكن استخدام الtimer لملء الكمبوبوكس haitham Muhammed 0 395 27-05-24, 09:55 PM
آخر رد: haitham Muhammed
Heart كيفية تغيير نوعية الــ DataBase أبو خالد الشكري 3 693 10-01-24, 10:55 PM
آخر رد: أبو خالد الشكري
Question [vb6.0] كيف يمكن برمجة عدد السجلات واستعراض السجلات بشرط رقم الموظف ؟ Microformt 3 587 09-01-24, 01:05 AM
آخر رد: Taha Okla
Question [vb6.0] كيف يمكن استدعاء اسم البرنامج من النافدة هذه وضعة في textbox ؟ Microformt 1 515 02-01-24, 10:06 PM
آخر رد: Taha Okla
Question [vb6.0] كيف يمكن استدعاء هذه الدالة وضعها تحت زر الامر ؟ Microformt 1 579 31-12-23, 11:52 PM
آخر رد: Taha Okla
  [vb6.0] تغيير نوع الخط فى عمود معين داخل الdatagrid haitham Muhammed 6 873 20-12-23, 01:11 PM
آخر رد: mhareek

التنقل السريع :


يقوم بقرائة الموضوع: