一到这里就提示错误,说是找不到图片```郁闷啊```我明明把图片放在了bin\debug\images里面了啊。而且图片名都是以shu开头后面是数字~~~
face是个int变量。
Directory.GetCurrentDirectory()这个函数是返回当前正在执行的目录路径吗?(bin\debug)?
2006-04-15 13:31

2006-04-15 14:38
2006-04-15 16:16
2006-04-15 16:32
2006-04-15 16:34
2006-04-15 16:37
![]() |
![]() |
![]() |
.NET Framework 类库 |
Directory 类 | Directory 成员 | System.IO 命名空间 |
平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列, .NET Framework 精简版 - Windows CE .NET, 公共语言基础结构 (CLI) 标准
.NET Framework 安全性:
获取应用程序的当前工作目录。
[Visual Basic] Public Shared Function GetCurrentDirectory() As String
[C#] public static string GetCurrentDirectory();
[C++] public: static String* GetCurrentDirectory();
[JScript] public static function GetCurrentDirectory() : String;
包含当前工作目录的路径的字符串。
| 异常类型 | 条件 |
|---|---|
| UnauthorizedAccessException | 调用方没有所要求的权限。 |
当前目录不同于原始目录,后者是从其开始进程的目录。
有关使用此方法的示例,请参阅下面的“示例”部分。下表列出了其他典型或相关的 I/O 任务的示例。
| 若要执行此操作... | 请参阅本主题中的示例... |
|---|---|
| 创建文本文件。 | |
| 写入文本文件。 | |
| 读取文本文件。 | |
| 查看目录中的文件。 | Name |
| 查看目录的子目录。 | GetDirectories |
| 查看目录的所有子目录中的所有文件。 | GetFileSystemInfos |
| 查看目录大小。 | Directory |
| 确定文件是否存在。 | Exists |
| 确定目录是否存在。 | Exists |
[Visual Basic, C#, C++] 下面的示例说明 GetCurrentDirectory 方法。
[Visual Basic]
Imports System
Imports System.IO
Public Class Test
Public Shared Sub Main()
Try
' Get the current directory.
Dim path As String = Directory.GetCurrentDirectory()
Dim target As String = "c:\temp"
Console.WriteLine("The current directory is {0}", path)
If Directory.Exists(target) = False Then
Directory.CreateDirectory(target)
End If
' Change the current directory.
Environment.CurrentDirectory = (target)
If path.Equals(Directory.GetCurrentDirectory()) Then
Console.WriteLine("You are in the temp directory.")
Else
Console.WriteLine("You are not in the temp directory.")
End If
Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub
End Class
[C#]
using System;
using System.IO;
class Test
{
public static void Main()
{
try
{
// Get the current directory.
string path = Directory.GetCurrentDirectory();
string target = @"c:\temp";
Console.WriteLine("The current directory is {0}", path);
if (!Directory.Exists(target))
{
Directory.CreateDirectory(target);
}
// Change the current directory.
Environment.CurrentDirectory = (target);
if (path.Equals(Directory.GetCurrentDirectory()))
{
Console.WriteLine("You are in the temp directory.");
}
else
{
Console.WriteLine("You are not in the temp directory.");
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::IO;
void main() {
try {
// Get the current directory.
String* path = Directory::GetCurrentDirectory();
String* target = S"c:\\temp";
Console::WriteLine(S"The current directory is {0}", path);
if (!Directory::Exists(target)) {
Directory::CreateDirectory(target);
}
// Change the current directory.
Environment::CurrentDirectory = target;
if (path->Equals(Directory::GetCurrentDirectory())) {
Console::WriteLine(S"You are in the temp directory.");
} else {
Console::WriteLine(S"You are not in the temp directory.");
}
} catch (Exception* e) {
Console::WriteLine(S"The process failed: {0}", e);
}
}
[JScript] 没有可用于 JScript 的示例。若要查看 Visual Basic、C# 或 C++ 示例,请单击页左上角的“语言筛选器”按钮
。
平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列, .NET Framework 精简版 - Windows CE .NET, 公共语言基础结构 (CLI) 标准
.NET Framework 安全性:
Directory 类 | Directory 成员 | System.IO 命名空间 |

2006-04-15 16:40
[Visual Basic]
Imports System
Imports System.IO
Public Class Test
Public Shared Sub Main()
Try
' Get the current directory.
Dim path As String = Directory.GetCurrentDirectory()
Dim target As String = "c:\temp"
Console.WriteLine("The current directory is {0}", path)
If Directory.Exists(target) = False Then
Directory.CreateDirectory(target)
End If
' Change the current directory.
Environment.CurrentDirectory = (target)
If path.Equals(Directory.GetCurrentDirectory()) Then
Console.WriteLine("You are in the temp directory.")
Else
Console.WriteLine("You are not in the temp directory.")
End If
Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub
End Class
[C#]
using System;
using System.IO;
class Test
{
public static void Main()
{
try
{
// Get the current directory.
string path = Directory.GetCurrentDirectory();
string target = @"c:\temp";
Console.WriteLine("The current directory is {0}", path);
if (!Directory.Exists(target))
{
Directory.CreateDirectory(target);
}
// Change the current directory.
Environment.CurrentDirectory = (target);
if (path.Equals(Directory.GetCurrentDirectory()))
{
Console.WriteLine("You are in the temp directory.");
}
else
{
Console.WriteLine("You are not in the temp directory.");
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
}

2006-04-15 16:43
4楼的朋友说的很好呀。
Application.StartupPath ---获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。
《来自msdn》你可以用一下!
下面的示例获取该属性并在文本框中显示其值。本示例假定 textBox1 已放置在窗体上。
private void PrintStartupPath() {
textBox1.Text = "The path for the executable file that " +
"started the application is: " +
Application.StartupPath;
}

2006-04-15 16:49
2006-04-16 16:07