自定义控件type

lsh2216024 2008-11-16 04:19:14
大家好,我做了个控件,正常的可以使用,

只是在用
for each ctl in vControls

if typeof ctl is textbox then

endif
next
運行時的type類型屬於textbox,我真是不明白了,上網查也沒有查到,請大家幫個忙了,怎樣改變自定義控件的type,謝謝了

下面是我的自定義控件代碼
Public Class ucNaturalNumericBox

Public Property InputOut()
Get
Return txtInput.Text.Trim
End Get
Set(ByVal Value)
txtInput.Text = Value
End Set
End Property

Private Sub txtInput_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtInput.KeyPress

If Asc(e.KeyChar) <> Keys.Back And txtInput.Text.Trim.Length = 0 And Asc(e.KeyChar) = Keys.Insert Then
e.Handled = False
ElseIf Asc(e.KeyChar) <> Keys.Back And txtInput.Text = Chr(Keys.D0) Then
e.Handled = True
ElseIf Asc(e.KeyChar) <> Keys.Back And txtInput.Text.Trim = Chr(Keys.Insert) And Asc(e.KeyChar) = Keys.D0 Then
e.Handled = True
ElseIf Asc(e.KeyChar) <> Keys.Back And IsNumeric(e.KeyChar) = False Then
e.Handled = True
End If
End Sub

End Class
...全文
77 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lsh2216024 2008-11-17
  • 打赏
  • 举报
回复
好了,呵呵

dim Ctl as usercontrol

for each ctl in vControls

if typeof ctl is ucNaturalNumericBox then

endif
next
必須把他的類型定義為用戶控件
再次謝謝了!
lsh2216024 2008-11-17
  • 打赏
  • 举报
回复
謝謝了,

我怎么才可以做一個
if typeof ctl is ztextbox then
dim Ctl_ as ZNumeric.ucTest = ctl
endif

謝謝!
oxlshmily 2008-11-17
  • 打赏
  • 举报
回复

if typeof ctl is textbox then
dim ctl as ucNaturalNumericBox
if(ctl!=null)
{
}
end if
end if
lsh2216024 2008-11-16
  • 打赏
  • 举报
回复
應該是我定義的這個控件,VB.net認為是textbox,
就把它轉換成textbox了,
我怎么才可以改變它的類型呢,謝謝了!
lsh2216024 2008-11-16
  • 打赏
  • 举报
回复
謝謝了,
對了,我的工程選項是web控件庫,程序集名稱是
ZNumeric,根命名空間是ZNumeric

我也嘗試過
if typeof ctl is textbox then
dim Ctl_ as ZNumeric.ucTest = ctl
endif

ucNaturalNumericBox tmp = ctrl as ucNaturalNumericBox
vb.net沒有這個語法

可都還是不行啊,再次麻煩你了,謝謝!
长沙三毛 2008-11-16
  • 打赏
  • 举报
回复
C#语言应该是 ctrl is ucNaturalNumericBox 啊。另外,容器控件中可能有其他控件,比较好的、安全的处理方式是:
ucNaturalNumericBox tmp = ctrl as ucNaturalNumericBox
if(tmp != null)
{
}

8,833

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 组件/控件开发
社区管理员
  • 组件/控件开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧