SVN r974
SVN-Revision: r974
This commit is contained in:
@@ -138,7 +138,7 @@ namespace Lskj.Main
|
||||
|
||||
if (SystemInfo.Instance.DisplayWatermark)
|
||||
{
|
||||
watermarkForm = new FrmWatermark();
|
||||
watermarkForm = new FrmWatermark(this);
|
||||
watermarkForm.Size = this.ClientSize; // 设置水印窗体的大小与主窗体客户端区域相同
|
||||
watermarkForm.Location = this.PointToScreen(new Point(0, 0)); // 将水印窗体定位到主窗体的位置
|
||||
watermarkForm.TopMost = true; // 确保水印窗体始终位于最顶层
|
||||
|
||||
@@ -15,9 +15,15 @@ namespace Lskj.Main
|
||||
{
|
||||
public partial class FrmWatermark : Form
|
||||
{
|
||||
public FrmWatermark()
|
||||
// 保存主窗体引用,用于同步位置和大小
|
||||
private Form _mainForm;
|
||||
|
||||
public FrmWatermark(Form mainForm)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_mainForm = mainForm; // 接收主窗体引用
|
||||
|
||||
this.FormBorderStyle = FormBorderStyle.None;
|
||||
this.ControlBox = false;
|
||||
this.ShowInTaskbar = false;
|
||||
@@ -28,6 +34,69 @@ namespace Lskj.Main
|
||||
this.Opacity = 0.2;
|
||||
//重绘界面,绘制水印
|
||||
this.Paint += FrmWatermark_Paint;
|
||||
|
||||
|
||||
// 监听主窗体的移动和大小变化(关键修复)
|
||||
if (_mainForm != null)
|
||||
{
|
||||
_mainForm.LocationChanged += MainForm_LocationChanged;
|
||||
_mainForm.SizeChanged += MainForm_SizeChanged;
|
||||
_mainForm.VisibleChanged += MainForm_VisibleChanged;
|
||||
_mainForm.FormClosing += MainForm_FormClosing;
|
||||
}
|
||||
|
||||
// 初始同步位置和大小
|
||||
SyncPositionAndSize();
|
||||
|
||||
}
|
||||
|
||||
// 主窗体位置变化时同步水印位置
|
||||
private void MainForm_LocationChanged(object sender, EventArgs e)
|
||||
{
|
||||
SyncPositionAndSize();
|
||||
}
|
||||
|
||||
// 主窗体大小变化时同步水印大小和位置
|
||||
private void MainForm_SizeChanged(object sender, EventArgs e)
|
||||
{
|
||||
SyncPositionAndSize();
|
||||
}
|
||||
|
||||
// 主窗体显示状态变化时同步
|
||||
private void MainForm_VisibleChanged(object sender, EventArgs e)
|
||||
{
|
||||
this.Visible = _mainForm.Visible;
|
||||
if (_mainForm.Visible)
|
||||
{
|
||||
SyncPositionAndSize();
|
||||
this.BringToFront();
|
||||
}
|
||||
}
|
||||
|
||||
// 主窗体关闭时同步关闭水印
|
||||
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
// 同步水印窗体与主窗体的位置和大小
|
||||
private void SyncPositionAndSize()
|
||||
{
|
||||
if (_mainForm == null || _mainForm.IsDisposed) return;
|
||||
|
||||
// 关键修复:在多屏幕环境下正确计算位置
|
||||
this.Size = _mainForm.ClientSize;
|
||||
this.Location = _mainForm.PointToScreen(new Point(0,30));
|
||||
|
||||
// 确保水印在主窗体上方
|
||||
if (_mainForm.WindowState != FormWindowState.Minimized)
|
||||
{
|
||||
this.TopMost = true;
|
||||
this.BringToFront();
|
||||
}
|
||||
|
||||
// 强制重绘
|
||||
this.Invalidate();
|
||||
}
|
||||
|
||||
private void FrmWatermark_Paint(object sender, PaintEventArgs e)
|
||||
@@ -57,48 +126,8 @@ namespace Lskj.Main
|
||||
int x = 20;
|
||||
int y = 20;
|
||||
|
||||
for (int i = 30; i < this.Height - 40; i=i+150)
|
||||
for (int i = 30; i < this.Height - 40; i=i+200)
|
||||
{
|
||||
for (int j = 40; j < this.Width - 40; j = j + 200)
|
||||
for (int j = 40; j < this.Width - 40; j = j + 250)
|
||||
{
|
||||
graphicsText.DrawString(ERPInfo.Instance.UserName, new Font("宋体", 15, FontStyle.Bold), brush, new PointF(j,i), format, -30f);
|
||||
}
|
||||
|
||||
}
|
||||
e.Graphics.TranslateTransform(x, y);
|
||||
e.Graphics.RotateTransform(-20f);
|
||||
//e.Graphics.DrawRectangle(pen, new Rectangle(-45, -19, 90, 32));
|
||||
}
|
||||
e.Graphics.ResetTransform();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||||
//MessageUtil.Show(Message, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 鼠标穿透水印操作下方
|
||||
/// </summary>
|
||||
protected override CreateParams CreateParams
|
||||
{
|
||||
get
|
||||
{
|
||||
CreateParams cp = base.CreateParams;
|
||||
cp.ExStyle |= 0x00000020; // 设置 WS_EX_TRANSPARENT 样式
|
||||
return cp;
|
||||
}
|
||||
}
|
||||
|
||||
//protected override void OnPaintBackground(PaintEventArgs e)
|
||||
//{
|
||||
// // 不执行基类的背景绘制方法,以达到窗口穿透的效果
|
||||
//}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
graphicsText.DrawString(ERPInfo.Instanc
|
||||
Reference in New Issue
Block a user