本文介绍了表单或用户控件的物理地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!





我正在制作一个包含多种表格和用户版权的程序,但我在这里面临一个问题,



如何才能获得我现在正在使用的表格的实际地址?



另外1:

我的意思是有一个属性动态地给我一个表单或用户控件的物理地址,当我使用它时,它给我在属性菜单中的Full Path框中写的地址,并且我可以像以下一样使用它:



Hi,

I'm making a program with several forms and usercontorls, But there is a problem I face here,

How can I get the Physical address of a form that I'm working in it right now?

Addition 1:
I mean is there a property that dynamically give me the physical address of a form or usercontrol, that when I use it, it give me the address written in the box of "Full Path" inside the properties menu, and I could use it like:

Dim myaddress as string = me.FullPath





增加2:

在解决方案资源管理器中,当您选择表格或用户控制甚至图像文件或文件夹等文件时,在您单击它并选择属性后,在属性菜单中,您会看到一行,其中包含该行的完整路径文件(完整路径),现在我正在寻找一种在程序中动态访问该属性的方法,例如编写



Addition 2:
In the solution explorer when you select a file such as form or usercontrol or even image file or a foler, after you righ-click on it and select properties, in the properties menu you see a row which includes the full path of that file (Full Path), Now I'm looking for a way to access that property dynamicaly inside the program, like writing

return me.FullPath

并返回文件的完整路径。



我尝试过:



到目前为止,我正在阅读MSDN并试图找到一个属性,该属性为我提供了用户控件的物理地址或一个表格。

and it returns the full path of the file.

What I have tried:

So far I'm reading the MSDN and trying to find a property that gives me the physical address of the usercontrol or a form.

推荐答案

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.


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


这篇关于表单或用户控件的物理地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 07:10