elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Security Series.XSS. [Cross Site Scripting]


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  ¿Cambiar el Color de un Item al agregarlo?
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: ¿Cambiar el Color de un Item al agregarlo?  (Leído 3,677 veces)
Brian1511

Desconectado Desconectado

Mensajes: 268


¿Quien soy esa es la gran pregunta?


Ver Perfil WWW
¿Cambiar el Color de un Item al agregarlo?
« en: 21 Noviembre 2012, 01:49 am »

Hola a todos quisiera sabes como cambiar el color de un item al agregarlo

Ejemplo!:

-----------------------------------------|
Hola                  |
Como estas  |
Jajaj             |
Estilos!            |
Brian1511     |
-----------------------------------------|

y haci susecivamente como lo hat¡ria porfavor ayudenme a hacer esto!.


En línea



Creador de BrainMind
Danyfirex


Desconectado Desconectado

Mensajes: 493


My Dear Mizuho


Ver Perfil
Re: ¿Cambiar el Color de un Item al agregarlo?
« Respuesta #1 en: 21 Noviembre 2012, 13:40 pm »

Es así.

Código
  1. ListView1.ListItems(1).ForeColor = vbRed


saludos

EDITO:

un ejemplo mas claro para que no tengas dudas.

Código
  1. Private Sub Form_Load()
  2. Dim i As Integer
  3. Dim li As ListItem
  4.  
  5. ListView1.View = lvwReport
  6.  
  7. ListView1.ColumnHeaders.Add Text:="hola", Width:=1000
  8.  
  9. For i = 1 To 8
  10. Set li = ListView1.ListItems.Add(Text:="Item " & i)
  11. Next i
  12.  
  13. ListView1.ListItems(1).ForeColor = vbYellow
  14. ListView1.ListItems(2).ForeColor = vbBlue
  15. ListView1.ListItems(3).ForeColor = vbRed
  16. ListView1.ListItems(4).ForeColor = vbGreen
  17. ListView1.ListItems(5).ForeColor = vbCyan
  18. ListView1.ListItems(6).ForeColor = vbWhite
  19. ListView1.ListItems(7).ForeColor = vbBlack
  20. ListView1.ListItems(8).ForeColor = vbMagenta
  21. End Sub
  22.  
  23.  
  24.  

saludos


« Última modificación: 21 Noviembre 2012, 13:45 pm por Danyfirex » En línea

Brian1511

Desconectado Desconectado

Mensajes: 268


¿Quien soy esa es la gran pregunta?


Ver Perfil WWW
Re: ¿Cambiar el Color de un Item al agregarlo?
« Respuesta #2 en: 21 Noviembre 2012, 19:16 pm »

Hoola amigo como etsas bueno probe tu code pero me di cuenta que lo que isiste fue para un ListView y lo quisiera es para en List Box porfavor ayudame

Gracias por Reponder!
En línea



Creador de BrainMind
BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: ¿Cambiar el Color de un Item al agregarlo?
« Respuesta #3 en: 21 Noviembre 2012, 19:53 pm »

LeandroA había creado un User Control el cual si no mal recuerdo tenia esta opción (Del cual yo cree mi ListViewEx 2.0), ya que este listItem creo que carece de tal función (puedes expandirla con subclasificación).

Dulces Lunas!¡.
En línea

The Dark Shadow is my passion.
seba123neo
Moderador
***
Desconectado Desconectado

Mensajes: 3.621



Ver Perfil WWW
Re: ¿Cambiar el Color de un Item al agregarlo?
« Respuesta #4 en: 21 Noviembre 2012, 20:08 pm »

pedis algo que parece facil, pero VB6 no lo ofrece, por lo tanto tenes que escribir una chorrada de codigo para hacer eso que queres, aca te dejo igual el codigo para hacer eso, pero te recomiendo que uses un usercontrol como el que te dijeron arriba.

en un modulo (bas)

Código
  1. Option Explicit
  2.  
  3. Private Type RECT
  4.    Left As Long
  5.    Top As Long
  6.    Right As Long
  7.    Bottom As Long
  8. End Type
  9.  
  10. Private Type DRAWITEMSTRUCT
  11.    CtlType As Long
  12.    CtlID As Long
  13.    itemID As Long
  14.    itemAction As Long
  15.    itemState As Long
  16.    hwndItem As Long
  17.    hdc As Long
  18.    rcItem As RECT
  19.    itemData As Long
  20. End Type
  21.  
  22. Private Type CWPSTRUCT
  23.    lParam As Long
  24.    wParam As Long
  25.    message As Long
  26.    hWnd As Long
  27. End Type
  28.  
  29. Private Type CREATESTRUCT
  30.    lpCreateParams As Long
  31.    hInstance As Long
  32.    hMenu As Long
  33.    hWndParent As Long
  34.    cy As Long
  35.    cx As Long
  36.    y As Long
  37.    x As Long
  38.    style As Long
  39.    lpszName As Long
  40.    lpszClass As Long
  41.    ExStyle As Long
  42. End Type
  43.  
  44. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  45. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  46. Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  47. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  48. Private Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
  49. Private Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
  50. 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
  51. Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
  52. Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
  53. Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
  54. Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
  55. Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
  56. Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
  57. Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
  58.  
  59. Private Const WH_CALLWNDPROC = 4
  60. Private Const CBS_OWNERDRAWVARIABLE = &H20&
  61. Private Const CB_GETLBTEXT = &H148
  62. Private Const COLOR_HIGHLIGHT = 13
  63. Private Const COLOR_HIGHLIGHTTEXT = 14
  64. Private Const COLOR_WINDOW = 5
  65. Private Const COLOR_WINDOWTEXT = 8
  66. Private Const GWL_WNDPROC = (-4)
  67. Private Const GWL_STYLE = (-16)
  68. Private Const ODS_SELECTED = &H1
  69. Private Const ODT_COMBOBOX = 3
  70. Private Const WM_CREATE = &H1
  71. Private Const WM_DRAWITEM = &H2B
  72.  
  73. Private lPrevWndProc As Long
  74. Private lHook As Long
  75. Private lSubCombo As Long
  76.  
  77. Sub Main()
  78.    lHook = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf HookApp, App.hInstance, App.ThreadID)
  79.    Form1.Show
  80.    Call UnhookWindowsHookEx(lHook)
  81. End Sub
  82.  
  83. Public Sub SubClassForm(ByVal hWnd As Long)
  84.    lPrevWndProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf SubClassedForm)
  85. End Sub
  86.  
  87. Public Sub RemoveSubClassing(ByVal hWnd As Long)
  88.    Call SetWindowLong(hWnd, GWL_WNDPROC, lPrevWndProc)
  89. End Sub
  90.  
  91. Public Function SubClassedForm(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  92.    Dim tItem As DRAWITEMSTRUCT
  93.    Dim sItem As String
  94.    Dim lBackBrush As Long
  95.  
  96.    If Msg = WM_DRAWITEM Then
  97.        Call CopyMemory(tItem, ByVal lParam, Len(tItem))
  98.        If tItem.CtlType = ODT_COMBOBOX Then
  99.            sItem = Space(255)
  100.            Call SendMessage(tItem.hwndItem, CB_GETLBTEXT, tItem.itemID, ByVal sItem)
  101.            sItem = Left(sItem, InStr(sItem, Chr(0)) - 1)
  102.            If (tItem.itemState And ODS_SELECTED) Then
  103.                lBackBrush = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT))
  104.                Call SetBkColor(tItem.hdc, GetSysColor(COLOR_HIGHLIGHT))
  105.                Call SetTextColor(tItem.hdc, GetSysColor(COLOR_HIGHLIGHTTEXT))
  106.            Else
  107.                lBackBrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW))
  108.                Call SetBkColor(tItem.hdc, GetSysColor(COLOR_WINDOW))
  109.                Call SetTextColor(tItem.hdc, tItem.itemData)
  110.            End If
  111.            FillRect tItem.hdc, tItem.rcItem, lBackBrush
  112.            TextOut tItem.hdc, tItem.rcItem.Left, tItem.rcItem.Top, ByVal sItem, Len(sItem)
  113.            SubClassedForm = 0
  114.            Exit Function
  115.        End If
  116.    End If
  117.    SubClassedForm = CallWindowProc(lPrevWndProc, hWnd, Msg, wParam, lParam)
  118. End Function
  119.  
  120. Private Function HookApp(ByVal lHookID As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  121.    Dim tCWP As CWPSTRUCT
  122.    Dim sClass As String
  123.  
  124.    Call CopyMemory(tCWP, ByVal lParam, Len(tCWP))
  125.    If tCWP.message = WM_CREATE Then
  126.        sClass = Space(128)
  127.        Call GetClassName(tCWP.hWnd, ByVal sClass, 128)
  128.        sClass = Left(sClass, InStr(sClass, Chr(0)) - 1)
  129.        If sClass = "ComboLBox" Then
  130.            lSubCombo = SetWindowLong(tCWP.hWnd, GWL_WNDPROC, AddressOf SubComboCreate)
  131.        End If
  132.    End If
  133.    HookApp = CallNextHookEx(lHook, lHookID, wParam, ByVal lParam)
  134. End Function
  135.  
  136. Private Function SubComboCreate(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  137.    Dim tCreate As CREATESTRUCT
  138.  
  139.    If Msg = WM_CREATE Then
  140.        Call CopyMemory(tCreate, ByVal lParam, Len(tCreate))
  141.        tCreate.style = tCreate.style Or CBS_OWNERDRAWVARIABLE
  142.        Call CopyMemory(ByVal lParam, tCreate, Len(tCreate))
  143.        Call SetWindowLong(hWnd, GWL_STYLE, tCreate.style)
  144.        Call SetWindowLong(hWnd, GWL_WNDPROC, lSubCombo)
  145.    End If
  146.    SubComboCreate = CallWindowProc(lSubCombo, hWnd, Msg, wParam, lParam)
  147. End Function
  148.  
  149.  

en el formulario:

Código
  1. Option Explicit
  2.  
  3. Private Sub Form_Load()
  4.  
  5.    With Combo1
  6.        .AddItem ("Item 1")
  7.        .itemData(.NewIndex) = vbBlue
  8.        .AddItem ("Item 2")
  9.        .itemData(.NewIndex) = vbRed
  10.        .AddItem ("Item 3")
  11.        .itemData(.NewIndex) = vbGreen
  12.        .AddItem ("Item 4")
  13.        .itemData(.NewIndex) = vbYellow
  14.        .AddItem ("Item 5")
  15.        .itemData(.NewIndex) = vbRed
  16.    End With
  17.  
  18.    Call SubClassForm(Me.hWnd)
  19. End Sub
  20.  
  21. Private Sub Form_Unload(Cancel As Integer)
  22.    Call RemoveSubClassing(Me.hWnd)
  23. End Sub

y tenes que hacer que el proyecto comienze desde el Sub_Main (en las propiedades del proyecto)
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Cambiar color
Diseño Gráfico
alkan 4 3,889 Último mensaje 4 Enero 2006, 20:26 pm
por alkan
Cambiar color a JButton....
Java
er_rafael_rafi 0 15,169 Último mensaje 18 Abril 2009, 18:42 pm
por er_rafael_rafi
[C#] Cambiar color de un item [NO seleccionado] en un ListBox
.NET (C#, VB.NET, ASP)
Shell Root 3 10,463 Último mensaje 16 Septiembre 2013, 08:16 am
por Shell Root
Cambiar fuente a un item de ComboBox
Programación Visual Basic
Orellanack 1 2,505 Último mensaje 3 Octubre 2013, 20:54 pm
por Danyfirex
cambiar el color del un item en Combobox
.NET (C#, VB.NET, ASP)
nolasco281 0 4,505 Último mensaje 9 Mayo 2014, 04:51 am
por nolasco281
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines