* UITextBox:增加ShowScrollBar属性,单独控制垂直滚动条

This commit is contained in:
Sunny 2021-04-18 22:27:40 +08:00
parent 70cdd7ce18
commit e8e590b891
6 changed files with 102 additions and 73 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -19,6 +19,7 @@
* 2020-01-01: V2.2.0 * 2020-01-01: V2.2.0
* 2020-06-03: V2.2.5 * 2020-06-03: V2.2.5
* 2020-09-03: V2.2.7 FocusedSelectAll属性 * 2020-09-03: V2.2.7 FocusedSelectAll属性
* 2021-04-18: V3.0.3 ShowScrollBar属性
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -42,7 +43,7 @@ namespace Sunny.UI
InitializeComponent(); InitializeComponent();
SetStyleFlags(); SetStyleFlags();
CalcEditHeight(); CalcEditHeight();
Height = MiniHeight; Height = MinHeight;
ShowText = false; ShowText = false;
Font = UIFontColor.Font; Font = UIFontColor.Font;
@ -72,7 +73,7 @@ namespace Sunny.UI
bar.ValueChanged += Bar_ValueChanged; bar.ValueChanged += Bar_ValueChanged;
edit.MouseWheel += OnMouseWheel; edit.MouseWheel += OnMouseWheel;
bar.MouseEnter += Bar_MouseEnter; bar.MouseEnter += Bar_MouseEnter;
base.TextAlignment = ContentAlignment.MiddleLeft; TextAlignment = ContentAlignment.MiddleLeft;
SizeChange(); SizeChange();
@ -203,14 +204,42 @@ namespace Sunny.UI
{ {
multiline = value; multiline = value;
edit.Multiline = value; edit.Multiline = value;
// edit.ScrollBars = value ? ScrollBars.Vertical : ScrollBars.None;
// bar.Visible = multiline;
edit.ScrollBars = value ? ScrollBars.Vertical : ScrollBars.None; if (value && Type != UIEditType.String)
bar.Visible = multiline; {
Type = UIEditType.String;
}
SizeChange(); SizeChange();
} }
} }
private bool showScrollBar;
[DefaultValue(false)]
[Description("显示垂直滚动条"), Category("SunnyUI")]
public bool ShowScrollBar
{
get => showScrollBar;
set
{
value = value && Multiline;
showScrollBar = value;
if (value)
{
edit.ScrollBars = ScrollBars.Vertical;
bar.Visible = true;
}
else
{
edit.ScrollBars = ScrollBars.None;
bar.Visible = false;
}
}
}
[DefaultValue(true)] [DefaultValue(true)]
public bool WordWarp public bool WordWarp
{ {
@ -320,14 +349,16 @@ namespace Sunny.UI
} }
} }
private int MiniHeight; private int MinHeight;
private int MaxHeight;
private void CalcEditHeight() private void CalcEditHeight()
{ {
UIEdit edt = new UIEdit(); TextBox edt = new TextBox();
edt.Font = edit.Font; edt.Font = edit.Font;
edt.Invalidate(); MinHeight = edt.PreferredHeight;
MiniHeight = edt.Height; edt.BorderStyle = BorderStyle.None;
MaxHeight = edt.PreferredHeight * 2 + MinHeight - edt.PreferredHeight;
edt.Dispose(); edt.Dispose();
} }
@ -335,10 +366,8 @@ namespace Sunny.UI
{ {
if (!multiline) if (!multiline)
{ {
if (Height < MiniHeight) if (Height < MinHeight) Height = MinHeight;
{ if (Height > MaxHeight) Height = MaxHeight;
Height = MiniHeight;
}
edit.Top = (Height - edit.Height) / 2; edit.Top = (Height - edit.Height) / 2;
edit.Left = 4; edit.Left = 4;
@ -615,7 +644,7 @@ namespace Sunny.UI
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
string currentItemText = values[i].ToString(); string currentItemText = values[i].ToString();
if (!currentItemText.Equals("ListItems")) if (currentItemText != null && !currentItemText.Equals("ListItems"))
{ {
list.Add(values[i]); list.Add(values[i]);
} }

View File

@ -1,84 +1,84 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net5.0-windows;netcoreapp3.1;net40</TargetFrameworks> <TargetFrameworks>net5.0-windows;netcoreapp3.1;net40</TargetFrameworks>
<ProjectGuid>{AB1CB247-E20B-4CBE-B269-570ADDD96C53}</ProjectGuid> <ProjectGuid>{AB1CB247-E20B-4CBE-B269-570ADDD96C53}</ProjectGuid>
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<RootNamespace>Sunny.UI</RootNamespace> <RootNamespace>Sunny.UI</RootNamespace>
<Description>SunnyUI.Net 是基于.Net Framework 4.0+、.Net Core3.1、.Net 5 框架的 C# WinForm 开源控件库、工具类库、扩展类库、多页面开发框架。</Description> <Description>SunnyUI.Net 是基于.Net Framework 4.0+、.Net Core3.1、.Net 5 框架的 C# WinForm 开源控件库、工具类库、扩展类库、多页面开发框架。</Description>
<Copyright>CopyRight © SunnyUI.Net 2012-2021</Copyright> <Copyright>CopyRight © SunnyUI.Net 2012-2021</Copyright>
<PackageLicenseFile>LICENSE</PackageLicenseFile> <PackageLicenseFile>LICENSE</PackageLicenseFile>
<Version>3.0.3</Version> <Version>3.0.3</Version>
<Authors>ShenYonghua</Authors> <Authors>ShenYonghua</Authors>
<Company>SunnyUI.Net</Company> <Company>SunnyUI.Net</Company>
<PackageId>SunnyUI</PackageId> <PackageId>SunnyUI</PackageId>
<PackageProjectUrl>https://gitee.com/yhuse/SunnyUI</PackageProjectUrl> <PackageProjectUrl>https://gitee.com/yhuse/SunnyUI</PackageProjectUrl>
<RepositoryUrl>https://gitee.com/yhuse/SunnyUI</RepositoryUrl> <RepositoryUrl>https://gitee.com/yhuse/SunnyUI</RepositoryUrl>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageIcon>SunnyUI.png</PackageIcon> <PackageIcon>SunnyUI.png</PackageIcon>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>..\Bin\</OutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile></DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>..\Bin\</OutputPath> <OutputPath>..\Bin\</OutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile></DocumentationFile> <DocumentationFile></DocumentationFile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net5.0-windows|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<Optimize>false</Optimize> <OutputPath>..\Bin\</OutputPath>
</PropertyGroup> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile></DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net5.0-windows|AnyCPU'">
<Optimize>false</Optimize>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<None Remove="Font\ElegantIcons.ttf" /> <None Remove="Font\ElegantIcons.ttf" />
<None Remove="Font\FontAwesome.ttf" /> <None Remove="Font\FontAwesome.ttf" />
<None Remove="Font\LigatureSymbols.ttf" /> <None Remove="Font\LigatureSymbols.ttf" />
<None Include="..\LICENSE"> <None Include="..\LICENSE">
<Pack>True</Pack> <Pack>True</Pack>
<PackagePath></PackagePath> <PackagePath></PackagePath>
</None> </None>
<None Include="..\SunnyUI.png"> <None Include="..\SunnyUI.png">
<Pack>True</Pack> <Pack>True</Pack>
<PackagePath></PackagePath> <PackagePath></PackagePath>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Font\ElegantIcons.ttf" /> <EmbeddedResource Include="Font\ElegantIcons.ttf" />
<EmbeddedResource Include="Font\FontAwesome.ttf" /> <EmbeddedResource Include="Font\FontAwesome.ttf" />
<EmbeddedResource Include="Font\LigatureSymbols.ttf" /> <EmbeddedResource Include="Font\LigatureSymbols.ttf" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="SunnyUI.Common" Version="3.0.3" /> <PackageReference Include="SunnyUI.Common" Version="3.0.3" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net40'"> <ItemGroup Condition="'$(TargetFramework)' == 'net40'">
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Web.Extensions" /> <Reference Include="System.Web.Extensions" />
<Reference Include="System.Design" /> <Reference Include="System.Design" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Update="Properties\Resources.Designer.cs"> <Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx"> <EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
</Project> </Project>