且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

表单或用户控件的物理地址

更新时间:2023-12-06 07:54:22

不确定这是否符合你的要求,以及它是否适合制作。

无论如何也许你尝试并获得一些想法。



使用System.Runtime.CompilerServices:

Not sure whether this does match your request and also whether it is a good idea for production.
Anyway maybe you try it and get some ideas.

Use System.Runtime.CompilerServices for this:
using System.Runtime.CompilerServices;

namespace LogTests
{
    public static class LogTest
    {
        public static string Log(string infoText,
                                [CallerFilePath] string file = "",
                                [CallerMemberName] string member = "",
                                [CallerLineNumber] int line = 0)
        {
            string test = string.Format("File= {0} Member= {1} Line= {2} InfoText= {3}", file, member, line, infoText);
            return (test);
        }
    }
}





MyControl做了类似的事情:



MyControl has do do something like this:

namespace MyControls
{
    public class MyControl
    {
        // ...
        private void PathTest()
        {
            string test = LogTest.Log("MyControl");
        }
        // ....
    }
}





我希望它有所帮助。



I hope it helps.


如果我理解了问题的正确答案是:反思。

使用下面的代码,您可以在应用程序内搜索所需的对象并获取其名称。



If I understood the question right the answer is : Reflection.
With the code below you could search inside your Application for the required objects and get their name.

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
        Dim t() As Type = a.GetTypes()

        For Each ty As Type In t
            If ty.BaseType.Name = "Form" Then
                MessageBox.Show(ty.Name)
            End If
        Next

    End Sub
End Class





使用Reflection也可以获得a的属性指定的对象类型 - 但不是你想象的那样。

要完成这个,你应该提供更多信息......你的最终目标是什么?



Also with Reflection you can get the Properties of a specified Object-Type - but not in the way you think.
To complete this you should provide much more Information ... what is your final Goal ?


使用
Server.MapPath

Path.GetFullPath