mirror of https://github.com/dahall/Vanara.git
Changed name of ConnectedDeviceCount to ConnectedDeviceNumber. Added ReadOnlyPath property.
parent
9112d0b634
commit
89b933022d
|
@ -14,7 +14,6 @@ namespace Vanara.Windows.Forms
|
||||||
/// <seealso cref="System.Windows.Forms.CommonDialog" />
|
/// <seealso cref="System.Windows.Forms.CommonDialog" />
|
||||||
public class NetworkConnectionDialog : CommonDialog
|
public class NetworkConnectionDialog : CommonDialog
|
||||||
{
|
{
|
||||||
private SafeCoTaskMemHandle lpnres;
|
|
||||||
private NETRESOURCE nres = new NETRESOURCE();
|
private NETRESOURCE nres = new NETRESOURCE();
|
||||||
private CONNECTDLGSTRUCT opts;
|
private CONNECTDLGSTRUCT opts;
|
||||||
|
|
||||||
|
@ -25,10 +24,10 @@ namespace Vanara.Windows.Forms
|
||||||
nres.dwType = NETRESOURCEType.RESOURCETYPE_DISK;
|
nres.dwType = NETRESOURCEType.RESOURCETYPE_DISK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Gets the connected device count. This value is only valid after successfully running the dialog.</summary>
|
/// <summary>Gets the connected device number. This value is only valid after successfully running the dialog.</summary>
|
||||||
/// <value>The connected device count.</value>
|
/// <value>The connected device number. The value is 1 for A:, 2 for B:, 3 for C:, and so on. If the user made a deviceless connection, the value is –1.</value>
|
||||||
[Browsable(false)]
|
[Browsable(false)]
|
||||||
public int ConnectedDeviceCount => opts.dwDevNum;
|
public int ConnectedDeviceNumber => opts.dwDevNum;
|
||||||
|
|
||||||
/// <summary>Gets or sets a value indicating whether to hide the check box allowing the user to restore the connection at logon.</summary>
|
/// <summary>Gets or sets a value indicating whether to hide the check box allowing the user to restore the connection at logon.</summary>
|
||||||
/// <value><c>true</c> if hiding restore connection check box; otherwise, <c>false</c>.</value>
|
/// <value><c>true</c> if hiding restore connection check box; otherwise, <c>false</c>.</value>
|
||||||
|
@ -52,6 +51,14 @@ namespace Vanara.Windows.Forms
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether to display a read-only path instead of allowing the user to type in a path. This is only
|
||||||
|
/// valid if <see cref="RemoteNetworkName"/> is not <see langword="null"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <value><c>true</c> to display a read only path; otherwise, <c>false</c>.</value>
|
||||||
|
[DefaultValue(false), Category("Appearance"), Description("Display a read-only path instead of allowing the user to type in a path.")]
|
||||||
|
public bool ReadOnlyPath { get; set; }
|
||||||
|
|
||||||
/// <summary>Gets or sets the name of the remote network.</summary>
|
/// <summary>Gets or sets the name of the remote network.</summary>
|
||||||
/// <value>The name of the remote network.</value>
|
/// <value>The name of the remote network.</value>
|
||||||
[DefaultValue(null), Category("Behavior"), Description("The value displayed in the path field.")]
|
[DefaultValue(null), Category("Behavior"), Description("The value displayed in the path field.")]
|
||||||
|
@ -78,18 +85,24 @@ namespace Vanara.Windows.Forms
|
||||||
opts.dwDevNum = -1;
|
opts.dwDevNum = -1;
|
||||||
opts.dwFlags = 0;
|
opts.dwFlags = 0;
|
||||||
opts.lpConnRes = IntPtr.Zero;
|
opts.lpConnRes = IntPtr.Zero;
|
||||||
|
ReadOnlyPath = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
protected override bool RunDialog(IntPtr hwndOwner)
|
protected override bool RunDialog(IntPtr hwndOwner)
|
||||||
{
|
{
|
||||||
opts.hwndOwner = hwndOwner;
|
using (var lpnres = SafeCoTaskMemHandle.CreateFromStructure(nres))
|
||||||
lpnres = SafeCoTaskMemHandle.CreateFromStructure(nres);
|
{
|
||||||
opts.lpConnRes = lpnres.DangerousGetHandle();
|
opts.hwndOwner = hwndOwner;
|
||||||
var ret = WNetConnectionDialog1(opts);
|
opts.lpConnRes = lpnres.DangerousGetHandle();
|
||||||
if (ret == -1) return false;
|
if (ReadOnlyPath && !string.IsNullOrEmpty(nres.lpRemoteName))
|
||||||
ret.ThrowIfFailed();
|
opts.dwFlags |= CONN_DLG.CONNDLG_RO_PATH;
|
||||||
return true;
|
var ret = WNetConnectionDialog1(opts);
|
||||||
|
opts.lpConnRes = IntPtr.Zero;
|
||||||
|
if (ret == -1) return false;
|
||||||
|
ret.ThrowIfFailed();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue