+ UIScrollingText:文字滚动显示控件,增加控件

This commit is contained in:
Sunny 2020-06-25 21:23:26 +08:00
parent d7621596be
commit 9d12d58523
9 changed files with 312 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -51,11 +51,17 @@
this.uiScrollBar2 = new Sunny.UI.UIScrollBar();
this.uiScrollBar3 = new Sunny.UI.UIScrollBar();
this.uiScrollBar4 = new Sunny.UI.UIScrollBar();
this.uiLine6 = new Sunny.UI.UILine();
this.uiScrollingText1 = new Sunny.UI.UIScrollingText();
this.uiScrollingText2 = new Sunny.UI.UIScrollingText();
this.PagePanel.SuspendLayout();
this.SuspendLayout();
//
// PagePanel
//
this.PagePanel.Controls.Add(this.uiScrollingText2);
this.PagePanel.Controls.Add(this.uiScrollingText1);
this.PagePanel.Controls.Add(this.uiLine6);
this.PagePanel.Controls.Add(this.uiScrollBar4);
this.PagePanel.Controls.Add(this.uiScrollBar3);
this.PagePanel.Controls.Add(this.uiScrollBar2);
@ -316,6 +322,42 @@
this.uiScrollBar4.TabIndex = 45;
this.uiScrollBar4.Text = "uiScrollBar4";
//
// uiLine6
//
this.uiLine6.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiLine6.Location = new System.Drawing.Point(30, 346);
this.uiLine6.MinimumSize = new System.Drawing.Size(16, 16);
this.uiLine6.Name = "uiLine6";
this.uiLine6.Size = new System.Drawing.Size(319, 20);
this.uiLine6.TabIndex = 47;
this.uiLine6.Text = "UIScrollingText";
this.uiLine6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// uiScrollingText1
//
this.uiScrollingText1.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255)))));
this.uiScrollingText1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiScrollingText1.ForeColor = System.Drawing.Color.Red;
this.uiScrollingText1.Location = new System.Drawing.Point(27, 372);
this.uiScrollingText1.Name = "uiScrollingText1";
this.uiScrollingText1.ScrollingType = Sunny.UI.UIScrollingText.UIScrollingType.LeftToRight;
this.uiScrollingText1.Size = new System.Drawing.Size(322, 35);
this.uiScrollingText1.Style = Sunny.UI.UIStyle.Custom;
this.uiScrollingText1.StyleCustomMode = true;
this.uiScrollingText1.TabIndex = 48;
this.uiScrollingText1.Text = "赠人玫瑰手有余香";
//
// uiScrollingText2
//
this.uiScrollingText2.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255)))));
this.uiScrollingText2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiScrollingText2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
this.uiScrollingText2.Location = new System.Drawing.Point(27, 413);
this.uiScrollingText2.Name = "uiScrollingText2";
this.uiScrollingText2.Size = new System.Drawing.Size(322, 35);
this.uiScrollingText2.TabIndex = 49;
this.uiScrollingText2.Text = "赠人玫瑰手有余香";
//
// FOther
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 21F);
@ -352,5 +394,8 @@
private UILine uiLine1;
private UIScrollBar uiScrollBar4;
private UIScrollBar uiScrollBar3;
private UILine uiLine6;
private UIScrollingText uiScrollingText1;
private UIScrollingText uiScrollingText2;
}
}

View File

@ -120,4 +120,7 @@
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>35</value>
</metadata>
</root>

View File

@ -0,0 +1,258 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace Sunny.UI
{
[ToolboxItem(true)]
public class UIScrollingText : UIControl
{
private readonly Timer timer = new Timer();
private int XPos = int.MinValue;
private int XPos1 = int.MaxValue;
private int interval = 200;
private int TextWidth = Int32.MinValue;
public UIScrollingText()
{
fillColor = UIStyles.Blue.PlainColor;
foreColor = UIStyles.Blue.RectColor;
Reset();
timer.Interval = interval;
timer.Tick += Timer_Tick;
timer.Start();
}
private void Reset()
{
XPos = int.MinValue;
XPos1 = int.MaxValue;
}
~UIScrollingText()
{
timer.Stop();
}
[DefaultValue(200),Description("刷新间隔")]
public int Interval
{
get => interval;
set
{
interval = Math.Max(value,50);
timer.Stop();
timer.Interval = interval;
timer.Start();
}
}
private int offset = 10;
[DefaultValue(10),Description("偏移量")]
public int Offset
{
get => offset;
set => offset = Math.Max(2, value);
}
private void Timer_Tick(object sender, EventArgs e)
{
if (XPos == Int32.MinValue)
{
Invalidate();
}
else
{
if (ScrollingType == UIScrollingType.RightToLeft)
{
XPos -= Offset;
if (XPos + TextWidth < 0)
{
XPos = XPos1 - Offset;
XPos1 = int.MaxValue;
}
}
if (ScrollingType == UIScrollingType.LeftToRight)
{
XPos += Offset;
if (XPos > Width)
{
XPos = XPos1 + Offset;
XPos1 = int.MaxValue;
}
}
Invalidate();
}
}
protected override void OnClick(EventArgs e)
{
timer.Enabled = !timer.Enabled;
base.OnClick(e);
}
protected override void OnPaintFore(Graphics g, GraphicsPath path)
{
SizeF sf = g.MeasureString(Text, Font);
int y = (int)((Height - sf.Height) / 2);
if (XPos == int.MinValue)
{
XPos = (int)((Width - sf.Width) / 2);
TextWidth = (int)sf.Width;
}
g.DrawString(Text, Font, ForeColor, XPos, y);
if (ScrollingType == UIScrollingType.LeftToRight)
{
if (TextWidth <= Width)
{
if (XPos + TextWidth > Width)
{
XPos1 = XPos - Width;
g.DrawString(Text, Font, ForeColor, XPos1, y);
}
}
else
{
if (XPos > 0)
{
if (XPos1 == int.MaxValue)
XPos1 = Offset - TextWidth;
else
XPos1 += Offset;
g.DrawString(Text, Font, ForeColor, XPos1, y);
}
}
}
if (ScrollingType == UIScrollingType.RightToLeft)
{
if (TextWidth <= Width)
{
if (XPos < 0)
{
XPos1 = Width + XPos;
g.DrawString(Text, Font, ForeColor, XPos1, y);
}
}
else
{
if (XPos + TextWidth < Width - Offset)
{
if (XPos1 == int.MaxValue)
XPos1 = Width - Offset;
else
XPos1 -= Offset;
g.DrawString(Text, Font, ForeColor, XPos1, y);
}
}
}
}
protected override void OnSizeChanged(EventArgs e)
{
Reset();
base.OnSizeChanged(e);
}
private UIScrollingType scrollingType;
[DefaultValue(UIScrollingType.RightToLeft), Description("滚动方向")]
public UIScrollingType ScrollingType
{
get => scrollingType;
set
{
scrollingType = value;
Reset();
Invalidate();
}
}
protected override void OnTextChanged(EventArgs e)
{
Reset();
base.OnTextChanged(e);
}
public enum UIScrollingType
{
RightToLeft,
LeftToRight
}
public override void SetStyleColor(UIBaseStyle uiColor)
{
base.SetStyleColor(uiColor);
if (uiColor.IsCustom()) return;
fillColor = uiColor.PlainColor;
foreColor = uiColor.RectColor;
Invalidate();
}
/// <summary>
/// 填充颜色,当值为背景色或透明色或空值则不填充
/// </summary>
[Description("填充颜色"), Category("自定义")]
[DefaultValue(typeof(Color), "80, 160, 255")]
public Color FillColor
{
get => fillColor;
set => SetFillColor(value);
}
/// <summary>
/// 字体颜色
/// </summary>
[Description("字体颜色"), Category("自定义")]
[DefaultValue(typeof(Color), "White")]
public override Color ForeColor
{
get => foreColor;
set => SetForeColor(value);
}
[DefaultValue(typeof(Color), "244, 244, 244")]
public Color FillDisableColor
{
get => fillDisableColor;
set => SetFillDisableColor(value);
}
[DefaultValue(typeof(Color), "173, 178, 181")]
public Color RectDisableColor
{
get => rectDisableColor;
set => SetRectDisableColor(value);
}
[DefaultValue(typeof(Color), "109, 109, 103")]
public Color ForeDisableColor
{
get => foreDisableColor;
set => SetForeDisableColor(value);
}
/// <summary>
/// 边框颜色
/// </summary>
[Description("边框颜色"), Category("自定义")]
[DefaultValue(typeof(Color), "80, 160, 255")]
public Color RectColor
{
get => rectColor;
set => SetRectColor(value);
}
}
}

View File

@ -114,6 +114,9 @@
<Compile Include="Controls\UIRichTextBox.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\UIScrollingText.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\UITimePicker.cs">
<SubType>UserControl</SubType>
</Compile>

View File

@ -1,5 +1,8 @@
+ 增加; - 删除; * 修改
2020.06.25
+ UIScrollingText增加控件
2020.06.24
+ UICheckBoxGroup增加全选、全不选、反选