📄 utility.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.WindowsCE.Forms;
using System.Drawing;
using HardwareDistributor.Business;
namespace HardwareDistributor.Utilities
{
public static class Utility
{
//this matches the value being used by the target window(splash screen) to wait for messages
private const int WM_STATUSUPDATE = 0x0409;
/// <summary>
/// Internal method for checking a string for null or empty including
/// making sure it is not composed of spaces.
/// </summary>
/// <param name="stringToCheck">string to test</param>
/// <returns>true if the string is null or empty</returns>
private static bool IsStringNullOrEmpty(string stringToCheck)
{
return string.IsNullOrEmpty(stringToCheck) ||
string.IsNullOrEmpty(stringToCheck.Trim());
}
/// <summary>
/// This is a generic method for testing to make sure a string is null
/// or empty. Empty is defined as have something besides space.
/// </summary>
/// <param name="stringToCheck">string to test</param>
/// <param name="errorMessage">
/// error message to put as the message for a
/// <see cref="System.ArgumentException"/>
/// </param>
/// <param name="throwException">set to true to throw an exception</param>
/// <returns>true if the string is null or empty</returns>
/// <exception cref="System.ArgumentException">
/// If the error message is missing or throwException is true then an
/// ArgumentException will be thrown.
/// </exception>
public static bool IsStringNullOrEmpty(string stringToCheck,
string errorMessage,
bool throwException)
{
bool result;
// Check if errorMessage argument is bad
if ((throwException) && (IsStringNullOrEmpty(errorMessage)))
{
throw new ArgumentException("ErrorMessage cannot be empty.");
}
result = IsStringNullOrEmpty(stringToCheck);
// If empty string and throw exception is true then create and
// throw exception
if (result && throwException)
{
throw new ArgumentException(errorMessage);
}
return result;
}
public static void CaptureScreenShot(int x, int y, int width, int height,
Graphics sourceGraphicsObject, string fileName, System.Drawing.Imaging.ImageFormat imageFormat)
{
//Raster operation code for Copy from Source for BitBlt
const int SRCCOPY = 0x00CC0020;
//destination image and device context
Bitmap memImage = new Bitmap(width, height);
Graphics memGraphic = Graphics.FromImage(memImage);
//get the Handles
IntPtr destinationHdc = memGraphic.GetHdc();
IntPtr sourceHdc = sourceGraphicsObject.GetHdc();
//call the native function to grab the region
Native.BitBlt(destinationHdc, 0, 0, width, height, sourceHdc, x, y, SRCCOPY);
//release
sourceGraphicsObject.ReleaseHdc(sourceHdc);
memGraphic.ReleaseHdc(destinationHdc);
memImage.Save(fileName, imageFormat);
}
public static string GetDBConnectionString()
{
string connectionString = GlobalCache.Instance.AppPath + GlobalCache.Instance.SqlCeDatabase;
return connectionString;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -