* UITextBox:增加图标和字体图标的显示

This commit is contained in:
Sunny 2021-06-01 17:49:55 +08:00
parent b1543067ae
commit 07dd22a65f
11 changed files with 146 additions and 18 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -45,12 +45,16 @@
this.uiLine2 = new Sunny.UI.UILine();
this.uiLine3 = new Sunny.UI.UILine();
this.uiTextBox4 = new Sunny.UI.UITextBox();
this.uiTextBox6 = new Sunny.UI.UITextBox();
this.uiTextBox5 = new Sunny.UI.UITextBox();
this.PagePanel.SuspendLayout();
this.uiContextMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
// PagePanel
//
this.PagePanel.Controls.Add(this.uiTextBox6);
this.PagePanel.Controls.Add(this.uiTextBox5);
this.PagePanel.Controls.Add(this.uiTextBox4);
this.PagePanel.Controls.Add(this.uiLine3);
this.PagePanel.Controls.Add(this.uiLine2);
@ -114,7 +118,7 @@
//
this.uiLabel2.AutoSize = true;
this.uiLabel2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiLabel2.Location = new System.Drawing.Point(38, 97);
this.uiLabel2.Location = new System.Drawing.Point(38, 175);
this.uiLabel2.Name = "uiLabel2";
this.uiLabel2.Size = new System.Drawing.Size(65, 21);
this.uiLabel2.TabIndex = 6;
@ -129,7 +133,7 @@
this.uiTextBox2.FillColor = System.Drawing.Color.White;
this.uiTextBox2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiTextBox2.IntValue = 5;
this.uiTextBox2.Location = new System.Drawing.Point(117, 93);
this.uiTextBox2.Location = new System.Drawing.Point(117, 171);
this.uiTextBox2.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiTextBox2.Maximum = 9D;
this.uiTextBox2.Minimum = 0D;
@ -147,7 +151,7 @@
//
this.uiLabel3.AutoSize = true;
this.uiLabel3.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiLabel3.Location = new System.Drawing.Point(38, 136);
this.uiLabel3.Location = new System.Drawing.Point(38, 214);
this.uiLabel3.Name = "uiLabel3";
this.uiLabel3.Size = new System.Drawing.Size(65, 21);
this.uiLabel3.TabIndex = 8;
@ -160,7 +164,7 @@
this.uiTextBox3.Cursor = System.Windows.Forms.Cursors.IBeam;
this.uiTextBox3.FillColor = System.Drawing.Color.White;
this.uiTextBox3.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiTextBox3.Location = new System.Drawing.Point(117, 132);
this.uiTextBox3.Location = new System.Drawing.Point(117, 210);
this.uiTextBox3.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiTextBox3.Maximum = 2147483647D;
this.uiTextBox3.Minimum = -2147483648D;
@ -225,7 +229,7 @@
this.uiRichTextBox1.ContextMenuStrip = this.uiContextMenuStrip1;
this.uiRichTextBox1.FillColor = System.Drawing.Color.White;
this.uiRichTextBox1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiRichTextBox1.Location = new System.Drawing.Point(388, 219);
this.uiRichTextBox1.Location = new System.Drawing.Point(388, 290);
this.uiRichTextBox1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiRichTextBox1.MinimumSize = new System.Drawing.Size(1, 1);
this.uiRichTextBox1.Name = "uiRichTextBox1";
@ -254,7 +258,7 @@
// uiLine2
//
this.uiLine2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiLine2.Location = new System.Drawing.Point(30, 180);
this.uiLine2.Location = new System.Drawing.Point(30, 251);
this.uiLine2.MinimumSize = new System.Drawing.Size(16, 16);
this.uiLine2.Name = "uiLine2";
this.uiLine2.Size = new System.Drawing.Size(308, 20);
@ -265,7 +269,7 @@
// uiLine3
//
this.uiLine3.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiLine3.Location = new System.Drawing.Point(388, 180);
this.uiLine3.Location = new System.Drawing.Point(388, 251);
this.uiLine3.MinimumSize = new System.Drawing.Size(16, 16);
this.uiLine3.Name = "uiLine3";
this.uiLine3.Size = new System.Drawing.Size(308, 20);
@ -278,7 +282,7 @@
this.uiTextBox4.Cursor = System.Windows.Forms.Cursors.IBeam;
this.uiTextBox4.FillColor = System.Drawing.Color.White;
this.uiTextBox4.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiTextBox4.Location = new System.Drawing.Point(30, 219);
this.uiTextBox4.Location = new System.Drawing.Point(30, 290);
this.uiTextBox4.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiTextBox4.Maximum = 2147483647D;
this.uiTextBox4.Minimum = -2147483648D;
@ -294,6 +298,42 @@
this.uiTextBox4.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
this.uiTextBox4.Watermark = "水印文字";
//
// uiTextBox6
//
this.uiTextBox6.Cursor = System.Windows.Forms.Cursors.IBeam;
this.uiTextBox6.FillColor = System.Drawing.Color.White;
this.uiTextBox6.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiTextBox6.Location = new System.Drawing.Point(117, 132);
this.uiTextBox6.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiTextBox6.Maximum = 2147483647D;
this.uiTextBox6.Minimum = -2147483648D;
this.uiTextBox6.MinimumSize = new System.Drawing.Size(1, 1);
this.uiTextBox6.Name = "uiTextBox6";
this.uiTextBox6.Padding = new System.Windows.Forms.Padding(5);
this.uiTextBox6.Size = new System.Drawing.Size(221, 29);
this.uiTextBox6.Symbol = 61461;
this.uiTextBox6.TabIndex = 37;
this.uiTextBox6.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
this.uiTextBox6.Watermark = "水印文字";
//
// uiTextBox5
//
this.uiTextBox5.Cursor = System.Windows.Forms.Cursors.IBeam;
this.uiTextBox5.FillColor = System.Drawing.Color.White;
this.uiTextBox5.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiTextBox5.Icon = global::Sunny.UI.Demo.Properties.Resources.Home_32x32;
this.uiTextBox5.Location = new System.Drawing.Point(117, 93);
this.uiTextBox5.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiTextBox5.Maximum = 2147483647D;
this.uiTextBox5.Minimum = -2147483648D;
this.uiTextBox5.MinimumSize = new System.Drawing.Size(1, 1);
this.uiTextBox5.Name = "uiTextBox5";
this.uiTextBox5.Padding = new System.Windows.Forms.Padding(5);
this.uiTextBox5.Size = new System.Drawing.Size(221, 29);
this.uiTextBox5.TabIndex = 36;
this.uiTextBox5.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
this.uiTextBox5.Watermark = "水印文字";
//
// FTextBox
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
@ -327,5 +367,7 @@
private UILine uiLine2;
private UIContextMenuStrip uiContextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem aaToolStripMenuItem;
private UITextBox uiTextBox6;
private UITextBox uiTextBox5;
}
}

View File

@ -440,6 +440,16 @@ namespace Sunny.UI.Demo.Properties {
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>
internal static System.Drawing.Bitmap Home_32x32 {
get {
object obj = ResourceManager.GetObject("Home_32x32", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>

View File

@ -205,6 +205,9 @@
<data name="HMF1" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\HMF1.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Home_32x32" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Home_32x32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="inter" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\inter.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -650,6 +650,7 @@
<None Include="Resources\7.png" />
<None Include="Resources\8.png" />
<None Include="Resources\9.png" />
<None Include="Resources\Home_32x32.png" />
<Content Include="SunnyUI.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@ -44,10 +44,9 @@ namespace Sunny.UI
SetStyleFlags();
CalcEditHeight();
Height = MinHeight;
iconSize = MinHeight;
ShowText = false;
Font = UIFontColor.Font;
Padding = new Padding(0, 0, 0, 0);
Padding = new Padding(0);
edit.Top = (Height - edit.Height) / 2;
edit.Left = 4;
@ -378,16 +377,24 @@ namespace Sunny.UI
if (Height > MaxHeight) Height = MaxHeight;
edit.Top = (Height - edit.Height) / 2;
if (icon == null)
if (icon == null && Symbol == 0)
{
edit.Left = 4 + Padding.Left;
edit.Width = Width - 8 - Padding.Left - Padding.Right;
}
else
{
if (icon != null)
{
edit.Left = 4 + iconSize + Padding.Left;
edit.Width = Width - 8 - iconSize - Padding.Left - Padding.Right;
}
else if (Symbol > 0)
{
edit.Left = 4 + SymbolSize + Padding.Left;
edit.Width = Width - 8 - SymbolSize - Padding.Left - Padding.Right;
}
}
}
else
{
@ -838,14 +845,14 @@ namespace Sunny.UI
}
}
private int iconSize;
[Description("图标大小(方形)"), Category("SunnyUI")]
private int iconSize = 24;
[Description("图标大小(方形)"), Category("SunnyUI"), DefaultValue(24)]
public int IconSize
{
get => iconSize;
set
{
iconSize = value;
iconSize = Math.Min(MinHeight, value);
SizeChange();
Invalidate();
}
@ -854,9 +861,74 @@ namespace Sunny.UI
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (!multiline && icon != null)
if (multiline) return;
if (icon != null)
{
e.Graphics.DrawImage(icon, new Rectangle(4, (Height - iconSize) / 2, iconSize, iconSize), new Rectangle(0, 0, iconSize, iconSize), GraphicsUnit.Pixel);
e.Graphics.DrawImage(icon, new Rectangle(4, (Height - iconSize) / 2, iconSize, iconSize), new Rectangle(0, 0, icon.Width, icon.Height), GraphicsUnit.Pixel);
}
else if (Symbol != 0)
{
e.Graphics.DrawFontImage(Symbol, SymbolSize, SymbolColor, new Rectangle(4 + symbolOffset.X, (Height - SymbolSize) / 2 + 1 + symbolOffset.Y, SymbolSize, SymbolSize));
}
}
private Point symbolOffset = new Point(0, 0);
[DefaultValue(typeof(Point), "0, 0")]
[Description("字体图标偏移"), Category("SunnyUI")]
public Point SymbolOffset
{
get => symbolOffset;
set
{
symbolOffset = value;
Invalidate();
}
}
public Color _symbolColor = UIFontColor.Primary;
[DefaultValue(typeof(Color), "48, 48, 48")]
[Description("字体图标颜色"), Category("SunnyUI")]
public Color SymbolColor
{
get => _symbolColor;
set
{
_symbolColor = value;
Invalidate();
}
}
private int _symbol = 0;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[Editor(typeof(UIImagePropertyEditor), typeof(UITypeEditor))]
[DefaultValue(0)]
[Description("字体图标"), Category("SunnyUI")]
public int Symbol
{
get => _symbol;
set
{
_symbol = value;
SizeChange();
Invalidate();
}
}
private int _symbolSize = 24;
[DefaultValue(24)]
[Description("字体图标大小"), Category("SunnyUI")]
public int SymbolSize
{
get => _symbolSize;
set
{
_symbolSize = Math.Max(value, 16);
_symbolSize = Math.Min(value, MinHeight);
SizeChange();
Invalidate();
}
}
}