You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

275 lines
9.7 KiB

using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
namespace ECMonitor.PlayerDraw.Code
{
public enum ColorEnum
{
绿,
,
,
,
,
,
,
,
,
}
/// <summary>
/// 表示部分音频文件的类型
/// </summary>
public enum FileTypes
{
MKV = 2669,
MP4 = 00,
INI = 255254,
MP3 = 7368,
WAV = 8273,
WMA = 4838,
AVI = 8273,
WMV = 4838,
}
public class BlackboardClass
{
/// <summary>
/// 初始化BlackboardClass
/// </summary>
public BlackboardClass()
{
}
/// <summary>
/// 添加或删除启动项
/// </summary>
/// <param name="isStart">true为添加启动项,否则为删除启动项</param>
/// <param name="startName">启动项的名称</param>
/// <param name="applicationPath">要开机启动的应用程序的exe文件的路径</param>
/// <returns>表示是否完成添加或删除任务</returns>
public static bool RunItem(bool isStart, string startName, string applicationPath)
{
bool result = true;
RegistryKey HKLM = Registry.CurrentUser;
RegistryKey run = HKLM.CreateSubKey(@"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\");
if (isStart)
{
try
{
run.SetValue(startName, applicationPath);
HKLM.Close();
}
catch (Exception)
{
}
}
else
{
try
{
run.DeleteValue(startName);
HKLM.Close();
}
catch (Exception)
{
}
}
result = run.GetValue("智能版") != null;
HKLM.Close();
return result;
}
/// <summary>
/// 初始化BlackboardClass
/// </summary>
/// <param name="moveControl">要移动的控件</param>
public BlackboardClass(UserControl moveControl)
{
MoveControl = moveControl;
}
/// <summary>
/// 要移动的控件
/// </summary>
public UserControl MoveControl { get; set; }
/// <summary>
/// 提供一个Thumb在Grid上的DragDelta处理程序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void ThumbMove(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
if (MoveControl != null)
{
double top = MoveControl.Margin.Top + e.VerticalChange,//上边距
left = MoveControl.Margin.Left + e.HorizontalChange;//左边距
MoveControl.Margin = new System.Windows.Thickness(left, top, 0, 0);
}
}
public static bool IsAudio(string path)
{
FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
BinaryReader read = new BinaryReader(fileStream);
byte code;
string fileTypeCode = String.Empty;
try
{
for (int i = 0; i < 2; i++)
{
code = read.ReadByte();
fileTypeCode += code.ToString();
}
}
catch (Exception)
{
return false;
}
fileStream.Close();
read.Close();
int tryVal;
return !Int32.TryParse(((FileTypes)Enum.Parse(typeof(FileTypes), fileTypeCode)).ToString(), out tryVal);
}
/// <summary>
/// 改变颜色
/// </summary>
/// <param name="color">要返回的颜色</param>
public static Color ChangeColor(ColorEnum color)
{
switch (color)
{
case ColorEnum.:
return Colors.White;
case ColorEnum.:
return Colors.Yellow;
case ColorEnum.:
return Colors.Black;
case ColorEnum.:
return Colors.Red;
case ColorEnum.:
return Colors.Gray;
case ColorEnum.:
return Colors.Blue;
case ColorEnum.绿:
return Colors.Green;
case ColorEnum.:
return Colors.Cyan;
case ColorEnum.:
return Colors.Purple;
case ColorEnum.:
return Colors.Orange;
default:
return new Color();
}
}
public void ChangSize(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
double wibth = this.MoveControl.ActualWidth;
double heigth = this.MoveControl.ActualHeight;
switch ((sender as Thumb).Name)
{
case "LeftTop":
double left = MoveControl.Margin.Left,
top = MoveControl.Margin.Top;
if (MoveControl.ActualWidth - e.HorizontalChange <= this.MoveControl.MaxWidth &&
MoveControl.ActualWidth - e.HorizontalChange >= this.MoveControl.MinWidth)
{
wibth = MoveControl.ActualWidth - e.HorizontalChange;
left = MoveControl.Margin.Left + e.HorizontalChange;
}
if (MoveControl.ActualHeight - e.VerticalChange <= this.MoveControl.MaxHeight &&
MoveControl.ActualHeight - e.VerticalChange >= this.MoveControl.MinHeight)
{
heigth = MoveControl.ActualHeight - e.VerticalChange;
top = MoveControl.Margin.Top + e.VerticalChange;
}
MoveControl.Margin = new Thickness(left, top, 0, 0);
break;
case "LeftBottom":
left = this.MoveControl.Margin.Left;
double bottom = this.MoveControl.Margin.Bottom;
if (MoveControl.ActualWidth - e.HorizontalChange <= this.MoveControl.MaxWidth &&
MoveControl.ActualWidth - e.HorizontalChange >= this.MoveControl.MinWidth)
{
wibth = MoveControl.ActualWidth - e.HorizontalChange;
left = MoveControl.Margin.Left + e.HorizontalChange;
}
if (MoveControl.ActualHeight + e.VerticalChange <= this.MoveControl.MaxHeight &&
MoveControl.ActualHeight + e.VerticalChange >= this.MoveControl.MinHeight)
{
heigth = MoveControl.ActualHeight + e.VerticalChange;
bottom = MoveControl.Margin.Bottom - e.VerticalChange;
}
MoveControl.Margin = new Thickness(left, MoveControl.Margin.Top, 0, bottom);
break;
case "RightTop":
top = this.MoveControl.Margin.Top;
if (MoveControl.ActualWidth + e.HorizontalChange <= this.MoveControl.MaxWidth &&
MoveControl.ActualWidth + e.HorizontalChange >= this.MoveControl.MinWidth)
wibth = MoveControl.ActualWidth + e.HorizontalChange;
if (MoveControl.ActualHeight - e.VerticalChange <= this.MoveControl.MaxHeight &&
MoveControl.ActualHeight - e.VerticalChange >= this.MoveControl.MinHeight)
{
heigth = MoveControl.ActualHeight - e.VerticalChange;
top = MoveControl.Margin.Top + e.VerticalChange;
}
MoveControl.Margin = new Thickness(MoveControl.Margin.Left,
top, 0, MoveControl.Margin.Bottom);
break;
default:
double right = this.MoveControl.Margin.Right;
bottom = this.MoveControl.Margin.Bottom;
if (MoveControl.ActualWidth + e.HorizontalChange <= this.MoveControl.MaxWidth &&
MoveControl.ActualWidth + e.HorizontalChange >= this.MoveControl.MinWidth)
{
wibth = MoveControl.ActualWidth + e.HorizontalChange;
right = MoveControl.Margin.Right - e.HorizontalChange;
}
if (MoveControl.ActualHeight + e.VerticalChange <= this.MoveControl.MaxHeight &&
MoveControl.ActualHeight + e.VerticalChange >= this.MoveControl.MinHeight)
{
heigth = MoveControl.ActualHeight + e.VerticalChange;
bottom = this.MoveControl.Margin.Bottom - e.VerticalChange;
}
MoveControl.Margin = new Thickness(MoveControl.Margin.Left,
MoveControl.Margin.Top, right, bottom);
break;
}
MoveControl.Width = wibth;
MoveControl.Height = heigth;
}
}
}