Add more common Control properties, add TextBox component
This commit is contained in:
Родитель
53feff4a5b
Коммит
eac0c6ff9b
|
@ -13,9 +13,13 @@ namespace BlinForms.Framework.Controls
|
|||
[Parameter] public int Width { get; set; }
|
||||
[Parameter] public int Height { get; set; }
|
||||
|
||||
[Parameter] public int TabIndex { get; set; }
|
||||
|
||||
[Parameter] public bool Visible { get; set; }
|
||||
[Parameter] public Color BackColor { get; set; }
|
||||
|
||||
[Parameter] public AnchorStyles Anchor { get; set; }
|
||||
|
||||
protected override void BuildRenderTree(RenderTreeBuilder builder)
|
||||
{
|
||||
builder.OpenElement(0, GetType().FullName);
|
||||
|
@ -26,6 +30,8 @@ namespace BlinForms.Framework.Controls
|
|||
builder.AddAttribute(103, nameof(Height), Height);
|
||||
builder.AddAttribute(104, nameof(Visible), Visible);
|
||||
builder.AddAttribute(105, nameof(BackColor), BackColor.ToArgb());
|
||||
builder.AddAttribute(106, nameof(TabIndex), TabIndex);
|
||||
builder.AddAttribute(107, nameof(Anchor), (int)Anchor);
|
||||
RenderContents(builder);
|
||||
builder.CloseElement();
|
||||
}
|
||||
|
@ -63,7 +69,16 @@ namespace BlinForms.Framework.Controls
|
|||
control.Visible = (bool)attributeValue;
|
||||
break;
|
||||
case nameof(BackColor):
|
||||
control.BackColor = Color.FromArgb(argb: int.Parse((string)attributeValue));
|
||||
if ((attributeValue as string) != "0")
|
||||
control.BackColor = Color.FromArgb(argb: int.Parse((string)attributeValue));
|
||||
break;
|
||||
case nameof(TabIndex):
|
||||
if ((attributeValue as string) != "0")
|
||||
control.TabIndex = int.Parse((string)attributeValue);
|
||||
break;
|
||||
case nameof(Anchor):
|
||||
if ((attributeValue as string) != "0")
|
||||
control.Anchor = (AnchorStyles)int.Parse((string)attributeValue);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException($"FormsComponentBase doesn't recognize attribute '{attributeName}'");
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.RenderTree;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace BlinForms.Framework.Controls
|
||||
{
|
||||
public class TextBox : FormsComponentBase
|
||||
{
|
||||
static TextBox()
|
||||
{
|
||||
BlontrolAdapter.KnownElements.Add(typeof(TextBox).FullName, renderer => new BlazorTextBox(renderer));
|
||||
}
|
||||
|
||||
[Parameter] public string Text { get; set; }
|
||||
[Parameter] public bool Multiline { get; set; }
|
||||
[Parameter] public bool ReadOnly { get; set; }
|
||||
[Parameter] public bool WordWrap { get; set; }
|
||||
[Parameter] public ScrollBars ScrollBars { get; set; }
|
||||
|
||||
protected override void RenderAttributes(RenderTreeBuilder builder)
|
||||
{
|
||||
builder.AddAttribute(1, nameof(Text), Text);
|
||||
builder.AddAttribute(2, nameof(Multiline), Multiline);
|
||||
builder.AddAttribute(3, nameof(ReadOnly), ReadOnly);
|
||||
builder.AddAttribute(4, nameof(WordWrap), WordWrap);
|
||||
builder.AddAttribute(5, nameof(ScrollBars), (int)ScrollBars);
|
||||
}
|
||||
|
||||
class BlazorTextBox : System.Windows.Forms.TextBox, IBlazorNativeControl
|
||||
{
|
||||
public BlazorTextBox(BlinFormsRenderer renderer)
|
||||
{
|
||||
}
|
||||
|
||||
public void ApplyAttribute(ulong attributeEventHandlerId, string attributeName, object attributeValue, string attributeEventUpdatesAttributeName)
|
||||
{
|
||||
switch (attributeName)
|
||||
{
|
||||
case nameof(Text):
|
||||
Text = (string)attributeValue;
|
||||
break;
|
||||
case nameof(Multiline):
|
||||
Multiline = (bool)attributeValue;
|
||||
break;
|
||||
case nameof(ReadOnly):
|
||||
ReadOnly = (bool)attributeValue;
|
||||
break;
|
||||
case nameof(WordWrap):
|
||||
WordWrap = (bool)attributeValue;
|
||||
break;
|
||||
case nameof(ScrollBars):
|
||||
if ((attributeValue as string) != "0")
|
||||
ScrollBars = (ScrollBars)int.Parse((string)attributeValue);
|
||||
break;
|
||||
default:
|
||||
FormsComponentBase.ApplyAttribute(this, attributeEventHandlerId, attributeName, attributeValue, attributeEventUpdatesAttributeName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
@using BlinForms.Framework.Controls
|
||||
@using System.Drawing
|
||||
|
||||
<Panel Visible="true" BackColor="Color.Red" Top="300" Left="300" Width="300" Height="100">
|
||||
<Panel Visible="true" BackColor="Color.Red" Top="200" Left="300" Width="300" Height="200" Anchor="@(System.Windows.Forms.AnchorStyles.Right | System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)">
|
||||
<Label Top="50" Left="10" Width="150" Height="23" BackColor="Color.Yellow" Text="This label is nested"></Label>
|
||||
|
||||
<TextBox Top="75" Left="20" Height="100" Width="150" Text="Heeeeeeey" Multiline="true" ScrollBars="System.Windows.Forms.ScrollBars.Vertical"></TextBox>
|
||||
</Panel>
|
||||
|
||||
|
||||
|
@ -13,15 +15,15 @@
|
|||
<Label Top="100" Width="200" Height="23" BackColor="Color.AliceBlue" Text="@("I'm a label: " + labelCount)"></Label>
|
||||
|
||||
|
||||
<Button Top="200" Width="400" Height="23" BackColor="Color.Orange" Text="@($"Show details... (visible={isDetailsVisible})")" OnClick="@ToggleDetailsVisible" />
|
||||
<Button Top="200" Width="250" Height="23" BackColor="Color.Orange" Text="@($"Show details... (visible={isDetailsVisible})")" OnClick="@ToggleDetailsVisible" />
|
||||
|
||||
@if (isDetailsVisible)
|
||||
{
|
||||
<Label Top="250" Width="200" Height="23" BackColor="Color.Cyan" Text="Details visible.."></Label>
|
||||
<Label Top="250" Width="200" Height="23" Text="Details visible.."></Label>
|
||||
}
|
||||
else
|
||||
{
|
||||
<Label Top="300" Width="200" Height="23" BackColor="Color.Magenta" Text="Details NOT visible..."></Label>
|
||||
<Label Top="300" Width="200" Height="23" Text="Details NOT visible..."></Label>
|
||||
}
|
||||
|
||||
@code {
|
||||
|
|
Загрузка…
Ссылка в новой задаче