Explorerpfad in Textfeld schreiben
Daniel Gesk
Hallo zusammen,ich habe die unten stehende Lösung ausprobiert, um einen Pfad in ein Textfeld auf einer Form einzutragen.
Das Dialogfenster von Windows öffnet sich, jedoch kann ich nur Dateien und [u][u]keine Ordner[/u][/u] auswählen.
Mache ich hier grundsätzlich etwas falsch? Vielen Dank für alle Hilfe!!
Hier der Code:
SwissAddonFramework.Utils.Windows.OpenFileDialog ofd = new SwissAddonFramework.Utils.Windows.OpenFileDialog();
ofd.FileSetEvent += new SwissAddonFramework.Utils.Windows.OpenFileDialog.FileSetHandler(delegate(string path)
{
ExtendedTextEdit.GetFromUID(pVal.Form, "FilePath").Value = path;
});
ofd.ShowDialog();
Daniel Gesk
Hallo zusammen,ich habe die Lösung gefunden. Hier der (extended) code:
[u]Globale Methoden und Variablen:[/u]
public string Zielpfad = "";
private System.Windows.Forms.FolderBrowserDialog objDialog = new System.Windows.Forms.FolderBrowserDialog();
public Form Eingabemaske;
public void ShowDialog(Form pEingabemaske)
{
Eingabemaske = pEingabemaske;
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(Open));
t.TrySetApartmentState(System.Threading.ApartmentState.STA);
t.Start();
}
public void Open()
{
Zielpfad = "";
WindowWrapper sap = new WindowWrapper ();
if (objDialog.ShowDialog(sap) == System.Windows.Forms.DialogResult.OK)
{
Zielpfad = objDialog.SelectedPath + "\\";
customize.UI.Components.ExtendedTextEdit.GetFromUID(Eingabemaske, "FilePath").Value = Zielpfad;
}
}
internal class WindowWrapper : System.Windows.Forms.IWin32Window
{
[DllImport("user32.dll")]
protected static extern int GetForegroundWindow();
public WindowWrapper ()
{
_hwnd = (IntPtr) GetForegroundWindow();
}
public IntPtr Handle
{
get { return _hwnd; }
}
private IntPtr _hwnd;
}
[u]Verwendungs- und Importanweisungen:[/u]
using System.Runtime.InteropServices;
Daniel Gesk
0
Please sign in to leave a comment.
Comments
0 comments