Disable X Close Button

#Region "Disable the 'X'"
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
Const CS_NOCLOSE As Integer = &H200
cp.ClassStyle = cp.ClassStyle Or CS_NOCLOSE
Return cp
End Get
End Property
#End Region
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
Const CS_NOCLOSE As Integer = &H200
cp.ClassStyle = cp.ClassStyle Or CS_NOCLOSE
Return cp
End Get
End Property
#End Region
Disable Alt+F4

[VB.NET]
Protected Overrides Sub WndProc( _
ByRef m As System.Windows.Forms.Message)
Const WM_SYSCOMMAND As Integer = &H112
Const SC_CLOSE As Integer = &HF060
If m.Msg = WM_SYSCOMMAND And m.WParam.ToInt32() = SC_CLOSE Then
Return
End If
MyBase.WndProc(m)
End Sub
Protected Overrides Sub WndProc( _
ByRef m As System.Windows.Forms.Message)
Const WM_SYSCOMMAND As Integer = &H112
Const SC_CLOSE As Integer = &HF060
If m.Msg = WM_SYSCOMMAND And m.WParam.ToInt32() = SC_CLOSE Then
Return
End If
MyBase.WndProc(m)
End Sub
隱藏任務欄

#Region "隐藏或显示任务栏"
Private Const SWP_HIDEWINDOW As Integer = &H80
Private Const SWP_SHOWWINDOW As Integer = &H40
Private Const SWP_NOSIZE As Integer = &H1
Private Const SWP_NOMOVE As Integer = &H2
Private Const SWP_NOACTIVATE As Integer = &H10
Private Const HWND_TOPMOST As Integer = -1
Private Const HWND_NOTOPMOST As Integer = -2
<DllImport("user32.dll")> _
Private Shared Function SetWindowPos( _
ByVal hWnd As Integer, _
ByVal hWndInsertAfter As Integer, _
ByVal X As Short, _
ByVal Y As Short, _
ByVal cx As Short, _
ByVal cy As Short, _
ByVal uFlags As UInt32 _
) As Boolean
End Function
<DllImport("user32.dll")> _
Private Shared Function FindWindow( _
ByVal lpClassName As String, _
ByVal lpWindowName As String _
) As Integer
End Function
Private Sub ShowOrHideTaskbar(ByVal isShow As Boolean)
Dim TaskBarHwnd As Integer = FindWindow("Shell_traywnd", "")
If isShow Then
SetWindowPos(TaskBarHwnd, 0, 0, 0, 0, 0, Convert.ToUInt32(SWP_SHOWWINDOW))
Else
'when browswer open new window,will not active taskbar
SetWindowPos(TaskBarHwnd, 0, 0, 0, 0, 0, Convert.ToUInt32(SWP_NOACTIVATE))
'SetWindowPos(TaskBarHwnd, 0, 0, 0, 0, 0, Convert.ToUInt32(SWP_HIDEWINDOW))
End If
End Sub
#End Region
Private Const SWP_HIDEWINDOW As Integer = &H80
Private Const SWP_SHOWWINDOW As Integer = &H40
Private Const SWP_NOSIZE As Integer = &H1
Private Const SWP_NOMOVE As Integer = &H2
Private Const SWP_NOACTIVATE As Integer = &H10
Private Const HWND_TOPMOST As Integer = -1
Private Const HWND_NOTOPMOST As Integer = -2
<DllImport("user32.dll")> _
Private Shared Function SetWindowPos( _
ByVal hWnd As Integer, _
ByVal hWndInsertAfter As Integer, _
ByVal X As Short, _
ByVal Y As Short, _
ByVal cx As Short, _
ByVal cy As Short, _
ByVal uFlags As UInt32 _
) As Boolean
End Function
<DllImport("user32.dll")> _
Private Shared Function FindWindow( _
ByVal lpClassName As String, _
ByVal lpWindowName As String _
) As Integer
End Function
Private Sub ShowOrHideTaskbar(ByVal isShow As Boolean)
Dim TaskBarHwnd As Integer = FindWindow("Shell_traywnd", "")
If isShow Then
SetWindowPos(TaskBarHwnd, 0, 0, 0, 0, 0, Convert.ToUInt32(SWP_SHOWWINDOW))
Else
'when browswer open new window,will not active taskbar
SetWindowPos(TaskBarHwnd, 0, 0, 0, 0, 0, Convert.ToUInt32(SWP_NOACTIVATE))
'SetWindowPos(TaskBarHwnd, 0, 0, 0, 0, 0, Convert.ToUInt32(SWP_HIDEWINDOW))
End If
End Sub
#End Region
得到硬盤邏輯盘的剩余空间

Public Function GetLogicalDiskFreeSpace(ByVal diskName As String) As Int64 '得到剩余空间
Dim newDiskName As String = diskName.Substring(0, 1) + ":"
Dim disk As New ManagementObject("win32_logicaldisk.deviceid=""" + newDiskName + """")
disk.Get()
Return Convert.ToInt64(disk("FreeSpace"))
End Function
Dim newDiskName As String = diskName.Substring(0, 1) + ":"
Dim disk As New ManagementObject("win32_logicaldisk.deviceid=""" + newDiskName + """")
disk.Get()
Return Convert.ToInt64(disk("FreeSpace"))
End Function
讀寫config 文件

Public Function ReadConfig(ByVal FileName As String, ByVal SectionName As String) As String
Dim configFile As New XmlDocument
Dim xpathTemplate = "//configuration/appSettings/add[@key='{0}']"
Dim xpath As String = String.Format(xpathTemplate, SectionName)
Dim att As String
Dim _node As XmlNode
Try
With configFile
.Load(FileName)
_node = .SelectSingleNode(xpath)
att = _node.Attributes("value").InnerText
End With
Catch fnfe As FileNotFoundException
Throw fnfe
Catch xe As XmlException
Throw xe
Catch ex As Exception
End Try
configFile = Nothing
Return att
End Function
Public Sub WriteConfig(ByVal FileName As String, ByVal SectionName As String, _
ByVal SectionValue As String)
Dim configFile As New XmlDocument
Dim xpathTemplate = "//configuration/appSettings/add[@key='{0}']"
Dim xpath As String = String.Format(xpathTemplate, SectionName)
Dim att As String
Dim _node As XmlNode
Try
With configFile
.Load(FileName)
_node = .SelectSingleNode(xpath)
'if no,insert
If _node Is Nothing Then
Dim keyattrib As XmlAttribute = configFile.CreateAttribute("key")
keyattrib.InnerText = SectionName
Dim valattrib As XmlAttribute = configFile.CreateAttribute("value")
valattrib.InnerText = SectionValue
Dim add As XmlNode = configFile.CreateElement("add")
add.Attributes.Append(keyattrib)
add.Attributes.Append(valattrib)
Dim appsettings As XmlNode = configFile.GetElementsByTagName("appSettings")(0)
appsettings.AppendChild(add)
Else
_node.Attributes("value").InnerText = SectionValue
End If
'persist changes
.Save(FileName)
End With
Catch fnfe As FileNotFoundException
Throw fnfe
Catch xe As XmlException
Throw xe
Catch ex As Exception
Throw ex
End Try
configFile = Nothing
End Sub
藍牙發送文件

Public Function BlueTooth(ByVal DeviceAdress As String, ByVal FilePath As String) As String
Try
Cursor.Current = Cursors.WaitCursor
Dim theuri As Uri
theuri = New Uri("obex://" + DeviceAdress + System.IO.Path.GetFileName(FilePath), True)
Dim request As New ObexWebRequest(theuri)
'request.Timeout = 1000 '1 seconds
request.ReadFile(FilePath)
Dim response As ObexWebResponse = CType(request.GetResponse(), ObexWebResponse)
Select Case response.StatusCode
Case ObexStatusCode.BadRequest
BlueTooth = "文件发送失败"
Case ObexStatusCode.Conflict
BlueTooth = "发生冲突,请重试"
Case ObexStatusCode.DatabaseFull
BlueTooth = "空间不够,请先清理文件"
Case ObexStatusCode.NotAcceptable
BlueTooth = "发生未知错误"
Case ObexStatusCode.Forbidden
BlueTooth = "发生未知错误"
Case ObexStatusCode.Final
BlueTooth = "文件发送完成"
Case 160
BlueTooth = "文件发送完成"
Case ObexStatusCode.GatewayTimeout
BlueTooth = "文件发送超时"
Case ObexStatusCode.InternalServerError
BlueTooth = "连接中断"
Case ObexStatusCode.NoContent
BlueTooth = "文件内容为空"
Case ObexStatusCode.NotFound
BlueTooth = "找不到文件"
Case Else
BlueTooth = response.StatusCode.ToString
End Select
response.Close()
Cursor.Current = Cursors.Default
Catch ex As Exception
BlueTooth = "文件发送失败"
End Try
Try
Cursor.Current = Cursors.WaitCursor
Dim theuri As Uri
theuri = New Uri("obex://" + DeviceAdress + System.IO.Path.GetFileName(FilePath), True)
Dim request As New ObexWebRequest(theuri)
'request.Timeout = 1000 '1 seconds
request.ReadFile(FilePath)
Dim response As ObexWebResponse = CType(request.GetResponse(), ObexWebResponse)
Select Case response.StatusCode
Case ObexStatusCode.BadRequest
BlueTooth = "文件发送失败"
Case ObexStatusCode.Conflict
BlueTooth = "发生冲突,请重试"
Case ObexStatusCode.DatabaseFull
BlueTooth = "空间不够,请先清理文件"
Case ObexStatusCode.NotAcceptable
BlueTooth = "发生未知错误"
Case ObexStatusCode.Forbidden
BlueTooth = "发生未知错误"
Case ObexStatusCode.Final
BlueTooth = "文件发送完成"
Case 160
BlueTooth = "文件发送完成"
Case ObexStatusCode.GatewayTimeout
BlueTooth = "文件发送超时"
Case ObexStatusCode.InternalServerError
BlueTooth = "连接中断"
Case ObexStatusCode.NoContent
BlueTooth = "文件内容为空"
Case ObexStatusCode.NotFound
BlueTooth = "找不到文件"
Case Else
BlueTooth = response.StatusCode.ToString
End Select
response.Close()
Cursor.Current = Cursors.Default
Catch ex As Exception
BlueTooth = "文件发送失败"
End Try
C# 泛型 对象数组排序

public void Sort<T>(object[] list, string key,bool isReverse)
{
int len = list.Length;
Type type = typeof(T);
object[] keys = new object[len];
for (int i = 0; i < len; i++)
{
//Hack,对于字符形式存储的数字,如7,8,9,10,排序,前面加0
string temp =type.InvokeMember(key, BindingFlags.GetProperty, null, list[i], null).ToString();
if (temp.Trim().Length == 1)
temp = "0" + temp.ToString();
keys[i] = temp;
}
Array.Sort(keys, list);
if (isReverse)
Array.Reverse(list);
}
{
int len = list.Length;
Type type = typeof(T);
object[] keys = new object[len];
for (int i = 0; i < len; i++)
{
//Hack,对于字符形式存储的数字,如7,8,9,10,排序,前面加0
string temp =type.InvokeMember(key, BindingFlags.GetProperty, null, list[i], null).ToString();
if (temp.Trim().Length == 1)
temp = "0" + temp.ToString();
keys[i] = temp;
}
Array.Sort(keys, list);
if (isReverse)
Array.Reverse(list);
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?