确定发件人是哪个表格 [英] Determine which form was the sender

查看:100
本文介绍了确定发件人是哪个表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有Web浏览器的表单(form1),可以用许多表单打开.根据打开该表单的形式,Web浏览器将打开一个不同的URL.

我尝试过这样的事情

I have a form (form1) with a webbrowser which can be opened by many forms. Depending on which form opens this form the webbrowser will open to a different URL.

I tried something like this

If sender Is frmRegInState Then
            Me.WebBrowser1.Url.ToString = ("www.yahoo.com") Then
            frmRegInState.Close()
        ElseIf sender Is frmRegOutOfState Then
            Me.WebBrowser1.Url.ToString = ("www.google.com") Then
            frmRegOutOfState.Close()
        End If

推荐答案

使用这样的url属性创建一个接口:
Create an interface with a url property like this :
public interface IUrlOwner
    {
        Uri Url
        {
            get;
            set;
        }
    }



然后使您的表单实现此接口.因此,表单将知道要打开哪个URL.
像这样:



Then make your form implement this interface. So the form will know which url to open.
like this :

public partial class DrawingWindow : Form,IUrlOwner 


当然,您必须实现该接口.所以您需要一个具体的吸气剂和吸气剂.
然后,您可以将发送方强制转换为接口,并在事件处理程序中获取url.


Of course you have to implement the interface. so you need a concrete getter and setter.
Then you can cast the sender to the interface and get to the url in your event handler.

(sender as IUrlOwner)Url



我的代码更像C#,但我希望您对VB.NET有足够的了解,以了解此处发生的情况.



My code is more like C# but I hope you know enough about VB.NET to understand what is going on here.


这篇关于确定发件人是哪个表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆