Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 | 2 |

 

  Вопрос: Мелочи а нет у кого спросить... Добавлено: 05.01.04 22:38  

Автор вопроса:  NovichoK

1) Как ограничить переменную типа double, чтоб она показывала только, к примеру, 4 символа после запятой

2)Как выводить в две колонки в listbox, вот таким образом

                               1         А                                        

                               2         Б

                               3         В 

Есть два массива. В данном примере в одно массиве  -  числа, в другом массиве  - буквы, и нужно их в listbox вывести таким образом, как это сделать?????Может есть какой другой компонент, тогда подскажите, потому что с листбоксом что-то не получается...            

Ответить

  Ответы Всего ответов: 16  

Номер ответа: 1
Автор ответа:
 Sharp


Лидер форума

ICQ: 216865379 

Вопросов: 106
Ответов: 9979
 Web-сайт: sharpc.livejournal.com
 Профиль | | #1
Добавлено: 05.01.04 23:35

1) Format(num,"#####.####")

2) Используй ListBox1.Additem a(i) & vbtab & a(i) и моноширинный шрифт :)

Вроде там есть что-то типа Columns, но не знаю, ниразу не юзал

Ответить

Номер ответа: 2
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #2
Добавлено: 05.01.04 23:44

На первый вопрос:

Round(doubleValue, 4)

На второй вопрос, ща ниже выдаю код формы, а потом модуля, на форме 2 ListBox (lst2, lst1) один Picture1...

Ответить

Номер ответа: 3
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #3
Добавлено: 05.01.04 23:44

На первый вопрос:

Round(doubleValue, 4)

На второй вопрос, ща ниже выдаю код формы, а потом модуля, на форме 2 ListBox (lst2, lst1) один Picture1 с картинкой...

Ответить

Номер ответа: 4
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #4
Добавлено: 05.01.04 23:44

На первый вопрос:

Round(doubleValue, 4)

На второй вопрос, ща ниже выдаю код формы, а потом модуля, на форме 2 ListBox (lst2, lst1) один Picture1 с картинкой...

Ответить

Номер ответа: 5
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #5
Добавлено: 05.01.04 23:44

'Форма

Option Explicit

Private Declare Sub InitCommonControls Lib "comctl32.dll" ()

Dim hHeader1 As Long, hHeader2 As Long

Private Sub Form_Initialize()

Call InitCommonControls

End Sub

Private Sub Form_Load()

Dim i As Long

With lst1

hHeader1 = DoCreateHeader(.hwnd, _

.Left \ Screen.TwipsPerPixelX, _

.Top \ Screen.TwipsPerPixelY - 18, _

.Width \ Screen.TwipsPerPixelX, _

20, _

HDS_BUTTONS)

End With

For i = 0 To 3

Call AddHeaderItem(hHeader1, i, 80, HDI_TEXT, HDF_LEFT, "???????" & i + 1)

Next

For i = 0 To 100

lst1.AddItem Timer & vbTab & Timer & vbTab & Timer & vbTab & Timer

Next

With lst2

hHeader2 = DoCreateHeader(.hwnd, _

.Left \ Screen.TwipsPerPixelX, _

.Top \ Screen.TwipsPerPixelY - 18, _

.Width \ Screen.TwipsPerPixelX, _

20, _

&H0)

End With

For i = 0 To 2

Call AddHeaderItem(hHeader2, i, 80, HDI_TEXT Or HDI_BITMAP, HDF_LEFT, "???????" & i + 1, Picture1.Picture)

Next

For i = 0 To 100

lst2.AddItem Timer & vbTab & Timer & vbTab & Timer

Next

End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

Call DestroyHeaderCtl(hHeader1)

Call DestroyHeaderCtl(hHeader2)

End Sub

Ответить

Номер ответа: 6
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #6
Добавлено: 05.01.04 23:45

' Модуль заголовка

Option Explicit

' §§§§§§§§§§§§§§§§§§§§§§§§§§ HomeWork 2003 §§§§§§§§§§§§§§§§§§§§§§§§§§

' §§§§§§§§§§§§§§§§§§§§§§§§§§ e-mail to sne_pro@mail.ru §§§§§§§§§§§§§§

Private Declare Sub InitCommonControls Lib "comctl32.dll" ()

Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Private Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Declare Function CreateWindowEx Lib "user32.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long

Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Declare Function GetStockObject Lib "gdi32.dll" (ByVal nIndex As Long) As Long

Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long

Private Declare Function GetParent Lib "user32.dll" (ByVal hwnd As Long) As Long

Public Enum gbHWHeaderStyles

HDS_BUTTONS = &H2

HDS_HOTTRACK = &H4

End Enum

Public Enum gbHWHeaderMask

HDI_WIDTH = &H1

HDI_TEXT = &H2

HDI_BITMAP = &H10

End Enum

Public Enum gbHWHEaderFormat

HDF_LEFT = &H0

HDF_RIGHT = &H1

HDF_CENTER = &H2

HDF_OWNERDRAW = &H8000&

HDF_STRING = &H4000

HDF_BITMAP = &H2000

HDF_BITMAP_ON_RIGHT = &H1000

End Enum

Public Type RECT

Left As Long

Top As Long

Right As Long

Bottom As Long

End Type

Public Type HD_ITEM

mask As gbHWHeaderMask

cxy As Long

pszText As String

hbm As Long

cchTextMax As Long

fmt As gbHWHEaderFormat

lParam As Long

iImage As Long ' comctl 4.70+

iOrder As Long ' comctl 4.70+

End Type

Private Type gbHWCtrlData

BaseProc As Long

hwnd As Long

lstHandle As Long

End Type

Private Const WS_CHILD As Long = &H40000000

Private Const SWP_SHOWWINDOW As Long = &H40

Private Const DEFAULT_GUI_FONT As Long = &H11

Private Const WM_SETFONT As Long = &H30

Private Const LB_SETTABSTOPS As Long = &H192

Private Const WM_SETREDRAW As Long = &HB

Private Const HDM_GETITEMCOUNT As Long = &H1200

Private Const HDM_INSERTITEM As Long = &H1201

Private Const HDM_DELETEITEM As Long = &H1202

Private Const HDM_GETITEMRECT As Long = &H1207

Private ctlData() As gbHWCtrlData

Public Function DoCreateHeader(ByVal lstHandle As Long, _

ByVal rcLeft As Long, _

ByVal rcTop As Long, _

ByVal rcWidth As Long, _

ByVal rcHeight As Long, _

Optional ByVal lStyle As gbHWHeaderStyles) As Long

Dim hFont As Long, tmp As Long, lOldWndProc As Long

Call InitCommonControls

DoCreateHeader = CreateWindowEx(&H0, "SysHeader32", vbNullString, lStyle Or WS_CHILD, &H0, &H0, &H0, &H0, GetParent(lstHandle), &H0, App.hInstance, ByVal &H0)

Call SetWindowPos(DoCreateHeader, &H0, rcLeft, rcTop, rcWidth, rcHeight, SWP_SHOWWINDOW)

hFont = GetStockObject(DEFAULT_GUI_FONT)

tmp = SelectObject(DoCreateHeader, hFont)

Call SendMessage(DoCreateHeader, WM_SETFONT, hFont, ByVal True)

Call SelectObject(DoCreateHeader, tmp)

lOldWndProc = SetWindowLong(DoCreateHeader, &HFFFC, AddressOf HeaderProc)

Call AddCtl(lOldWndProc, DoCreateHeader, lstHandle)

End Function

Public Sub DestroyHeaderCtl(ByVal lClHandle As Long)

Dim Index As Integer, ProcOld As Long

Index = GetCtlByKey(lClHandle, ProcOld)

If Index = &HFFFF Then Exit Sub

Call SetWindowLong(lClHandle, &HFFFC, ProcOld)

Call RemoveCtl(Index)

End Sub

Public Sub AddHeaderItem(ByVal hHeader As Long, _

ByVal itemNo As Long, _

ByVal nItemWidth As Long, _

ByVal hdiMask As gbHWHeaderMask, _

ByVal hdiFormat As gbHWHEaderFormat, _

Optional ByRef sCaption As String, _

Optional ByRef hBitMap As Long)

Dim HDI As HD_ITEM

With HDI

.mask = hdiMask

.hbm = hBitMap

.fmt = hdiFormat

.cxy = nItemWidth

.pszText = sCaption

.cchTextMax = Len(HDI.pszText)

End With

Call SendMessage(hHeader, HDM_INSERTITEM, itemNo, HDI)

End Sub

Private Function HeaderProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

On Error Resume Next

Dim ProcOld As Long, lstHandle As Long, lWrk As Long, TabArray() As Long, rct As RECT

Call GetCtlByKey(hwnd, ProcOld, lstHandle)

HeaderProc = CallWindowProc(ProcOld, hwnd, Msg, wParam, lParam)

If Msg = &HF Then

lWrk = SendMessage(hwnd, HDM_GETITEMCOUNT, &H0, ByVal &H0)

ReDim TabArray(lWrk - &H2)

For lWrk = 0 To lWrk - &H2

Call SendMessage(hwnd, HDM_GETITEMRECT, lWrk, rct)

TabArray(lWrk) = rct.Right / 1.5

Next

Call SendMessage(lstHandle, LB_SE

Ответить

Номер ответа: 7
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #7
Добавлено: 05.01.04 23:49

Ну и на мыло скинул тоже самое, только примером... Этого примера ни у кого нет, я сам писал... Фишка в том, что размер столбцов в Liste можно менять во время выполнения, путем изменения ширины Header'а...

Там модуль, это все к Header'у... Поьзуем ;)

Ответить

Номер ответа: 8
Автор ответа:
 Sharp


Лидер форума

ICQ: 216865379 

Вопросов: 106
Ответов: 9979
 Web-сайт: sharpc.livejournal.com
 Профиль | | #8
Добавлено: 06.01.04 00:00

2sne: не дописал

Ответить

Номер ответа: 9
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #9
Добавлено: 06.01.04 00:49

' Упс, не заметил, сории, теперь все!



Option Explicit

' §§§§§§§§§§§§§§§§§§§§§§§§§§ HomeWork 2003 §§§§§§§§§§§§§§§§§§§§§§§§§§

' §§§§§§§§§§§§§§§§§§§§§§§§§§ e-mail to sne_pro@mail.ru §§§§§§§§§§§§§§

Private Declare Sub InitCommonControls Lib "comctl32.dll" ()

Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Private Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Declare Function CreateWindowEx Lib "user32.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long

Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Declare Function GetStockObject Lib "gdi32.dll" (ByVal nIndex As Long) As Long

Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long

Private Declare Function GetParent Lib "user32.dll" (ByVal hwnd As Long) As Long

Public Enum gbHWHeaderStyles

HDS_BUTTONS = &H2

HDS_HOTTRACK = &H4

End Enum

Public Enum gbHWHeaderMask

HDI_WIDTH = &H1

HDI_TEXT = &H2

HDI_BITMAP = &H10

End Enum

Public Enum gbHWHEaderFormat

HDF_LEFT = &H0

HDF_RIGHT = &H1

HDF_CENTER = &H2

HDF_OWNERDRAW = &H8000&

HDF_STRING = &H4000

HDF_BITMAP = &H2000

HDF_BITMAP_ON_RIGHT = &H1000

End Enum

Public Type RECT

Left As Long

Top As Long

Right As Long

Bottom As Long

End Type

Public Type HD_ITEM

mask As gbHWHeaderMask

cxy As Long

pszText As String

hbm As Long

cchTextMax As Long

fmt As gbHWHEaderFormat

lParam As Long

iImage As Long ' comctl 4.70+

iOrder As Long ' comctl 4.70+

End Type

Private Type gbHWCtrlData

BaseProc As Long

hwnd As Long

lstHandle As Long

End Type

Private Const WS_CHILD As Long = &H40000000

Private Const SWP_SHOWWINDOW As Long = &H40

Private Const DEFAULT_GUI_FONT As Long = &H11

Private Const WM_SETFONT As Long = &H30

Private Const LB_SETTABSTOPS As Long = &H192

Private Const WM_SETREDRAW As Long = &HB

Private Const HDM_GETITEMCOUNT As Long = &H1200

Private Const HDM_INSERTITEM As Long = &H1201

Private Const HDM_DELETEITEM As Long = &H1202

Private Const HDM_GETITEMRECT As Long = &H1207

Private ctlData() As gbHWCtrlData

Public Function DoCreateHeader(ByVal lstHandle As Long, _

ByVal rcLeft As Long, _

ByVal rcTop As Long, _

ByVal rcWidth As Long, _

ByVal rcHeight As Long, _

Optional ByVal lStyle As gbHWHeaderStyles) As Long

Dim hFont As Long, tmp As Long, lOldWndProc As Long

Call InitCommonControls

DoCreateHeader = CreateWindowEx(&H0, "SysHeader32", vbNullString, lStyle Or WS_CHILD, &H0, &H0, &H0, &H0, GetParent(lstHandle), &H0, App.hInstance, ByVal &H0)

Call SetWindowPos(DoCreateHeader, &H0, rcLeft, rcTop, rcWidth, rcHeight, SWP_SHOWWINDOW)

hFont = GetStockObject(DEFAULT_GUI_FONT)

tmp = SelectObject(DoCreateHeader, hFont)

Call SendMessage(DoCreateHeader, WM_SETFONT, hFont, ByVal True)

Call SelectObject(DoCreateHeader, tmp)

lOldWndProc = SetWindowLong(DoCreateHeader, &HFFFC, AddressOf HeaderProc)

Call AddCtl(lOldWndProc, DoCreateHeader, lstHandle)

End Function

Public Sub DestroyHeaderCtl(ByVal lClHandle As Long)

Dim Index As Integer, ProcOld As Long

Index = GetCtlByKey(lClHandle, ProcOld)

If Index = &HFFFF Then Exit Sub

Call SetWindowLong(lClHandle, &HFFFC, ProcOld)

Call RemoveCtl(Index)

End Sub

Public Sub AddHeaderItem(ByVal hHeader As Long, _

ByVal itemNo As Long, _

ByVal nItemWidth As Long, _

ByVal hdiMask As gbHWHeaderMask, _

ByVal hdiFormat As gbHWHEaderFormat, _

Optional ByRef sCaption As String, _

Optional ByRef hBitMap As Long)

Dim HDI As HD_ITEM

With HDI

.mask = hdiMask

.hbm = hBitMap

.fmt = hdiFormat

.cxy = nItemWidth

.pszText = sCaption

.cchTextMax = Len(HDI.pszText)

End With

Call SendMessage(hHeader, HDM_INSERTITEM, itemNo, HDI)

End Sub

Private Function HeaderProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

On Error Resume Next

Dim ProcOld As Long, lstHandle As Long, lWrk As Long, TabArray() As Long, rct As RECT

Call GetCtlByKey(hwnd, ProcOld, lstHandle)

HeaderProc = CallWindowProc(ProcOld, hwnd, Msg, wParam, lParam)

If Msg = &HF Then

lWrk = SendMessage(hwnd, HDM_GETITEMCOUNT, &H0, ByVal &H0)

ReDim TabArray(lWrk - &H2)

For lWrk = 0 To lWrk - &H2

Call SendMessage(hwnd, HDM_GETITEMRECT, lWrk, rct)

TabArray(lWrk) = rct.Right / 1.5

Next

Call S

Ответить

Номер ответа: 10
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #10
Добавлено: 06.01.04 00:55

' Так, я че-то не понял, какого хрена этот форум мой код обрезает %(((

' Продолжение модуля!!!



TabArray(lWrk) = rct.Right / 1.5

Next

Call SendMessage(lstHandle, LB_SETTABSTOPS, &H0, ByVal 0&)

Call SendMessage(lstHandle, LB_SETTABSTOPS, 2, TabArray(0))

Call SendMessage(lstHandle, &HB, WM_SETREDRAW, ByVal &H0)

End If

End Function

Private Function FindCtlByKey(ByVal hwnd As Long) As Integer

On Error GoTo er

Dim fk As Long: FindCtlByKey = &HFFFF

For fk = 0 To UBoundCtl

If hwnd = ctlData(fk).hwnd Then FindCtlByKey = fk: Exit For

Next

er:

End Function

Private Function AddCtl(ByVal BaseProc As Long, _

ByVal hwnd As Long, _

ByVal lstHandle As Long)

On Error GoTo er

Dim Index As Integer: Index = UBoundCtl + &H1

ReDim Preserve ctlData(Index)

With ctlData(Index)

.BaseProc = BaseProc

.hwnd = hwnd

.lstHandle = lstHandle

End With

AddCtl = Index

er:

End Function

Private Function RemoveCtl(ByVal Index As Integer) As Integer

On Error GoTo er

Dim ub As Long: ub = UBoundCtl

If Not ub = 0 And Not ub = &HFFFF Then

Call CopyMemory(ctlData(Index), ctlData(Index + 1), &HE * (ub - Index)) ' &HE - размер структуры

Else

Erase ctlData

End If

er:

End Function

Private Function GetCtlByKey(ByVal hwnd As Long, _

ByRef BaseProc As Long, _

Optional ByRef lstHandle As Long)

GetCtlByKey = FindCtlByKey(hwnd)

If GetCtlByKey = &HFFFF Then Exit Function

With ctlData(GetCtlByKey)

BaseProc = .BaseProc

hwnd = .hwnd

lstHandle = .lstHandle

End With

End Function

Private Function UBoundCtl() As Long

On Error GoTo er

UBoundCtl = UBound(ctlData)

Exit Function

er: UBoundCtl = &HFFFF

End Function

Ответить

Номер ответа: 11
Автор ответа:
 Smith



ICQ: adamis@list.ru 

Вопросов: 153
Ответов: 3632
 Профиль | | #11 Добавлено: 06.01.04 01:08

Лугче просто использовать контрол ListView. Он прикольней!

Ответить

Номер ответа: 12
Автор ответа:
 Smith



ICQ: adamis@list.ru 

Вопросов: 153
Ответов: 3632
 Профиль | | #12 Добавлено: 06.01.04 01:13
Это был ответ на 2-ой вопрос!

Ответить

Номер ответа: 13
Автор ответа:
 sne



Разработчик Offline Client

ICQ: 233286456 

Вопросов: 34
Ответов: 5445
 Web-сайт: hw.t-k.ru
 Профиль | | #13
Добавлено: 06.01.04 02:17

Кого прикалывает полтора метра за своей прогой таскать, прикалывайтесь на здоровье, и вообще WinAPI рулит!!! Кто не согласен, извиняйте... скоро и вы это поймете!

Ответить

Номер ответа: 14
Автор ответа:
 NovichoK



Вопросов: 72
Ответов: 147
 Профиль | | #14 Добавлено: 06.01.04 14:03

Спасибо sne, sharp!

to Sharp:

Что еще за моноширный шрифт?

Ответить

Номер ответа: 15
Автор ответа:
 Sharp


Лидер форума

ICQ: 216865379 

Вопросов: 106
Ответов: 9979
 Web-сайт: sharpc.livejournal.com
 Профиль | | #15
Добавлено: 06.01.04 14:53

Гы... насмешил... Моноширинный шрифт - шрифт с символами равной ширины: Courier, Courier New, Lucida Console, FixedSys, Terminal etc

Ответить

Страница: 1 | 2 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам