【问题标题】:Visual Basic 2010 Finding objects at a point on the formVisual Basic 2010 在表单上的某个点查找对象
【发布时间】:2013-07-25 14:25:11
【问题描述】:

所以我一直在 Visual Basic 2010 中进行一些编程。对于我的程序,我需要确定主窗体上的某个点是否有对象 [例如 (20, 35)]。我试过了:

Dim ObjectFind as object   
ObjectFind = Me.GetChildAtPoint(20, 35)

我不确定这是否有效,ObjectFind 通常等于 {System.Windows.Forms.Form} 所以我想如果 ObjectFind 不等于 {System.Windows.Forms.Form} 那我那里会有一个不同的对象,所以我做了:

If ObjectFind <> System.Windows.Forms.Form then  
    ' Code is here  
end if 

但 Visual Basic 说 System.Windows.Forms.Form 不能在条件下使用。 我做了很多研究,但在 Visual Basic 中的某个点上,我没有找到太多关于如何找到对象的信息。

我也试过了:

If ObjectFind.Equals(System.Windows.Forms.Form) = false then  
    ' Code is here  
end if  

我遇到了和以前一样的错误。
由于 System.Windows.Forms.Form 是我尝试的主要形式:

If ObjectFind.Equals(Me) = false then  
    ' Code is here  
end if  

但是无论什么对象在 (20, 35) 处,它总是错误的

如果您不确定我的问题是:如何确定 Visual Basic 2010 中表单上的某个点是否有对象?

【问题讨论】:

  • 您说,“我需要确定主窗体上的某个点是否有对象……”您所说的对象是指某种控件吗?

标签: vb.net visual-studio-2010 object


【解决方案1】:

这是在 VB.NET 中测试对象是否为特定类型的方法:

If TypeOf ObjectFind Is System.Windows.Forms.Form then

【讨论】:

    【解决方案2】:

    如果使用以下内容,则代替第一个:

    If ObjectFind.GetType() <> GetType(System.Windows.Forms.Form) Then
    
    End If
    

    【讨论】:

    • 这种进行类型比较的方法在测试项目中对我不起作用。可能是因为在我的情况下,ObjectFind 是从一个表单派生的,而不仅仅是一个表单。不得不使用这个:If ObjectFind.GetType.IsSubclassOf(GetType(Form)) Then.
    猜你喜欢
    • 2012-11-01
    • 2016-12-17
    • 2021-11-23
    • 1970-01-01
    • 2011-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-22
    相关资源
    最近更新 更多