Files
lserp_cs_6.0/插件库/Lskj.Control/LabelWatermarkLayer.cs
cyf ab56a9bcf7 基线 SVN r240
SVN-Revision: r240
2025-02-06 06:46:06 +00:00

96 lines
3.1 KiB
C#

using Lskj.Business.Impl;
using Lskj.Model;
using Lskj.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Lskj.Control
{
public partial class LabelWatermarkLayer : Panel
{
public LabelWatermarkLayer()
{
InitializeComponent();
// 设置窗体背景为透明
//重绘界面,绘制水印
this.Paint += FrmWatermark_Paint;
}
private void FrmWatermark_Paint(object sender, PaintEventArgs e)
{
try
{
this.BackColor = Color.Transparent;
GraphicsText graphicsText = new GraphicsText();
graphicsText.Graphics = e.Graphics;
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
Pen pen = new Pen(Color.Red, 2f);
int alpha = 128; // 设置透明度为128(半透明)
Color color = Color.FromArgb(200, 200, 200);
//color = Color.FromArgb(alpha, color);
SolidBrush brush = new SolidBrush(color);
if (!string.IsNullOrEmpty(ERPInfo.Instance.UserName))
{
//居中
//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);
int x = 20;
int y = 20;
for (int i = 30; i < this.Height - 40; i = i + 150)
{
for (int j = 40; j < this.Width - 40; j = j + 200)
{
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;
}
}
}
}