Fetstil Fetstil Kursiv Understrykning linje färgläggning tabellverk Punktlista Nummerlista Vänster Centrerat högerställt Utfyllt Länk Bild htmlmode
  • Forum & Blog
    • Forum - översikt
      • .Net
        • asp.net generellt
        • c#
        • vb.net
        • f#
        • silverlight
        • microsoft surface
        • visual studio .net
      • databaser
        • sql-server
        • databaser
        • access
        • mysql
      • mjukvara klient
        • datorer och komponenter
        • nätverk, lan/wan
        • operativsystem
        • programvaror
        • säkerhet, inställningar
        • windows server
        • allmänt
        • crystal reports
        • exchange/outlook
        • microsoft office
      • mjukvara server
        • active directory
        • biztalk
        • exchange
        • linux
        • sharepoint
        • webbservers
        • sql server
      • appar (win/mobil)
      • programspråk
        • c++
        • delphi
        • java
        • quick basic
        • visual basic
      • scripting
        • asp 3.0
        • flash actionscript
        • html css
        • javascript
        • php
        • regular expresssion
        • xml
      • spel och grafik
        • DirectX
        • Spel och grafik
      • ledning
        • Arkitektur
        • Systemutveckling
        • krav och test
        • projektledning
        • ledningsfrågor
      • vb-sektioner
        • activeX
        • windows api
        • elektronik
        • internet
        • komponenter
        • nätverk
        • operativsystem
      • övriga forum
        • arbete karriär
        • erbjuda uppdrag och tjänster
        • juridiska frågor
        • köp och sälj
        • matematik och fysik
        • intern information
        • skrivklåda
        • webb-operatörer
    • Posta inlägg i forumet
    • Chatta med andra
  • Konto
    • Medlemssida
    • Byta lösenord
    • Bli bonsumedlem
    • iMail
  • Material
    • Tips & tricks
    • Artiklar
    • Programarkiv
  • JOBB
  • Student
    • Studentlicenser
  • KONTAKT
    • Om pellesoft
    • Grundare
    • Kontakta oss
    • Annonsering
    • Partners
    • Felanmälan
  • Logga in

Hem / Tips & tricks

#820 - Högerställ texterna i en combobox

Postat 2001-11-08 12:45:41 av Pelle Johansson i Kategori Programmering, C#, Kommandon med 0 Kommentarer

Private Const GWL_EXSTYLE As Long = (-20)
Private Const WS_EX_RIGHT As Long = &H1000
Private Const WS_EX_LEFTSCROLLBAR As Long = &H4000
Private Const CB_SHOWDROPDOWN = &H14F

Private Enum AlignConstants
alignLeft = 0
alignRight = 1
End Enum

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

Private Type COMBOBOXINFO
cbSize As Long
rcItem As RECT
rcButton As RECT
stateButton As Long
hwndCombo As Long
hwndEdit As Long
hwndList As Long
End Type

Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex 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 GetComboBoxInfo _
Lib "user32.dll" _
(ByVal hwndCombo As Long, _
CBInfo As COMBOBOXINFO) As Long

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



Private Sub Form_Load()

Dim x As Long

For x = 0 To Screen.FontCount - 1
Combo1.AddItem Screen.Fonts(x)
Next

End Sub


Private Sub Check1_Click()

'Since the values of the alignment Enum
'correspond to the two values of a checkbox,
'the checkbox value property can be used
'directly as the alignment style parameter.
ComboListAlign Combo1, Check1.Value

End Sub

Private Sub Check2_Click()


ComboScrollAlign Combo1, Check2.Value

End Sub


Private Sub Check3_Click()

ComboFlipButtonEdit Combo1, Check3.Value

End Sub


Private Sub ComboListAlign(cb As ComboBox, _
Optional ByVal Align As AlignConstants = alignLeft)

Dim hList As Long
Dim nStyle As Long

'obtain the handle to the list
'portion of the combo
hList = GetComboListHandle(cb)

'if valid, change the style
If hList <> 0 Then

nStyle = GetWindowLong(hList, GWL_EXSTYLE)

Select Case Align
Case alignRight
nStyle = nStyle Or WS_EX_RIGHT
Case Else
nStyle = nStyle And Not WS_EX_RIGHT
End Select

SetWindowLong hList, GWL_EXSTYLE, nStyle

End If

'drop the combo
Call SendMessage(cb.hwnd, CB_SHOWDROPDOWN, True, ByVal 0)

End Sub


Private Sub ComboScrollAlign(cb As ComboBox, _
Optional ByVal Align As AlignConstants = alignRight)

Dim hList As Long
Dim nStyle As Long

'obtain the handle to the list
'portion of the combo
hList = GetComboListHandle(cb)

'if valid, change the style
If hList <> 0 Then

nStyle = GetWindowLong(hList, GWL_EXSTYLE)

Select Case Align
Case alignRight
nStyle = nStyle Or WS_EX_LEFTSCROLLBAR
Case Else
nStyle = nStyle And Not WS_EX_LEFTSCROLLBAR
End Select

SetWindowLong hList, GWL_EXSTYLE, nStyle

End If

'drop the combo
Call SendMessage(cb.hwnd, CB_SHOWDROPDOWN, True, ByVal 0)

End Sub


Private Sub ComboFlipButtonEdit(cb As ComboBox, _
Optional ByVal Align As AlignConstants = alignLeft)

Dim nStyle As Long

'get the style for the combo
nStyle = GetWindowLong(cb.hwnd, GWL_EXSTYLE)

'apply or remove the WS_EX_RIGHT
'window style
Select Case Align
Case alignRight
nStyle = nStyle Or WS_EX_RIGHT
Case Else
nStyle = nStyle And Not WS_EX_RIGHT
End Select

SetWindowLong cb.hwnd, GWL_EXSTYLE, nStyle

'the code above flips the list
'portion too, so reset the list
'to the correct alignment
ComboListAlign cb, alignLeft

End Sub


Private Function GetComboListHandle(ctl As ComboBox) As Long

Dim CBI As COMBOBOXINFO

CBI.cbSize = Len(CBI)
Call GetComboBoxInfo(ctl.hwnd, CBI)
GetComboListHandle = CBI.hwndList

End Function

Sample:
Size:

Nyligen

  • 09:09 Vill du köpa medicinska tester?
  • 12:47 Vem beviljar assistansen – kommune
  • 14:17 Någon med erfarenhet av hemstädnin
  • 14:14 Bör man använda sig av en båtförme
  • 14:12 Finns det någon intressant hundblo
  • 14:25 Tips på verktyg för att skapa QR-k
  • 14:23 Tips på verktyg för att skapa QR-k
  • 20:52 Fungerer innskuddsbonuser egentlig

Sidor

  • Hem
  • Bli bonusmedlem
  • Läs artiklar
  • Chatta med andra
  • Sök och erbjud jobb
  • Kontakta oss
  • Studentlicenser
  • Skriv en artikel

Statistik

Antal besökare:
Antal medlemmar:
Antal inlägg:
Online:
På chatten:
4 569 159
27 952
271 704
892
0

Kontakta oss

Frågor runt konsultation, rådgivning, uppdrag, rekrytering, annonsering och övriga ärenden. Ring: 0730-88 22 24 | pelle@pellesoft.se

© 1986-2013 PelleSoft AB. Last Build 4.1.7169.18070 (2019-08-18 10:02:21) 4.0.30319.42000
  • Om
  • Kontakta
  • Regler
  • Cookies