Closed VolatilePulse closed 2 years ago
Sorry @VolatilePulse , I have tried your scenario and mine works as expected. Did you inherit MaterialTextBox2 in a new class? Do you have some extra code inside that class to check for textbox's value? Maybe there is a problem...
Demo: starting disabled, switched to enabled and everything works fine...
I can't reproduce that also. Could you make a test project and share it ?
This shows two issues, the inner control stays disabled while the outer control is enabled and the Hint text is overlapped by the Text value.
using MaterialSkin.Controls;
using System;
using System.Windows.Forms;
namespace WinFormsApp1
{
internal static class Program
{
[STAThread]
private static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new ExampleForm("Sample Text"));
}
}
public partial class ExampleForm : MaterialForm
{
public ExampleForm(string textBoxString)
{
InitializeComponent();
ExampleTextBox.Text = textBoxString;
}
public MaterialTextBox2 ExampleTextBox = new();
public MaterialSwitch ExampleSwitch = new();
private void InitializeComponent()
{
ClientSize = new System.Drawing.Size(800, 450);
Text = "Example Form";
ExampleTextBox.Hint = "Test";
ExampleTextBox.Text = string.Empty;
ExampleTextBox.Enabled = false;
ExampleTextBox.Location = new System.Drawing.Point(32, 100);
ExampleTextBox.Size = new System.Drawing.Size(200, 60);
ExampleSwitch.Text = "TextBox Enabled";
ExampleSwitch.Location = new System.Drawing.Point(264, 100);
ExampleSwitch.Size = new System.Drawing.Size(200, 20);
ExampleSwitch.Click += ExampleSwitch_Click;
Controls.Add(ExampleTextBox);
Controls.Add(ExampleSwitch);
}
private void ExampleSwitch_Click(object? sender, EventArgs e) => ExampleTextBox.Enabled = ExampleSwitch.Checked;
}
}
Hi @VolatilePulse , I've tried your code and works fine for me for Enabled issue. Yes, there is a problem with baseTextBox position when Hint is visible and not empty.
Edit: The problem is from initialization of control in your example, because the text is initially set as string.Empty
, and Hint
is not empty, and the Text
value is set after form initialization. But calling UpdateRects()
method on the overridden Text
property of MaterialTextBox2
, the location of baseTextBox
will be set correctly.
Demo:
Hi @VolatilePulse
Try my PR #292 and see if it solve your problem. See my Edit
from post above, too...
Demo:
Overlapping fix has been merged into master. Could you try again and tell us if everything is fixed ?
Part of the confusion was because I was using an older commit. I misunderstood the usage of git submodule
. After pulling the latest version, all issues have been resolved. Thank you.
One of the scenarios at work is using a switch to toggle between using a local DB or server DB. If switching to a server DB, the user is required to provide a connection string which set's the text box's enable state to true. The outer control can receive focus, but the inner text box is still disabled.
Starting Disabled State with a Text value:
Toggled Enabled State with a Text Value:
If the control starts enabled, everything works as expected at first. Once the Enabled state is toggled to false, you get the first image. Toggling the Enabled state to true again will get you the second image.