Symbian CAknSingleStyleListBox 使用教程

需积分: 0 10 下载量 158 浏览量 更新于2024-10-24 收藏 126KB PDF 举报
"Symbian ListBox使用.pdf" 在Symbian操作系统中,ListBox是一个重要的用户界面组件,用于显示可滚动的项目列表。这篇教程主要讲解了如何在Symbian平台上使用CAknSingleStyleListBox,这是一种简单风格的ListBox实现,适合新手入门。 首先,你需要声明一个CAknSingleStyleListBox类型的指针,例如`CAknSingleStyleListBox *iListBox`。在容器类(如CUniNewsAppContainer)的构造函数`ConstructL()`中创建这个ListBox实例。创建过程包括: 1. 在适当位置调用`new(ELeave)`来分配内存并创建ListBox对象。 2. 使用`SetContainerWindowL(*this)`将当前窗口设置为ListBox的容器窗口。 3. 设置ListBox的观察者,通常是你自己创建的类,以便监听ListBox的事件,这里通过`SetListBoxObserver(this)`实现。 4. 调用`ConstructL()`方法初始化ListBox,传入父窗口(this)以及一些风格标志,例如`EAknListBoxSelectionList`表示允许选择列表项,`EAknListBoxLoopScrolling`表示循环滚动。 5. 创建滚动条框架`CreateScrollBarFrameL(ETrue)`,并设置滚动条的可见性`SetScrollBarVisibilityL(CEikScrollBarFrame::EOn, CEikScrollBarFrame::EOn)`,使得水平和垂直滚动条都可见。 6. 通过`ItemDrawer()->ColumnData()->EnableMarqueeL(ETrue)`开启文本的马拉松效果,当文本过长时,会在水平方向上滚动显示。 7. 最后,设置ListBox的矩形区域`SetRect(aRect)`,并调整容器自身的矩形区域`SetRect(aRect)`,确保ListBox占据整个主面板。 初始化ListBox后,需要添加内容到列表中。这通常通过调用`InsertItemL()`或`AppendItemL()`方法实现。例如,你可以创建一个TDes字符串来存储列表项文本,然后传递给这些方法。如果需要自定义列表项的显示,可能还需要重写`CEikListBox::DrawItem()`方法。 在Symbian的UI编程中,ListBox通常用于展示数据列表,如联系人、短信等。理解如何创建、配置和更新ListBox对于开发Symbian应用是至关重要的。通过熟练掌握CAknSingleStyleListBox,开发者可以进一步学习更复杂的ListBox实现,如CAknListbox和CAknMultiStyleListBox,以满足更丰富的用户界面需求。

帮我合并以下宏程序 Private Sub Worksheet_Change(ByVal Target As Range) Dim rng As Range, cell As Range Dim arr() As Variant Dim cnt As Long Dim isCopying As Boolean ' 如果B1单元格为空,直接退出Sub过程 If Me.Range("B1").Value = "" Then Exit Sub If Not Intersect(Target, Me.Range("B1")) Is Nothing Then Sheets("点位提取").Range("C5:C200").ClearContents If Me.Range("AH34").Value = True Then Me.ListBox1.AddItem "数据已被清空 " & Format(Now, "hh:mm:ss") Me.ListBox1.ListIndex = Me.ListBox1.ListCount - 1 End If Set rng = Me.Range("B1:B2000") cnt = 0 isCopying = False For Each cell In rng If cell.Value = ":BEGIN" Then isCopying = True ReDim arr(2000) If Me.Range("AH34").Value = True Then Me.ListBox1.AddItem "开始提取数据 " & Format(Now, "hh:mm:ss") Me.ListBox1.ListIndex = Me.ListBox1.ListCount - 1 End If ElseIf cell.Value = ":END" Then isCopying = False ReDim Preserve arr(cnt - 1) Sheets("点位提取").Range("C5").Resize(cnt, 1).Value = Application.Transpose(arr) If Me.Range("AH34").Value = True Then Me.ListBox1.AddItem "数据已进行提取完毕 " & Format(Now, "hh:mm:ss") Me.ListBox1.ListIndex = Me.ListBox1.ListCount - 1 End If Exit For End If If isCopying And cell.Value <> ":BEGIN" Then arr(cnt) = rng.Cells(cell.Row, 1).Value cnt = cnt + 1 End If Next cell End If On Error GoTo ErrorHandler Exit Sub ErrorHandler: If Me.Range("AH36").Value = True Then Me.ListBox2.AddItem Err.Description & " " & Format(Now, "hh:mm:ss") Me.ListBox2.ListIndex = Me.ListBox2.ListCount - 1 End If End Sub Private Sub Worksheet_Change(ByVal Target As Range) Dim i As Integer Dim j As Integer Dim k As Integer Dim ws As Worksheet Set ws = ActiveSheet If Target.Address = "$B$2" Then For i = 9 To 40 For j = 2 To 7 If ws.Cells(i, j).Value = ws.Cells(8, 5).Value Then For k = 3 To 4 ws.Cells(i, j + k - 2).Value = ws.Cells(Application.Match(ws.Cells(i, 1).Value, ws.Range("AK9:AK40"), 0) + 8, k).Value Next k End If Next j Next i End If End Sub

2023-05-15 上传

在以下宏中帮我把查找结果输出到对应的AL9-EG40单元格中 Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) Dim rng As Range, cell As Range Dim arr() As Variant Dim cnt As Long Dim isCopying As Boolean Dim i As Integer Dim j As Integer Dim k As Integer Dim ws As Worksheet Set ws = ActiveSheet ' 如果B1单元格为空,直接退出Sub过程 If Me.Range("B1").Value = "" Then Exit Sub If Not Intersect(Target, Me.Range("B1")) Is Nothing Then Sheets("点位提取").Range("C5:C200").ClearContents If Me.Range("AH34").Value = True Then Me.ListBox1.AddItem "数据已被清空 " & Format(Now, "hh:mm:ss") Me.ListBox1.ListIndex = Me.ListBox1.ListCount - 1 End If Set rng = Me.Range("B1:B2000") cnt = 0 isCopying = False For Each cell In rng If cell.Value = ":BEGIN" Then isCopying = True ReDim arr(2000) If Me.Range("AH34").Value = True Then Me.ListBox1.AddItem "开始提取数据 " & Format(Now, "hh:mm:ss") Me.ListBox1.ListIndex = Me.ListBox1.ListCount - 1 End If ElseIf cell.Value = ":END" Then isCopying = False ReDim Preserve arr(cnt - 1) Sheets("点位提取").Range("C5").Resize(cnt, 1).Value = Application.Transpose(arr) If Me.Range("AH34").Value = True Then Me.ListBox1.AddItem "数据已进行提取完毕 " & Format(Now, "hh:mm:ss") Me.ListBox1.ListIndex = Me.ListBox1.ListCount - 1 End If Exit For End If If isCopying And cell.Value <> ":BEGIN" Then arr(cnt) = rng.Cells(cell.Row, 1).Value cnt = cnt + 1 End If Next cell If Target.Address = "$B$2" Then For i = 9 To 40 For j = 2 To 7 If ws.Cells(i, j).Value = ws.Cells(8, 5).Value Then For k = 3 To 4 ws.Cells(i, j + k - 2).Value = ws.Cells(Application.Match(ws.Cells(i, 1).Value, ws.Range("AK9:AK40"), 0) + 8, k).Value Next k End If Next j Next i End If End If On Error GoTo ErrorHandler Exit Sub ErrorHandler: If Me.Range("AH36").Value = True Then Me.ListBox2.AddItem Err.Description & " " & Format(Now, "hh:mm:ss") Me.ListBox2.ListIndex = Me.ListBox2.ListCount - 1 End If End Sub

2023-05-15 上传