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.
247 lines
9.2 KiB
C#
247 lines
9.2 KiB
C#
using NPOI.OpenXmlFormats.Dml.Chart;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Reflection.Emit;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Rs.MotionPlat
|
|
{
|
|
public enum EButtonType
|
|
{
|
|
None = 1 << 0,
|
|
Cancel = 1 << 1,
|
|
Ok = 1 << 2,
|
|
Retry = 1 << 3,
|
|
EndInput = 1 << 4,
|
|
Skip = 1 << 5,
|
|
Recheck = 1 << 6
|
|
}
|
|
|
|
public partial class FrmDialog : BaseFormHeader
|
|
{
|
|
|
|
string cnContent = "";
|
|
string enContent = "";
|
|
//关闭窗体事件
|
|
Button btnOk = new Button() { Name="Ok"};
|
|
Button btnCancel = new Button() { Name = "Cancel" };
|
|
Button btnEndInput = new Button() { Name = "EndInput" };
|
|
Button btnRetry = new Button() { Name = "Retry" };
|
|
Button btnSkip = new Button() { Name = "Skip" };
|
|
Button btnRecheck = new Button() { Name = "Recheck" };
|
|
List<Button> buttons = new List<Button>();
|
|
public FrmDialog()
|
|
{
|
|
InitializeComponent();
|
|
buttons.Add(btnOk);
|
|
buttons.Add(btnCancel);
|
|
buttons.Add(btnEndInput);
|
|
buttons.Add(btnRetry);
|
|
buttons.Add(btnSkip);
|
|
buttons.Add(btnRecheck);
|
|
foreach (var item in buttons)
|
|
{
|
|
item.Cursor = Cursors.Hand;
|
|
item.Text = item.Name;
|
|
item.Size = new System.Drawing.Size(100, 30);
|
|
item.ForeColor = System.Drawing.Color.White;
|
|
item.Margin = new System.Windows.Forms.Padding(0, 0, 10, 0);
|
|
item.FlatStyle = FlatStyle.Flat;
|
|
item.FlatAppearance.BorderSize =1;
|
|
item.FlatAppearance.BorderColor = Color.Red;
|
|
item.BackColor = Color.FromArgb(56, 56, 56);
|
|
item.Click += (a, b) => {
|
|
btnResult = (EButtonType)Enum.Parse(typeof(EButtonType), item.Name);
|
|
this.Close();
|
|
};
|
|
}
|
|
}
|
|
|
|
private void BtnOk_Click(object sender, EventArgs e)
|
|
{
|
|
btnResult = EButtonType.Ok;
|
|
this.Close();
|
|
}
|
|
|
|
private void FrmDialog_Load(object sender, EventArgs e)
|
|
{
|
|
// ShowMessage(EButtonType.Ok| EButtonType.Cancel);
|
|
}
|
|
|
|
public const int HWND_TOP = 0;
|
|
public const int HWND_BOTTOM = 1;
|
|
public const int HWND_TOPMOST = -1;
|
|
public const int HWND_NOTOPMOST = -2;
|
|
|
|
//设置此窗体为活动窗体:
|
|
//将创建指定窗口的线程带到前台并激活该窗口。键盘输入直接指向窗口,并为用户更改各种视觉提示。
|
|
//系统为创建前台窗口的线程分配的优先级略高于其他线程。
|
|
[DllImport("user32.dll", EntryPoint = "SetForegroundWindow")]
|
|
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
|
|
|
//设置此窗体为活动窗体:
|
|
//激活窗口。窗口必须附加到调用线程的消息队列。
|
|
[DllImport("user32.dll", EntryPoint = "SetActiveWindow")]
|
|
public static extern IntPtr SetActiveWindow(IntPtr hWnd);
|
|
|
|
//设置窗体位置
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
|
private static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags);
|
|
|
|
EButtonType btnResult = EButtonType.None;
|
|
public EButtonType ShowMessage(EButtonType eButtonType,string _cnContent,string _enContent,string title="",bool bWait=true)
|
|
{
|
|
cnContent = _cnContent;
|
|
enContent = _enContent;
|
|
if(!string.IsNullOrEmpty(title))
|
|
{
|
|
this.HeadText= title;
|
|
}
|
|
this.lblContent.Text= cnContent;
|
|
//遍历
|
|
string[] buttons = Enum.GetNames(typeof(EButtonType));
|
|
foreach (string button in buttons.Reverse())
|
|
{
|
|
EButtonType bt = (EButtonType)Enum.Parse(typeof(EButtonType), button);
|
|
if (eButtonType.HasFlag(bt))
|
|
{
|
|
Panel p = new Panel();
|
|
p.Size = new Size(120, 30);
|
|
p.Padding = new Padding(5);
|
|
p.Dock = DockStyle.Right;
|
|
//p.BackColor = Color.Red;
|
|
switch (button)
|
|
{
|
|
case "Ok":
|
|
btnOk.Dock = DockStyle.Fill;
|
|
p.Controls.Add(btnOk);
|
|
break;
|
|
case "Cancel":
|
|
btnCancel.Dock = DockStyle.Fill;
|
|
p.Controls.Add(btnCancel);
|
|
break;
|
|
case "EndInput":
|
|
btnEndInput.Dock = DockStyle.Fill;
|
|
p.Controls.Add(btnEndInput);
|
|
break;
|
|
case "Retry":
|
|
btnRetry.Dock = DockStyle.Fill;
|
|
p.Controls.Add(btnRetry);
|
|
break;
|
|
case "Skip":
|
|
btnSkip.Dock = DockStyle.Fill;
|
|
p.Controls.Add(btnSkip);
|
|
break;
|
|
case "Recheck":
|
|
btnRecheck.Dock = DockStyle.Fill;
|
|
p.Controls.Add(btnRecheck);
|
|
break;
|
|
case "None":
|
|
this.panelBottom.Visible = false;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
panelBottom.Controls.Add(p);
|
|
}
|
|
}
|
|
// 设置窗体显示在最上层
|
|
SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 0x0001 | 0x0002 | 0x0010 | 0x0080);
|
|
// 设置本窗体为活动窗体
|
|
SetActiveWindow(this.Handle);
|
|
SetForegroundWindow(this.Handle);
|
|
this.TopMost = true;
|
|
|
|
this.StartPosition = FormStartPosition.CenterScreen;
|
|
if (bWait)
|
|
this.ShowDialog();
|
|
else
|
|
this.Show();
|
|
//this.Show();
|
|
return btnResult;
|
|
|
|
}
|
|
|
|
private void lblContent_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
int LineDistance = 8;//行间距
|
|
System.Windows.Forms.Label label = sender as System.Windows.Forms.Label;
|
|
System.Drawing.Font drawFont = label.Font;
|
|
label.AutoSize = false;
|
|
SolidBrush drawBrush = new SolidBrush(label.ForeColor);
|
|
Graphics g = e.Graphics;
|
|
g.Clear(label.BackColor);
|
|
StringFormat drawFormat = new StringFormat();
|
|
string[] arrDrawString = label.Text.Split(new char[] { '\n' });
|
|
|
|
int height = 0;
|
|
foreach (string str in arrDrawString)
|
|
{
|
|
//文本的矩形区域大小
|
|
SizeF textSize = g.MeasureString(str, label.Font);
|
|
|
|
//计算行数
|
|
int strLineCount = Convert.ToInt32(Math.Ceiling(textSize.Width / label.Width));
|
|
|
|
|
|
height += Convert.ToInt16((textSize.Height + LineDistance) * strLineCount);
|
|
}
|
|
|
|
label.Height = height; //计算调整后的高度
|
|
float netTextPos_Y = 0; // 下一行的位置
|
|
foreach (string drawString in arrDrawString)
|
|
{
|
|
bool drawText = false;
|
|
int strLenght = 1; // 长度
|
|
int startIndex = 0; // 开始位置
|
|
for (int i = 0; i < drawString.Length; i++, strLenght++)
|
|
{
|
|
string subN = drawString.Substring(startIndex, strLenght);
|
|
if (startIndex + strLenght >= drawString.Length)
|
|
{
|
|
drawText = true;
|
|
}
|
|
else
|
|
{
|
|
string subN1 = drawString.Substring(startIndex, strLenght + 1);
|
|
if (g.MeasureString(subN, label.Font).Width <= label.Width && g.MeasureString(subN1, label.Font).Width > label.Width)
|
|
{
|
|
drawText = true;
|
|
}
|
|
}
|
|
if (drawText)
|
|
{
|
|
drawText = false;
|
|
strLenght = 0;
|
|
startIndex = i + 1;
|
|
SizeF textSize = g.MeasureString(subN, label.Font);
|
|
e.Graphics.DrawString(subN, drawFont, drawBrush, 0, netTextPos_Y, drawFormat);
|
|
netTextPos_Y = netTextPos_Y + textSize.Height + LineDistance;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ReloadLanguage()
|
|
{
|
|
string lang = Properties.Settings.Default.DefaultLanguage;
|
|
if (lang == "zh-CN")
|
|
{
|
|
lblContent.Text = cnContent;
|
|
}
|
|
else
|
|
{
|
|
lblContent.Text = enContent;
|
|
}
|
|
}
|
|
}
|
|
}
|