我试图通过查询所有驱动器来确定远程服务器上的可用空间,然后循环直到找到我正在寻找的驱动器.
有一个更好的方法吗?
Dim oConn As New ConnectionOptions
Dim sNameSpace As String = "\\mnb-content2\root\cimv2"
Dim oMS As New ManagementScope(sNameSpace, oConn)
Dim oQuery As System.Management.ObjectQuery = New System.Management.ObjectQuery("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3")
Dim oSearcher As ManagementObjectSearcher = New ManagementObjectSearcher(oMS, oQuery)
Dim oReturnCollection As ManagementObjectCollection = oSearcher.Get()
Dim oReturn As ManagementObject
For Each oReturn In oReturnCollection
'Disk name
Console.WriteLine("Name : " + oReturn("Name").ToString())
'Free Space in bytes
Dim sFreespace As String = oReturn("FreeSpace").ToString()
If Left(oReturn("Name").ToString(), 1) = "Y" Then
Console.WriteLine(sFreespace)
End If …
Run Code Online (Sandbox Code Playgroud) 我有一个标签显示在一行以上,我想证明其中的文字(左右对齐).实现这一目标的最佳方法是什么?
我知道这个话题已经讨论过很多次了,但我需要了解如何以正确的方式编写代码。
我在协议版本 HTTP 1.1 中多次使用相同的 HttpWebRequest(到相同的 url)。
Method = "POST"
KeepAlive = True
Run Code Online (Sandbox Code Playgroud)
但每次我需要发送不同的请求,并得到不同的响应。
(注意。下一个代码不正确并引发异常)
Private Sub SendHttpWebReq()
Dim httpWebReq = CType(Net.WebRequest.Create("http://www.contoso.com/"), Net.HttpWebRequest)
httpWebReq.Method = "POST"
httpWebReq.KeepAlive = True
httpWebReq.ContentType = "application/x-www-form-urlencoded"
Dim myRequestString As New List(Of String) From {"abc", "def"}
Dim ContentList As New List(Of String)
For a = 0 To 1
Dim inputData As String = MyRequestString(a)
Dim postData As String = "firstone" + ChrW(61) + inputData
Dim encoding As New System.Text.ASCIIEncoding()
Dim byteData As Byte() = encoding.GetBytes(postData) …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个 Windows 窗体应用程序,以 .Net 4.5 作为目标框架。
Label
我注意到的一件事是,如果我在控件上显示日语文本,而Font
标签(Arial)不支持日语字符,那么也Label
可以成功显示这些字符。
如果我在分配日语文本之前和之后检查标签的字体属性,它只会显示“Arial”,因此字体可能不会动态更改。
Label 具有哪些内部功能使其能够实现这一目标?
我有一个包含几个组合框的表单。
我希望其中一个 ComboBox 在从键盘和鼠标获得焦点时打开元素列表。
DroppedDown
ComboBox 类的属性管理元素列表的可见性。
最符合我需求的事件是Enter
,所以我写的代码是:
private void comboBox1_Enter(object sender, EventArgs e)
{
this.comboBox1.DroppedDown = true;
}
Run Code Online (Sandbox Code Playgroud)
它可以工作,但是当直接单击位于组合框右侧没有焦点的图标时,元素列表会打开,并且在打开后突然消失。
我尝试了很多方法来修复这种奇怪的行为,检查Focused
属性或使用其他事件,如DropDown
或MouseClick
,但没有得到任何可接受的结果。
我有一个文本框xaml
:
<TextBox Name="Text" HorizontalAlignment="Left" Height="75" VerticalContentAlignment="Center" TextWrapping="NoWrap" Text="TextBox" Width="336" BorderBrush="Black" FontSize="40" />
Run Code Online (Sandbox Code Playgroud)
我使用此方法向其添加文本:
private string words = "Initial text contents of the TextBox.";
public async void textRotation()
{
for(int a =0; a < words.Length; a++)
{
Text.Text = words.Substring(0,a);
await Task.Delay(500);
}
}
Run Code Online (Sandbox Code Playgroud)
一旦文本脱离包装,有一种方法可以将结尾集中起来,这样旧文本就会消失在左侧,而新文本会在右侧消失,而不是直接将其添加到右侧而看不到。
当 USB 设备与Win32_DeviceChangeEvent连接时我可以捕获
但只允许查看 3 个属性
class Win32_DeviceChangeEvent : __ExtrinsicEvent
{
uint8 SECURITY_DESCRIPTOR[];
uint64 TIME_CREATED;
uint16 EventType;
};
Run Code Online (Sandbox Code Playgroud)
但我不明白如何获取有关该设备的所有信息。具体来说,它的端口和集线器、VirtualHubAdress Name等。
public enum EventType
{
Inserted = 2,
Removed = 3
}
public static void RegisterUsbDeviceNotification()
{
var watcher = new ManagementEventWatcher();
var query = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2");
//watcher.EventArrived += new EventArrivedEventHandler(watcher_EventArrived);
watcher.EventArrived += (s, e) =>
{
//here is im need to get info about this device
EventType eventType …
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个可以托管动态添加控件的面板。有两个注意事项:
我已经看到了一些在表单中居中动态控件的提议解决方案,但由于以下原因而拒绝了这些解决方案:
我想知道我是否缺少一些可以帮助我处理增长/收缩事件而不创建我自己的 TableLayoutPanel 变体的功能?
编辑:
以下是功能草案:
我有一个 PNG 文件,文件属性证明它具有 8 位颜色深度:
是的,当我打开文件时
var filePath = "00050-w600.png";
var bitmap = new Bitmap(filePath);
Console.WriteLine(bitmap.PixelFormat);
Run Code Online (Sandbox Code Playgroud)
我明白了Format32bppArgb
。我还查看了PropertyIdList
和PropertyItems
属性,但没有看到任何明显的东西。
那么如何从 PNG 中提取位深度呢?
PS 没有框架方法似乎工作。 System.Windows.Media.Imaging.BitmapSource
可能有效,但仅适用于 WPF 和 .NET Core 3。我需要它用于 .NET 4.x 和 .NET Core 2.x。
PPS 我只需要知道 PNG 是否是 8 位,所以我写了一个确定的方法来检查是否有人需要它 - 应该在任何框架中工作。
public static bool IsPng8BitColorDepth(string filePath)
{
const int COLOR_TYPE_BITS_8 = 3;
const int COLOR_DEPTH_8 = 8;
int startReadPosition = 24;
int colorDepthPositionOffset = 0;
int colorTypePositionOffset = 1;
try
{
using …
Run Code Online (Sandbox Code Playgroud)