首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

支持多国语言的combox(开源),该如何处理

2012-02-15 
支持多国语言的combox(开源)最近做产品一直被combox不支持多国语言的问题困扰,得到了csdn不少兄弟的帮助,

支持多国语言的combox(开源)
最近做产品一直被combox不支持多国语言的问题困扰,得到了csdn不少兄弟的帮助,很遗憾最终也没能完美解决,索性用自己有限的水平写一个ocx,继承了vb自带combox的主要方法属性,实现原理非常简单,richtexbox+combox组合
但是现在有一个问题,在引用ocx后,在ocx的事件中写入代码的时候,总是提示运行时错误330,非法参数。因为不支持持久性不能写对象
(只写了一个dropdown事件)
抛块砖,希望能引出高手的玉,完善的有分
以下是代码:

Option   Explicit

Private   iMaxLength   As   Integer
Private   iWidth,   iHeight   As   Integer
Private   Const   blnEnabled   As   Boolean   =   True
Private   Const   blnLocked   As   Boolean   =   False

Public   Event   DropDown()

Property   Get   Text()   As   String
Text   =   cmbBox.Text
End   Property

Property   Let   Text(ByVal   str   As   String)
cmbBox.Text   =   str
End   Property

Property   Get   ListIndex()   As   Integer
ListIndex   =   cmbBox.ListIndex
End   Property

Property   Let   ListIndex(ByVal   i   As   Integer)
cmbBox.ListIndex   =   i
End   Property

Property   Get   List(i   As   Integer)   As   String
List   =   cmbBox.List(i)   &   " "
End   Property

Property   Get   ListCount()   As   Integer
ListCount   =   cmbBox.ListCount
End   Property

Property   Get   Enabled()   As   Boolean
Enabled   =   UserControl.Enabled
End   Property

Property   Let   Enabled(ByVal   bln   As   Boolean)
UserControl.Enabled   =   bln
cmbBox.Enabled   =   bln
End   Property

Property   Get   Locked()   As   Boolean
Locked   =   cmbBox.Locked
End   Property

Property   Let   Locked(ByVal   bln   As   Boolean)
cmbBox.Locked   =   bln
txtRich.Locked   =   bln
End   Property

Public   Function   AddItem(   _
                                                ByRef   sText   As   String,   _
                                                Optional   ByVal   iIndex   As   Long)
cmbBox.AddItem   sText,   iIndex
End   Function

Public   Sub   Clear()
cmbBox.Clear
txtRich.Text   =   " "
End   Sub

Private   Sub   cmbbox_Click()
txtRich.Text   =   cmbBox.Text
End   Sub

Private   Sub   cmbBox_DropDown()
RaiseEvent   DropDown
End   Sub

Private   Sub   txtRich_Change()
cmbBox.Text   =   txtRich.Text
End   Sub

Private   Sub   UserControl_Initialize()
txtRich.ZOrder   1
End   Sub

Private   Sub   UserControl_ReadProperties(PropBag   As   PropertyBag)
iWidth   =   PropBag.ReadProperty( "Width ",   cmbBox.Width)
UserControl.Enabled   =   PropBag.ReadProperty( "Enabled ",   blnEnabled)
cmbBox.Enabled   =   UserControl.Enabled
cmbBox.Locked   =   PropBag.ReadProperty( "Locked ",   blnLocked)


txtRich.Locked   =   PropBag.ReadProperty( "Locked ",   blnLocked)
End   Sub

Private   Sub   UserControl_Resize()
cmbBox.Left   =   0
cmbBox.Top   =   0
cmbBox.Width   =   UserControl.Width
UserControl.Height   =   cmbBox.Height
txtRich.Top   =   cmbBox.Top   +   30
txtRich.Left   =   cmbBox.Left   +   30
txtRich.Width   =   cmbBox.Width   -   300
txtRich.Height   =   cmbBox.Height   -   txtRich.Top   *   2
End   Sub

Private   Sub   UserControl_WriteProperties(PropBag   As   PropertyBag)
Call   PropBag.WriteProperty( "Width ",   iWidth,   cmbBox.Width)
Call   PropBag.WriteProperty( "Enabled ",   UserControl.Enabled,   blnEnabled)
Call   PropBag.WriteProperty( "Locked ",   cmbBox,   blnLocked)
Call   PropBag.WriteProperty( "Locked ",   txtRich,   blnLocked)
End   Sub

有兴趣的留下mail我发源程序

[解决办法]
http://community.csdn.net/Expert/TopicView3.asp?id=5562793
[解决办法]
DROPDOWN事件不应该出错,而 "因为不支持持久性不能写对象 "是因为下面的代码有问题:
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty( "Locked ", cmbBox, blnLocked)
Call PropBag.WriteProperty( "Locked ", txtRich, blnLocked)
End Sub

你试试改成下面这样:
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty( "Locked ", cmbBox.Locked, blnLocked)
Call PropBag.WriteProperty( "Locked ", txtRich.Locked, blnLocked)
End Sub

热点排行