200分求一小段代码淂翻译 c# - vb.net
public class GetFileNameClass
{
[DllImport( "user32.dll" )]
private static extern IntPtr GetForegroundWindow();
FolderBrowserDialog _oFileDialog;
// Properties
public string FileName
{
get { return _oFileDialog.SelectedPath; }
set { _oFileDialog.SelectedPath = value; }
}
// public string InitialDirectory
// {
// get { return _oFileDialog.InitialDirectory; }
// set { _oFileDialog.InitialDirectory = value; }
// }
// Constructor
public GetFileNameClass()
{
_oFileDialog = new FolderBrowserDialog();
}
// Methods
public void GetFileName()
{
IntPtr ptr = GetForegroundWindow();
WindowWrapper oWindow = new WindowWrapper(ptr);
if (_oFileDialog.ShowDialog(oWindow) != DialogResult.OK)
{
_oFileDialog.SelectedPath = string.Empty;
}
oWindow = null;
}
}
public class WindowWrapper : System.Windows.Forms.IWin32Window
{
private IntPtr _hwnd;
// Property
public virtual IntPtr Handle
{
get { return _hwnd; }
}
// Constructor
public WindowWrapper(IntPtr handle)
{
_hwnd = handle;
}
}
谢谢
问题点数:200、回复次数:11Top
1 楼yf1025(小桥,流水,人家)回复于 2006-03-20 14:20:26 得分 100
Public Class GetFileNameClass
<DllImport("user32.dll")> _
private static extern IntPtr GetForegroundWindow()
Dim _oFileDialog As FolderBrowserDialog
' Properties
Public Property FileName() As String
Get
Return _oFileDialog.SelectedPath
End Get
Set (ByVal Value As String)
_oFileDialog.SelectedPath = value
End Set
End Property
' public string InitialDirectory
' {
' get { return _oFileDialog.InitialDirectory; }
' set { _oFileDialog.InitialDirectory = value; }
' }
' Constructor
Public Sub New()
_oFileDialog = New FolderBrowserDialog()
End Sub
' Methods
Public Sub GetFileName()
Dim ptr As IntPtr = GetForegroundWindow()
Dim oWindow As WindowWrapper = New WindowWrapper(ptr)
If _oFileDialog.ShowDialog(oWindow) <> DialogResult.OK Then
_oFileDialog.SelectedPath = String.Empty
End If
oWindow = Nothing
End Sub
End Class
Public Class WindowWrapper
Inherits System.Windows.Forms.IWin32Window
Private _hwnd As IntPtr
' Property
Public Overridable ReadOnly Property Handle() As IntPtr
Get
Return _hwnd
End Get
End Property
' Constructor
Public Sub New(ByVal handle As IntPtr)
_hwnd = handle
End Sub
End ClassTop
2 楼lyhold(让你飞)回复于 2006-03-20 14:28:51 得分 0
楼上淂兄弟,对不起,又几处错误能编译不过去Top
3 楼Mittermeyer(疾风之狼)回复于 2006-03-20 14:37:12 得分 20
在当前系统的前台窗口前显示一个FileDialog。
应该没有其他意思了。Top
4 楼BookSirSwordsMan(书生剑客)回复于 2006-03-20 14:42:04 得分 0
网上有那么多的软件可以转换从C#-VB.NET,从VB.NET-C#Top
5 楼lyhold(让你飞)回复于 2006-03-20 14:45:42 得分 0
但是感觉转换淂效果不好,编译不过去,而且运行淂结果跟C#不一样Top
6 楼wxdl1981(沉默之狼)回复于 2006-03-20 14:56:53 得分 0
楼主可真会偷懒啊!Top
7 楼20011521()回复于 2006-03-20 14:59:29 得分 0
我们公司有买了一个老外的
100美圆转得很好Top
8 楼20011521()回复于 2006-03-20 14:59:58 得分 0
现在找不到了那个转换的工具了Top
9 楼lyhold(让你飞)回复于 2006-03-20 15:04:08 得分 0
楼上的兄弟能帮个忙吗?Top
10 楼lyhold(让你飞)回复于 2006-03-21 10:25:48 得分 0
[DllImport("user32.dll", EntryPoint="GetForegroundWindow")]
public static extern int GetForegroundWindow ();
vb.net应该怎么写!谢谢!
[DllImport("user32.dll", EntryPoint="GetForegroundWindow")]
public static extern int GetForegroundWindow ();
vb.net应该怎么写!谢谢!Top
11 楼independently(我是风筝高高飞)回复于 2006-03-21 10:46:17 得分 80
DllImport("user32.dll", EntryPoint:="GetForegroundWindow")= _
Private Shared Function GetForegroundWindow() As IntPtr
End Function
Top




