SVN-Revision: r983
This commit is contained in:
cyf
2025-09-10 09:17:53 +00:00
parent 6e13cdd916
commit 9c20dd48c8
3 changed files with 75 additions and 24 deletions
+2 -2
View File
@@ -141,8 +141,8 @@ namespace Lskj.Main
watermarkForm = new FrmWatermark(this);
watermarkForm.Size = this.ClientSize; // 设置水印窗体的大小与主窗体客户端区域相同
watermarkForm.Location = this.PointToScreen(new Point(0, 0)); // 将水印窗体定位到主窗体的位置
watermarkForm.TopMost = true; // 确保水印窗体始终位于最顶层
watermarkForm.Show(); // 显示水印窗体
//watermarkForm.TopMost = true; // 确保水印窗体始终位于最顶层
watermarkForm.Show(this); // 显示水印窗体
//watermarkForm.StartPosition = FormStartPosition.CenterScreen;//居中显示
//watermarkForm.Show(this);// 使用Show方法的overload,设置为最上层显示
this.SizeChanged += FrmMain_SizeChanged;
+69 -17
View File
@@ -1,4 +1,5 @@
using Lskj.Business.Impl;
using Lskj.Business;
using Lskj.Business.Impl;
using Lskj.Model;
using Lskj.Util;
using System;
@@ -31,7 +32,7 @@ namespace Lskj.Main
Color color = Color.FromArgb(175, 175, 175);
this.BackColor = color;
this.TransparencyKey = color;
this.Opacity = 0.2;
this.Opacity = 0.3;
//重绘界面,绘制水印
this.Paint += FrmWatermark_Paint;
@@ -86,12 +87,12 @@ namespace Lskj.Main
// 关键修复:在多屏幕环境下正确计算位置
this.Size = _mainForm.ClientSize;
this.Location = _mainForm.PointToScreen(new Point(0,30));
this.Location = _mainForm.PointToScreen(new Point(0, 30));
// 确保水印在主窗体上方
if (_mainForm.WindowState != FormWindowState.Minimized)
{
this.TopMost = true;
//this.TopMost = true;
this.BringToFront();
}
@@ -110,24 +111,75 @@ namespace Lskj.Main
format.LineAlignment = StringAlignment.Center;
Pen pen = new Pen(Color.Red, 2f);
int alpha = 128; // 设置透明度为128(半透明)
Color color = Color.FromArgb(200, 200, 200);
Font watermarkFont = new Font("宋体", 15, FontStyle.Bold);
Color color = Color.FromArgb(200, 200, 200);
//int alpha = 128; // 设置透明度为128(半透明)
//color = Color.FromArgb(alpha, color);
SolidBrush brush = new SolidBrush(color);
if (!string.IsNullOrEmpty(ERPInfo.Instance.UserName))
string content = ERPInfo.Instance.UserName;
if (!string.IsNullOrWhiteSpace(SystemInfo.Instance.WatermarkContent))
{
//居中
//int x = (this.Width - 90) / 2;
//int y = (this.Height - 32) / 2;
//graphicsText.DrawString(ERPInfo.Instance.UserName, new Font("宋体", 20, FontStyle.Bold), brush, new PointF(x, y), format, -20f);
//graphicsText.DrawString(ERPInfo.Instance.UserName, new Font("宋体", 20, FontStyle.Bold), brush, new PointF(x-50, y), format, -20f);
content = ReplaceHelper.ReplaceUserInfo(SystemInfo.Instance.WatermarkContent);
}
int x = 20;
int y = 20;
if (!string.IsNullOrEmpty(content))
{
// 1. 测量文本实际尺寸
SizeF textSize = e.Graphics.MeasureString(content, watermarkFont);
for (int i = 30; i < this.Height - 40; i=i+200)
// 2. 计算旋转角度和左侧预留空间
float rotationAngle = -30f; // 旋转角度
double radians = rotationAngle * Math.PI / 180; // 转换为弧度
// 计算旋转后文本左侧可能超出的最大距离
float leftOverlap = (float)(Math.Abs(textSize.Width * Math.Cos(radians)) / 2 +
Math.Abs(textSize.Height * Math.Sin(radians)) / 2);
// 3. 计算动态间距
int horizontalSpacing = (int)(textSize.Width * 1.5);
int verticalSpacing = (int)(textSize.Height * 2);
// 设置最小间距
horizontalSpacing = Math.Max(horizontalSpacing, 250);
verticalSpacing = Math.Max(verticalSpacing, 150);
// 4. 计算绘制区域(只限制左侧,不限制右侧)
int marginLeft = (int)leftOverlap; // 左侧预留空间,防止超出
int marginTop = 30; // 顶部基础边距
int marginBottom = 40; // 底部基础边距
int startX = marginLeft; // 起始X,确保左侧不超出
int startY = marginTop; // 起始Y
int maxY = this.Height - marginBottom; // 最大Y,避免底部超出
// 5. 绘制水印网格
for (int i = startY; i < maxY; i += verticalSpacing)
{
for (int j = 40; j < this.Width - 40; j = j + 250)
// 只限制左侧,右侧允许超出(不设置maxX)
for (int j = startX; j < this.Width + horizontalSpacing; j += horizontalSpacing)
{
graphicsText.DrawString(ERPInfo.Instanc
var state = e.Graphics.Save();
e.Graphics.TranslateTransform(j, i);
e.Graphics.RotateTransform(rotationAngle);
graphicsText.DrawString(
content,
watermarkFont,
brush,
new PointF(0, 0),
format,
0f);
e.Graphics.Restore(state);
}
}
}
//if (!string.IsNullOrEmpty(content))
//{
// int x = 20;
// int y = 20;
// for (int i = 30; i < this.Height - 40; i=i+200)
// {
// for (int j = 40; j < this.Width - 40; j = j + 250)
+4 -5
View File
@@ -17,23 +17,22 @@ using System.Reflection;
using System.IO;
using Lskj.Control.BrowserSetting;
using Microsoft.Win32;
using System.Runtime.InteropServices;
namespace Lskj.Main
{
static class Program
{
[DllImport("user32.dll")]
private static extern bool SetProcessDpiAwarenessContext(IntPtr dpiContext);
//[DllImport("user32.dll")]
//private static extern bool SetProcessDpiAwarenessContext(IntPtr dpiContext);
private static readonly IntPtr DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = new IntPtr(-4);
//private static readonly IntPtr DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = new IntPtr(-4);
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
//SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
CefRuntime.Load();//cef浏览器模块设置加载
var mainArgs = new CefMainArgs(args);
var app = new DemoCefApp();