You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
641 lines
16 KiB
C#
641 lines
16 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Runtime.InteropServices;
|
|
using System.Windows.Forms;
|
|
|
|
namespace GeoSigmaViewer
|
|
{
|
|
/// <summary>
|
|
/// 自定义光标加载类,原来的 DrawCursors 类代码是自动生成的,直接在里面改会被冲掉,现在光标统一从这个自定义类获取
|
|
/// </summary>
|
|
public class CustomDrawCursors
|
|
{
|
|
private static Cursor defaultCursor;
|
|
private static Cursor select;
|
|
private static Cursor viewWindow;
|
|
private static Cursor pan;
|
|
private static Cursor pan1;
|
|
private static Cursor line;
|
|
private static Cursor ellipse;
|
|
private static Cursor rectangle;
|
|
private static Cursor polyHandle;
|
|
private static Cursor pencil;
|
|
private static Cursor curveDraw;
|
|
private static Cursor addHandle;
|
|
private static Cursor curveMovePoint;
|
|
private static Cursor curveMove;
|
|
private static Cursor trackNWSE;
|
|
private static Cursor trackNESW;
|
|
private static Cursor trackNS;
|
|
private static Cursor trackWE;
|
|
private static Cursor track4Way;
|
|
private static Cursor move4Way;
|
|
private static Cursor copy4Way;
|
|
private static Cursor rotate;
|
|
private static Cursor shearHor;
|
|
private static Cursor shearVert;
|
|
private static Cursor hArrow;
|
|
private static Cursor vArrow;
|
|
private static Cursor lBArrow;
|
|
private static Cursor rBArrow;
|
|
private static Cursor hShearArrow;
|
|
private static Cursor vShearArrow;
|
|
private static Cursor range;
|
|
private static Cursor breakCurve;
|
|
private static Cursor selectElement;
|
|
private static Cursor delete;
|
|
|
|
/// <summary>
|
|
/// 判断是否是高分屏
|
|
/// </summary>
|
|
/// <returns>true/false</returns>
|
|
public static bool IsHightDpi()
|
|
{
|
|
return CustomPrimaryScreen.ScaleX >= 1.9 || CustomPrimaryScreen.ScaleY >= 1.9;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 默认光标
|
|
/// </summary>
|
|
public static Cursor Default
|
|
{
|
|
get
|
|
{
|
|
if (defaultCursor == null)
|
|
{
|
|
defaultCursor = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curDefault);
|
|
}
|
|
|
|
return defaultCursor;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 选择光标
|
|
/// </summary>
|
|
public static Cursor Select
|
|
{
|
|
get
|
|
{
|
|
if (select == null)
|
|
{
|
|
if (IsHightDpi())
|
|
{
|
|
select = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curSelect);
|
|
}
|
|
else
|
|
{
|
|
select = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curSelectSmall);
|
|
}
|
|
}
|
|
|
|
return select;
|
|
}
|
|
}
|
|
|
|
public static Cursor ViewWindow
|
|
{
|
|
get
|
|
{
|
|
if (viewWindow == null)
|
|
{
|
|
viewWindow = CursorResourceLoader.LoadEmbeddedCursor(Resource1.viewWindow);
|
|
}
|
|
|
|
return viewWindow;
|
|
}
|
|
}
|
|
|
|
public static Cursor Pan
|
|
{
|
|
get
|
|
{
|
|
if (pan == null)
|
|
{
|
|
pan = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curPan);
|
|
}
|
|
|
|
return pan;
|
|
}
|
|
}
|
|
|
|
public static Cursor Pan1
|
|
{
|
|
get
|
|
{
|
|
if (pan1 == null)
|
|
{
|
|
pan1 = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curPan1);
|
|
}
|
|
|
|
return pan1;
|
|
}
|
|
}
|
|
|
|
public static Cursor Line
|
|
{
|
|
get
|
|
{
|
|
if (line == null)
|
|
{
|
|
line = CursorResourceLoader.LoadEmbeddedCursor(Resource1.Line);
|
|
}
|
|
|
|
return line;
|
|
}
|
|
}
|
|
|
|
public static Cursor Ellipse
|
|
{
|
|
get
|
|
{
|
|
if (ellipse == null)
|
|
{
|
|
ellipse = CursorResourceLoader.LoadEmbeddedCursor(Resource1.Ellipse);
|
|
}
|
|
|
|
return ellipse;
|
|
}
|
|
}
|
|
|
|
public static Cursor Rectangle
|
|
{
|
|
get
|
|
{
|
|
if (range == null)
|
|
{
|
|
rectangle = CursorResourceLoader.LoadEmbeddedCursor(Resource1.Rectangle);
|
|
}
|
|
|
|
return rectangle;
|
|
}
|
|
}
|
|
|
|
public static Cursor PolyHandle
|
|
{
|
|
get
|
|
{
|
|
if (polyHandle == null)
|
|
{
|
|
polyHandle = CursorResourceLoader.LoadEmbeddedCursor(Resource1.PolyHandle);
|
|
}
|
|
|
|
return polyHandle;
|
|
}
|
|
}
|
|
|
|
public static Cursor Pencil
|
|
{
|
|
get
|
|
{
|
|
if (pencil == null)
|
|
{
|
|
pencil = CursorResourceLoader.LoadEmbeddedCursor(Resource1.Pencil);
|
|
}
|
|
|
|
return pencil;
|
|
}
|
|
}
|
|
|
|
public static Cursor CurveDraw
|
|
{
|
|
get
|
|
{
|
|
if (curveDraw == null)
|
|
{
|
|
curveDraw = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curCurve);
|
|
}
|
|
|
|
return curveDraw;
|
|
}
|
|
}
|
|
|
|
public static Cursor AddHandle
|
|
{
|
|
get
|
|
{
|
|
if (addHandle == null)
|
|
{
|
|
addHandle = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curAddHandle);
|
|
}
|
|
|
|
return addHandle;
|
|
}
|
|
}
|
|
|
|
public static Cursor CurveMovePoint
|
|
{
|
|
get
|
|
{
|
|
if (curveMovePoint == null)
|
|
{
|
|
curveMovePoint = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curMoveHandle);
|
|
}
|
|
|
|
return curveMovePoint;
|
|
}
|
|
}
|
|
|
|
public static Cursor CurveMove
|
|
{
|
|
get
|
|
{
|
|
if (curveMove == null)
|
|
{
|
|
curveMove = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curMove4Way);
|
|
}
|
|
|
|
return curveMove;
|
|
}
|
|
}
|
|
|
|
public static Cursor TrackNWSE
|
|
{
|
|
get
|
|
{
|
|
if (trackNWSE == null)
|
|
{
|
|
trackNWSE = CursorResourceLoader.LoadEmbeddedCursor(Resource1.trcknwse);
|
|
}
|
|
|
|
return trackNWSE;
|
|
}
|
|
}
|
|
|
|
public static Cursor TrackNESW
|
|
{
|
|
get
|
|
{
|
|
if (trackNESW == null)
|
|
{
|
|
trackNESW = CursorResourceLoader.LoadEmbeddedCursor(Resource1.trcknesw);
|
|
}
|
|
|
|
return trackNESW;
|
|
}
|
|
}
|
|
|
|
public static Cursor TrackNS
|
|
{
|
|
get
|
|
{
|
|
if (trackNS == null)
|
|
{
|
|
trackNS = CursorResourceLoader.LoadEmbeddedCursor(Resource1.trckns);
|
|
}
|
|
|
|
return trackNS;
|
|
}
|
|
}
|
|
|
|
public static Cursor TrackWE
|
|
{
|
|
get
|
|
{
|
|
if (trackWE == null)
|
|
{
|
|
trackWE = CursorResourceLoader.LoadEmbeddedCursor(Resource1.trckwe);
|
|
}
|
|
|
|
return trackWE;
|
|
}
|
|
}
|
|
|
|
public static Cursor Track4Way
|
|
{
|
|
get
|
|
{
|
|
if (track4Way == null)
|
|
{
|
|
track4Way = CursorResourceLoader.LoadEmbeddedCursor(Resource1.trck4way);
|
|
}
|
|
|
|
return track4Way;
|
|
}
|
|
}
|
|
|
|
public static Cursor Move4Way
|
|
{
|
|
get
|
|
{
|
|
if (move4Way == null)
|
|
{
|
|
move4Way = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curMove4Way);
|
|
}
|
|
|
|
return move4Way;
|
|
}
|
|
}
|
|
|
|
public static Cursor Copy4Way
|
|
{
|
|
get
|
|
{
|
|
if (copy4Way == null)
|
|
{
|
|
copy4Way = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curCopy4Way);
|
|
}
|
|
|
|
return copy4Way;
|
|
}
|
|
}
|
|
|
|
public static Cursor Rotate
|
|
{
|
|
get
|
|
{
|
|
if (rotate == null)
|
|
{
|
|
rotate = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curRotate);
|
|
}
|
|
|
|
return rotate;
|
|
}
|
|
}
|
|
|
|
public static Cursor ShearHor
|
|
{
|
|
get
|
|
{
|
|
if (shearHor == null)
|
|
{
|
|
shearHor = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curShearHor);
|
|
}
|
|
|
|
return shearHor;
|
|
}
|
|
}
|
|
|
|
public static Cursor ShearVert
|
|
{
|
|
get
|
|
{
|
|
if (shearVert == null)
|
|
{
|
|
shearVert = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curShearVert);
|
|
}
|
|
|
|
return shearVert;
|
|
}
|
|
}
|
|
|
|
public static Cursor HArrow
|
|
{
|
|
get
|
|
{
|
|
if (hArrow == null)
|
|
{
|
|
hArrow = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curHArrow);
|
|
}
|
|
|
|
return hArrow;
|
|
}
|
|
}
|
|
|
|
public static Cursor VArrow
|
|
{
|
|
get
|
|
{
|
|
if (vArrow == null)
|
|
{
|
|
vArrow = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curVArrow);
|
|
}
|
|
|
|
return vArrow;
|
|
}
|
|
}
|
|
|
|
public static Cursor LBArrow
|
|
{
|
|
get
|
|
{
|
|
if (lBArrow == null)
|
|
{
|
|
lBArrow = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curLBArrow);
|
|
}
|
|
|
|
return lBArrow;
|
|
}
|
|
}
|
|
|
|
public static Cursor RBArrow
|
|
{
|
|
get
|
|
{
|
|
if (rBArrow == null)
|
|
{
|
|
rBArrow = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curRBArrow);
|
|
}
|
|
|
|
return rBArrow;
|
|
}
|
|
}
|
|
|
|
public static Cursor HShearArrow
|
|
{
|
|
get
|
|
{
|
|
if (hShearArrow == null)
|
|
{
|
|
hShearArrow = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curShearHor);
|
|
}
|
|
|
|
return hShearArrow;
|
|
}
|
|
}
|
|
|
|
public static Cursor VShearArrow
|
|
{
|
|
get
|
|
{
|
|
if (vShearArrow == null)
|
|
{
|
|
vShearArrow = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curShearVert);
|
|
}
|
|
|
|
return vShearArrow;
|
|
}
|
|
}
|
|
|
|
public static Cursor Range
|
|
{
|
|
get
|
|
{
|
|
if (range == null)
|
|
{
|
|
range = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curRange);
|
|
}
|
|
|
|
return range;
|
|
}
|
|
}
|
|
|
|
public static Cursor BreakCurve
|
|
{
|
|
get
|
|
{
|
|
if (breakCurve == null)
|
|
{
|
|
breakCurve = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curBreakCurve);
|
|
}
|
|
|
|
return breakCurve;
|
|
}
|
|
}
|
|
|
|
public static Cursor SelectElement
|
|
{
|
|
get
|
|
{
|
|
if (selectElement == null)
|
|
{
|
|
selectElement = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curSelectElement);
|
|
}
|
|
|
|
return selectElement;
|
|
}
|
|
}
|
|
|
|
public static Cursor Delete
|
|
{
|
|
get
|
|
{
|
|
if (delete == null)
|
|
{
|
|
delete = CursorResourceLoader.LoadEmbeddedCursor(Resource1.curDelete);
|
|
}
|
|
|
|
return delete;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 自定义主屏幕类
|
|
/// </summary>
|
|
#pragma warning disable SA1402 // File may only contain a single type
|
|
public class CustomPrimaryScreen
|
|
#pragma warning restore SA1402 // File may only contain a single type
|
|
{
|
|
#region Win32 API
|
|
|
|
[DllImport("user32.dll")]
|
|
private static extern IntPtr GetDC(IntPtr ptr);
|
|
|
|
[DllImport("gdi32.dll")]
|
|
private static extern int GetDeviceCaps(
|
|
IntPtr hdc, // handle to DC
|
|
int nIndex // index of capability
|
|
);
|
|
|
|
[DllImport("user32.dll", EntryPoint = "ReleaseDC")]
|
|
private static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
|
|
|
|
#endregion Win32 API
|
|
|
|
#region DeviceCaps常量
|
|
|
|
private const int HORZRES = 8;
|
|
private const int VERTRES = 10;
|
|
private const int LOGPIXELSX = 88;
|
|
private const int LOGPIXELSY = 90;
|
|
private const int DESKTOPVERTRES = 117;
|
|
private const int DESKTOPHORZRES = 118;
|
|
|
|
#endregion DeviceCaps常量
|
|
|
|
#region 属性
|
|
|
|
/// <summary>
|
|
/// Gets 获取屏幕分辨率当前物理大小.
|
|
/// </summary>
|
|
public static Size WorkingArea
|
|
{
|
|
get
|
|
{
|
|
IntPtr hdc = GetDC(IntPtr.Zero);
|
|
Size size = new Size();
|
|
size.Width = GetDeviceCaps(hdc, HORZRES);
|
|
size.Height = GetDeviceCaps(hdc, VERTRES);
|
|
ReleaseDC(IntPtr.Zero, hdc);
|
|
return size;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets 当前系统DPI_X 大小 一般为96.
|
|
/// </summary>
|
|
public static int DpiX
|
|
{
|
|
get
|
|
{
|
|
IntPtr hdc = GetDC(IntPtr.Zero);
|
|
int dpiX = GetDeviceCaps(hdc, LOGPIXELSX);
|
|
ReleaseDC(IntPtr.Zero, hdc);
|
|
return dpiX;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets 当前系统DPI_Y 大小 一般为96.
|
|
/// </summary>
|
|
public static int DpiY
|
|
{
|
|
get
|
|
{
|
|
IntPtr hdc = GetDC(IntPtr.Zero);
|
|
int dpiX = GetDeviceCaps(hdc, LOGPIXELSY);
|
|
ReleaseDC(IntPtr.Zero, hdc);
|
|
return dpiX;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets 真实设置的桌面分辨率大小.
|
|
/// </summary>
|
|
public static Size DESKTOP
|
|
{
|
|
get
|
|
{
|
|
IntPtr hdc = GetDC(IntPtr.Zero);
|
|
Size size = new Size();
|
|
size.Width = GetDeviceCaps(hdc, DESKTOPHORZRES);
|
|
size.Height = GetDeviceCaps(hdc, DESKTOPVERTRES);
|
|
ReleaseDC(IntPtr.Zero, hdc);
|
|
return size;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets 宽度缩放百分比.
|
|
/// </summary>
|
|
public static float ScaleX
|
|
{
|
|
get
|
|
{
|
|
IntPtr hdc = GetDC(IntPtr.Zero);
|
|
int t = GetDeviceCaps(hdc, DESKTOPHORZRES);
|
|
int d = GetDeviceCaps(hdc, HORZRES);
|
|
float scaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES);
|
|
ReleaseDC(IntPtr.Zero, hdc);
|
|
return scaleX;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets 获取高度缩放百分比.
|
|
/// </summary>
|
|
public static float ScaleY
|
|
{
|
|
get
|
|
{
|
|
IntPtr hdc = GetDC(IntPtr.Zero);
|
|
float scaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES);
|
|
ReleaseDC(IntPtr.Zero, hdc);
|
|
return scaleY;
|
|
}
|
|
}
|
|
|
|
#endregion 属性
|
|
}
|
|
} |