diff --git a/SunnyUI/Controls/UIGroupBox.cs b/SunnyUI/Controls/UIGroupBox.cs index 950d8893..7047973b 100644 --- a/SunnyUI/Controls/UIGroupBox.cs +++ b/SunnyUI/Controls/UIGroupBox.cs @@ -44,6 +44,9 @@ namespace Sunny.UI SetStyleFlags(true, false); } + [Browsable(false)] + public override string[] FormTranslatorProperties => ["Text"]; + private void UIGroupBox_TextAlignmentChange(object sender, ContentAlignment alignment) { Invalidate(); diff --git a/SunnyUI/Controls/UIHeaderButton.cs b/SunnyUI/Controls/UIHeaderButton.cs index 59a38604..85ef98c6 100644 --- a/SunnyUI/Controls/UIHeaderButton.cs +++ b/SunnyUI/Controls/UIHeaderButton.cs @@ -71,6 +71,9 @@ namespace Sunny.UI rectDisableColor = UIStyles.Blue.RectDisableColor; } + [Browsable(false)] + public override string[] FormTranslatorProperties => ["Text"]; + /// /// 设置控件缩放比例 /// diff --git a/SunnyUI/Controls/UILabel.cs b/SunnyUI/Controls/UILabel.cs index c3378581..03808757 100644 --- a/SunnyUI/Controls/UILabel.cs +++ b/SunnyUI/Controls/UILabel.cs @@ -34,7 +34,7 @@ namespace Sunny.UI [ToolboxItem(true)] [DefaultEvent("Click")] [DefaultProperty("Text")] - public class UILabel : Label, IStyleInterface, IZoomScale + public class UILabel : Label, IStyleInterface, IZoomScale, IFormTranslator { public UILabel() { @@ -43,6 +43,14 @@ namespace Sunny.UI ForeColor = UIStyles.Blue.LabelForeColor; } + [Browsable(false)] + [Description("控件在界面显示时需要多语翻译的属性名称数组"), Category("SunnyUI")] + public string[] FormTranslatorProperties => ["Text"]; + + [DefaultValue(false)] + [Description("控件是否显示多语内置资源"), Category("SunnyUI")] + public bool ShowBuiltInResources { get; set; } = false; + /// /// 禁止控件跟随窗体缩放 /// @@ -160,7 +168,7 @@ namespace Sunny.UI [ToolboxItem(true)] [DefaultEvent("Click")] [DefaultProperty("Text")] - public sealed class UILinkLabel : LinkLabel, IStyleInterface, IZoomScale + public sealed class UILinkLabel : LinkLabel, IStyleInterface, IZoomScale, IFormTranslator { public UILinkLabel() { @@ -174,6 +182,14 @@ namespace Sunny.UI base.LinkColor = linkColor = ForeColor = UIStyles.Blue.LabelForeColor; } + [Browsable(false)] + [Description("控件在界面显示时需要多语翻译的属性名称数组"), Category("SunnyUI")] + public string[] FormTranslatorProperties => ["Text"]; + + [DefaultValue(false)] + [Description("控件是否显示多语内置资源"), Category("SunnyUI")] + public bool ShowBuiltInResources { get; set; } = false; + /// /// 禁止控件跟随窗体缩放 /// diff --git a/SunnyUI/Controls/UILedDisplay.cs b/SunnyUI/Controls/UILedDisplay.cs index a910970c..5304e4db 100644 --- a/SunnyUI/Controls/UILedDisplay.cs +++ b/SunnyUI/Controls/UILedDisplay.cs @@ -31,7 +31,7 @@ namespace Sunny.UI /// LED显示屏 /// [DefaultProperty("Text")] - public class UILedDisplay : Control + public class UILedDisplay : Control, IFormTranslator { #region 组件设计器生成的代码 @@ -85,6 +85,14 @@ namespace Sunny.UI Version = UIGlobal.Version; } + [Browsable(false)] + [Description("控件在界面显示时需要多语翻译的属性名称数组"), Category("SunnyUI")] + public string[] FormTranslatorProperties => ["Text"]; + + [DefaultValue(false)] + [Description("控件是否显示多语内置资源"), Category("SunnyUI")] + public bool ShowBuiltInResources { get; set; } = false; + public string Version { get; } /// diff --git a/SunnyUI/Controls/UILedLabel.cs b/SunnyUI/Controls/UILedLabel.cs index 733d9da5..ffd30274 100644 --- a/SunnyUI/Controls/UILedLabel.cs +++ b/SunnyUI/Controls/UILedLabel.cs @@ -39,6 +39,9 @@ namespace Sunny.UI foreColor = UIStyles.Blue.LedLabelForeColor; } + [Browsable(false)] + public override string[] FormTranslatorProperties => ["Text"]; + /// /// 重载绘图 /// diff --git a/SunnyUI/Controls/UILine.cs b/SunnyUI/Controls/UILine.cs index a29d1ea2..630e11d2 100644 --- a/SunnyUI/Controls/UILine.cs +++ b/SunnyUI/Controls/UILine.cs @@ -48,6 +48,9 @@ namespace Sunny.UI rectColor = UIStyles.Blue.LineRectColor; } + [Browsable(false)] + public override string[] FormTranslatorProperties => ["Text"]; + public enum LineDirection { /// diff --git a/SunnyUI/Controls/UIMiniPagination.cs b/SunnyUI/Controls/UIMiniPagination.cs index 442a5947..8ea3e670 100644 --- a/SunnyUI/Controls/UIMiniPagination.cs +++ b/SunnyUI/Controls/UIMiniPagination.cs @@ -109,6 +109,7 @@ namespace Sunny.UI buttons[i].MouseLeave += UIDataGridPage_MouseLeave; buttons[i].Click += UIDataGridPage_Click; buttons[i].Size = new System.Drawing.Size(32, 32); + buttons[i].ShowBuiltInResources = true; } buttonTags.TryAdd(b0, -1); diff --git a/SunnyUI/Controls/UIPagination.cs b/SunnyUI/Controls/UIPagination.cs index 2331d740..cd87c215 100644 --- a/SunnyUI/Controls/UIPagination.cs +++ b/SunnyUI/Controls/UIPagination.cs @@ -678,6 +678,7 @@ namespace Sunny.UI uiLabel2.ForeColor = Color.FromArgb(48, 48, 48); uiLabel2.Location = new Point(726, 10); uiLabel2.Name = "uiLabel2"; + uiLabel2.ShowBuiltInResources = true; uiLabel2.Size = new Size(21, 14); uiLabel2.TabIndex = 2; uiLabel2.Text = "页"; @@ -691,6 +692,7 @@ namespace Sunny.UI uiLabel1.ForeColor = Color.FromArgb(48, 48, 48); uiLabel1.Location = new Point(650, 10); uiLabel1.Name = "uiLabel1"; + uiLabel1.ShowBuiltInResources = true; uiLabel1.Size = new Size(21, 14); uiLabel1.TabIndex = 0; uiLabel1.Text = "第"; diff --git a/SunnyUI/Controls/UIPanel.cs b/SunnyUI/Controls/UIPanel.cs index 5c8d814b..b671b98c 100644 --- a/SunnyUI/Controls/UIPanel.cs +++ b/SunnyUI/Controls/UIPanel.cs @@ -45,6 +45,9 @@ namespace Sunny.UI SetStyleFlags(true, false, true); } + [Browsable(false)] + public override string[] FormTranslatorProperties => ["Text"]; + /// /// 字体颜色 /// diff --git a/SunnyUI/Controls/UIRadioButton.cs b/SunnyUI/Controls/UIRadioButton.cs index 75eb09a6..76ec1633 100644 --- a/SunnyUI/Controls/UIRadioButton.cs +++ b/SunnyUI/Controls/UIRadioButton.cs @@ -60,6 +60,9 @@ namespace Sunny.UI fillColor = UIStyles.Blue.CheckBoxColor; } + [Browsable(false)] + public override string[] FormTranslatorProperties => ["Text"]; + /// /// 重载绘图 /// diff --git a/SunnyUI/Controls/UISmoothLabel.cs b/SunnyUI/Controls/UISmoothLabel.cs index 45298683..cbcee821 100644 --- a/SunnyUI/Controls/UISmoothLabel.cs +++ b/SunnyUI/Controls/UISmoothLabel.cs @@ -33,7 +33,7 @@ namespace Sunny.UI [ToolboxItem(true)] [DefaultEvent("Click")] [DefaultProperty("Text")] - public sealed class UISmoothLabel : Label, IStyleInterface, IZoomScale + public sealed class UISmoothLabel : Label, IStyleInterface, IZoomScale, IFormTranslator { private PointF point; private SizeF drawSize; @@ -55,6 +55,14 @@ namespace Sunny.UI Size = new Size(300, 60); } + [Browsable(false)] + [Description("控件在界面显示时需要多语翻译的属性名称数组"), Category("SunnyUI")] + public string[] FormTranslatorProperties => ["Text"]; + + [DefaultValue(false)] + [Description("控件是否显示多语内置资源"), Category("SunnyUI")] + public bool ShowBuiltInResources { get; set; } = false; + protected override void Dispose(bool disposing) { if (disposing) diff --git a/SunnyUI/Controls/UISwitch.cs b/SunnyUI/Controls/UISwitch.cs index 070c9b7a..2388f44b 100644 --- a/SunnyUI/Controls/UISwitch.cs +++ b/SunnyUI/Controls/UISwitch.cs @@ -52,6 +52,9 @@ namespace Sunny.UI Square } + [Browsable(false)] + public override string[] FormTranslatorProperties => ["ActiveText", "InActiveText"]; + public UISwitch() { SetStyleFlags(); diff --git a/SunnyUI/Controls/UISymbolLabel.cs b/SunnyUI/Controls/UISymbolLabel.cs index b7acf3fb..f27ef363 100644 --- a/SunnyUI/Controls/UISymbolLabel.cs +++ b/SunnyUI/Controls/UISymbolLabel.cs @@ -53,6 +53,9 @@ namespace Sunny.UI Height = 35; } + [Browsable(false)] + public override string[] FormTranslatorProperties => ["Text"]; + private bool autoSize; [Browsable(true)] diff --git a/SunnyUI/Controls/UITurnSwitch.cs b/SunnyUI/Controls/UITurnSwitch.cs index 8f7bedf1..1c36de73 100644 --- a/SunnyUI/Controls/UITurnSwitch.cs +++ b/SunnyUI/Controls/UITurnSwitch.cs @@ -49,6 +49,9 @@ namespace Sunny.UI ShowRect = false; } + [Browsable(false)] + public override string[] FormTranslatorProperties => ["ActiveText", "InActiveText"]; + [DefaultValue(false)] [Description("是否只读"), Category("SunnyUI")] public bool ReadOnly { get; set; } diff --git a/SunnyUI/Controls/UIUserControl.cs b/SunnyUI/Controls/UIUserControl.cs index d6a19467..d186617f 100644 --- a/SunnyUI/Controls/UIUserControl.cs +++ b/SunnyUI/Controls/UIUserControl.cs @@ -35,7 +35,7 @@ namespace Sunny.UI { [Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(System.ComponentModel.Design.IDesigner))] [DefaultEvent("Click"), DefaultProperty("Text")] - public partial class UIUserControl : UserControl, IStyleInterface, IZoomScale + public partial class UIUserControl : UserControl, IStyleInterface, IZoomScale, IFormTranslator { private int radius = 5; protected Color rectColor = UIStyles.Blue.PanelRectColor; @@ -54,6 +54,14 @@ namespace Sunny.UI SetStyleFlags(true, false); } + [Browsable(false)] + [Description("控件在界面显示时需要多语翻译的属性名称数组"), Category("SunnyUI")] + public virtual string[] FormTranslatorProperties { get; } + + [DefaultValue(false)] + [Description("控件是否显示多语内置资源"), Category("SunnyUI")] + public bool ShowBuiltInResources { get; set; } = false; + protected override void OnClick(EventArgs e) { base.OnClick(e); diff --git a/SunnyUI/Forms/UIBaseForm.cs b/SunnyUI/Forms/UIBaseForm.cs index 04310abf..e2a77dce 100644 --- a/SunnyUI/Forms/UIBaseForm.cs +++ b/SunnyUI/Forms/UIBaseForm.cs @@ -149,8 +149,6 @@ namespace Sunny.UI { SetInheritedStyle(UIStyles.Style); } - - Translate(); } public virtual void SetInheritedStyle(UIStyle style) diff --git a/SunnyUI/Style/UTranslate.cs b/SunnyUI/Style/UTranslate.cs index d39119fd..151f7668 100644 --- a/SunnyUI/Style/UTranslate.cs +++ b/SunnyUI/Style/UTranslate.cs @@ -90,7 +90,7 @@ namespace Sunny.UI string key = ctrl.Name + "." + propertyName; string langStr = ini.Read(section, key, ""); - string ctrlStr = pt.GetValue(ctrl, null).ToString(); + string ctrlStr = pt.GetValue(ctrl, null)?.ToString(); if (langStr.IsNullOrEmpty()) {