From 1a1c8e71fcd14858f595029f089b2d4a00202b32 Mon Sep 17 00:00:00 2001
From: ogi <Administrator@S-OGI-PC>
Date: Fri, 05 Dec 2025 09:24:16 +0900
Subject: [PATCH] プロジェクトファイルを追加。
---
HotelPms.Share.Windows/Component/ButtonFlat.cs | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 177 insertions(+), 0 deletions(-)
diff --git a/HotelPms.Share.Windows/Component/ButtonFlat.cs b/HotelPms.Share.Windows/Component/ButtonFlat.cs
new file mode 100644
index 0000000..1d306b6
--- /dev/null
+++ b/HotelPms.Share.Windows/Component/ButtonFlat.cs
@@ -0,0 +1,177 @@
+using HotelPms.Share.Windows.GraphicsApi;
+using HotelPms.Share.Windows.Util;
+using System;
+using System.ComponentModel;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Windows.Forms;
+
+namespace HotelPms.Share.Windows.Component
+{
+ public class ButtonFlat : System.Windows.Forms.Button
+ {
+ private bool m_DisableClickEvent = true;
+
+ /// <summary>
+ /// Click連打禁止 【※注意:ボタンイベントの中でFrom.Show()を使うとShownイベントなども消える場合があります。】
+ /// </summary>
+ [Description("Click連打禁止 【※注意:ボタンイベントの中でFrom.Show()を使うとShownイベントなども消える場合があります。】"), Category("拡張動作"), DefaultValue(true)]
+ public bool DisableClickEvent
+ {
+ get { return m_DisableClickEvent; }
+ set { m_DisableClickEvent = value; }
+ }
+
+ private LinearGradientMode m_GradientMode = LinearGradientMode.Horizontal;
+
+ [Description("GradientMode"), Category("拡張動作"), DefaultValue(LinearGradientMode.Horizontal)]
+ public LinearGradientMode GradientMode
+ {
+ get { return m_GradientMode; }
+ set { m_GradientMode = value; Invalidate(); }
+ }
+
+ private Color m_GradientColor = Color.Empty;
+
+ [Description("GradientColor"), Category("拡張動作")]
+ public Color GradientColor
+ {
+ get { return m_GradientColor; }
+ set { m_GradientColor = value; Invalidate(); }
+ }
+
+ private bool m_Selected = false;
+ private bool m_MouseFocused = false;
+ private StringFormat m_StringFormat = new StringFormat();
+ private Image imgEllipse = null;
+
+ protected override void Dispose(bool disposing)
+ {
+ if (imgEllipse != null) { imgEllipse.Dispose(); }
+ m_StringFormat.Dispose();
+ base.Dispose(disposing);
+ }
+
+ protected override void OnPaint(PaintEventArgs pevent)
+ {
+ base.OnPaint(pevent);
+ if (this.FlatStyle != FlatStyle.Flat) { return; }
+
+ //ControlPaint.Light
+ Color beginColor = this.m_MouseFocused ? (FlatAppearance.MouseOverBackColor == Color.Empty ? ControlPaint.Light(this.BackColor) : FlatAppearance.MouseOverBackColor) : m_Selected ? (FlatAppearance.MouseDownBackColor == Color.Empty ? ControlPaint.Light(this.BackColor) : FlatAppearance.MouseDownBackColor) : this.BackColor;
+ Color endColor = m_GradientColor == Color.Empty ? beginColor : this.m_MouseFocused ? ControlPaint.LightLight(m_GradientColor) : m_Selected ? ControlPaint.Light(m_GradientColor) : m_GradientColor;
+
+ //using (LinearGradientBrush brush = new LinearGradientBrush(this.ClientRectangle, Color.FromArgb(0, 136, 0), Color.FromArgb(0, 166, 0), m_GradientMode))
+ using (LinearGradientBrush brush = new LinearGradientBrush(this.ClientRectangle, beginColor, endColor, m_GradientMode))
+ {
+ pevent.Graphics.FillRectangle(brush, this.ClientRectangle);
+ }
+
+ //線
+ if (this.FlatAppearance.BorderSize > 0 && !this.FlatAppearance.BorderColor.Equals(Color.Empty))
+ {
+ using (Pen pen = new Pen(this.FlatAppearance.BorderColor, this.FlatAppearance.BorderSize))
+ {
+ pevent.Graphics.DrawRectangle(pen, new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width - this.FlatAppearance.BorderSize, this.ClientRectangle.Height - this.FlatAppearance.BorderSize));
+ }
+ }
+
+ Rectangle textRect = ClientRectangle;
+ if (Image != null && imgEllipse == null)
+ {
+ imgEllipse = GdiPlus.CutEllipse(Image, new Rectangle(0, 0, Image.Size.Width, Image.Size.Height), Image.Size);
+ }
+
+ if (imgEllipse != null)
+ {
+ //高さの80%で出力
+ int imgHeight = (int)(ClientRectangle.Height * 0.8F);
+ int adding = (int)(textRect.Height - imgHeight) / 2;
+ pevent.Graphics.DrawImage(imgEllipse, new Rectangle(adding, adding, imgHeight, imgHeight));
+ textRect = new Rectangle(new Point(textRect.Location.X + textRect.Height, 0), new Size(textRect.Width - textRect.Height, textRect.Height));
+ }
+
+ SetStringFormat();
+ using (SolidBrush foreBrush = new SolidBrush(this.ForeColor))
+ {
+ pevent.Graphics.DrawString(this.Text, this.Font, foreBrush, textRect, m_StringFormat);
+ }
+ }
+
+ private void SetStringFormat()
+ {
+ switch (this.TextAlign)
+ {
+ case ContentAlignment.BottomCenter:
+ case ContentAlignment.BottomLeft:
+ case ContentAlignment.BottomRight:
+ m_StringFormat.LineAlignment = StringAlignment.Far;
+ break;
+ case ContentAlignment.MiddleCenter:
+ case ContentAlignment.MiddleLeft:
+ case ContentAlignment.MiddleRight:
+ m_StringFormat.LineAlignment = StringAlignment.Center;
+ break;
+ case ContentAlignment.TopCenter:
+ case ContentAlignment.TopLeft:
+ case ContentAlignment.TopRight:
+ m_StringFormat.LineAlignment = StringAlignment.Near;
+ break;
+ }
+
+ switch (this.TextAlign)
+ {
+ case ContentAlignment.TopLeft:
+ case ContentAlignment.BottomLeft:
+ case ContentAlignment.MiddleLeft:
+ m_StringFormat.Alignment = StringAlignment.Near;
+ break;
+ case ContentAlignment.MiddleCenter:
+ case ContentAlignment.BottomCenter:
+ case ContentAlignment.TopCenter:
+ m_StringFormat.Alignment = StringAlignment.Center;
+ break;
+ case ContentAlignment.BottomRight:
+ case ContentAlignment.MiddleRight:
+ case ContentAlignment.TopRight:
+ m_StringFormat.Alignment = StringAlignment.Far;
+ break;
+ }
+ }
+
+ protected override void OnEnter(EventArgs e)
+ {
+ base.OnEnter(e);
+ m_Selected = true;
+ }
+
+ protected override void OnLeave(EventArgs e)
+ {
+ base.OnLeave(e);
+ m_Selected = false;
+ }
+
+ protected override void OnMouseEnter(EventArgs e)
+ {
+ base.OnMouseEnter(e);
+ m_MouseFocused = true;
+ }
+
+ protected override void OnMouseLeave(EventArgs e)
+ {
+ base.OnMouseLeave(e);
+ m_MouseFocused = false;
+ }
+
+ protected override void OnClick(EventArgs e)
+ {
+ //System.Diagnostics.Debug.WriteLine("base.OnClick begin");
+ base.OnClick(e);
+
+ //System.Diagnostics.Debug.WriteLine("base.OnClick end ");
+
+ //保留されているメッセージを削除し、2度押しを許可しない
+ if (m_DisableClickEvent) { RemovePeekMessage.Invoke(); }
+ }
+ }
+}
--
Gitblit v1.10.0