有问题请教大家
问题如下,自定义控件实现了两个属性,一个是ListItem,该属性是数组,另一个属性是FileName。
请问:
一、如何让ListItem属性在设计时能够像VB的ListBox控件的List属性那样,在属性窗口可以对此属性输入多行文字?
二、如何让FileName属性在设计时能够像VB的PictureBox的Picture属性那样,设置该属性时可以弹出文件选择对话框?
在此先谢了!
[解决办法]
既然是自定义控件,应该可以多加上这么两个控件在里面吧(ListBox,PictureBox)
[解决办法]
很少做控件,帮顶...
[解决办法]
[解决办法]
第二个是不是可以参照下combobox的点击事件,或者干脆加个按钮,点击触发事件。呵呵~~~个人想法
[解决办法]
帮顶.
FileName应该可以使用属性页完成,但那个下拉列表就不清楚了.....
[解决办法]
自定义的?
你要他干什么他就干什么。
nnd,考试么?
sugar
[解决办法]
看看这样行不行
- VB code
Dim MyList() As StringDim m_ListCount As LongDim RunMode As BooleanPublic Property Get ListCount() As Integer ListCount = m_ListCountEnd Property#If RunMode Then '运行模式 Public Property Get List(ByVal Index As Integer) As String If Index < m_ListCount Then List = MyList(Index) End If UserControl_Resize End Property#Else '设计模式 Public Property Get List() As String Dim X As Long Dim ReturnStr As String For X = 0 To m_ListCount - 1 If X = 0 Then ReturnStr = MyList(X) Else ReturnStr = ReturnStr & vbCrLf & MyList(X) End If Next X List = ReturnStr End Property Public Property Let List(ByVal vNewValue As String) If Len(vNewValue) = 0 Then Erase MyList m_ListCount = 0 Else MyList = Split(vNewValue, vbCrLf) On Error Resume Next m_ListCount = UBound(MyList) If Err.Number <> 0 Then m_ListCount = 0 Else m_ListCount = m_ListCount + 1 End If End If UserControl_Resize End Property#End IfPublic Sub AddItem(Item As String) On Error Resume Next m_ListCount = UBound(MyList) If Err.Number <> 0 Then m_ListCount = 0 ReDim MyList(m_ListCount) Else m_ListCount = m_ListCount + 1 ReDim Preserve MyList(m_ListCount) End If MyList(m_ListCount) = New_List m_ListCount = m_ListCount + 1 UserControl_ResizeEnd SubPrivate Sub UserControl_Resize() UserControl.Cls Dim X As Long If m_ListCount > 0 Then For X = 0 To m_ListCount - 1 Print MyList(X) Next X End IfEnd SubPrivate Sub UserControl_Show() RunMode = Ambient.UserModeEnd Sub
[解决办法]
春春新年好
[解决办法]
仔细看了一下还是不行
主要是运行时和设计时老是弄不好
- VB code
Dim MyList() As StringDim m_ListCount As LongDim RunMode As BooleanPublic Property Get ListCount() As Integer ListCount = m_ListCountEnd Property#If RunMode Then '运行模式 Public Property Get List(ByVal Index As Integer) As String If Index < m_ListCount Then List = MyList(Index) End If UserControl_Resize End Property Public Property Let List(ByVal Index As Integer, ByVal vNewValue As String) If Index < m_ListCount Then MyList(Index) = vNewValue End If UserControl_Resize End Property#Else '设计模式 Public Property Get List() As String Dim X As Long Dim ReturnStr As String For X = 0 To m_ListCount - 1 If X = 0 Then ReturnStr = MyList(X) Else ReturnStr = ReturnStr & vbCrLf & MyList(X) End If Next X List = ReturnStr End Property Public Property Let List(ByVal vNewValue As String) If Len(vNewValue) = 0 Then Erase MyList m_ListCount = 0 Else MyList = Split(vNewValue, vbCrLf) On Error Resume Next m_ListCount = UBound(MyList) If Err.Number <> 0 Then m_ListCount = 0 Else m_ListCount = m_ListCount + 1 End If PropertyChanged "ListCount" End If UserControl_Resize End Property#End IfPublic Sub AddItem(Item As String) On Error Resume Next m_ListCount = UBound(MyList) If Err.Number <> 0 Then m_ListCount = 0 ReDim MyList(m_ListCount) Else m_ListCount = m_ListCount + 1 ReDim Preserve MyList(m_ListCount) End If MyList(m_ListCount) = Item m_ListCount = m_ListCount + 1 RunMode = Ambient.UserMode UserControl_ResizeEnd SubPrivate Sub UserControl_InitProperties() RunMode = Ambient.UserModeEnd SubPrivate Sub UserControl_Resize() UserControl.Cls Dim X As Long Print RunMode If m_ListCount > 0 Then For X = 0 To m_ListCount - 1 Print MyList(X) Next X End IfEnd Sub'从存贮器中加载属性值Private Sub UserControl_ReadProperties(PropBag As PropertyBag) Dim X As Integer m_ListCount = PropBag.ReadProperty("ListCount", 0) If m_ListCount >= 1 Then ReDim MyList(m_ListCount - 1) For X = 0 To m_ListCount - 1 MyList(X) = PropBag.ReadProperty("List" & X, "") Next X End IfEnd Sub'将属性值写到存储器Private Sub UserControl_WriteProperties(PropBag As PropertyBag) Dim X As Integer Call PropBag.WriteProperty("ListCount", m_ListCount, 0) For X = 0 To m_ListCount - 1 Call PropBag.WriteProperty("List" & X, MyList(X), "") Next XEnd Sub
[解决办法]
江南兄的帖子,一定要顶!
[解决办法]
VB大侠们,学习了
[解决办法]
举例说明:
1.需要先启用vb6 ActiveX 控件接口向导添加接口
2.需要添加属性页设计向导设计属性页,再属性页的PropertyPage_Initialize事件里加上下面的代码,
CommonDialog1.ShowOpen
Text1.Text = CommonDialog1.FileName
[解决办法]
这两个功能做过的人应该不是很多,估计江南同学直接去微软论坛比较理想:
http://social.microsoft.com/Forums/zh-CN/category/visualstudio