I have a GUI with a flat style for the buttons. I would like to use TextBox controls with the same appearance, but I can't find where can I configure the outer line with. Is there any control in WinForms which can be given FlatStyle? Thanks!
Edit 1
Thanks for the information about FixedSingle border style, but then, how can I change the line properties?
Edit 2
I've implemented a solution with a little bit of both. I would like if you could help improving this class, as I'm not an expert in C# and I find this code somewhat messy. Here is the code:
class BorderTextBox : UserControl
{
private TextBox m_textBox;
private int m_borderSize;
private void ResizeComponent()
{
m_textBox.Size = new Size(Size.Width - 2 * m_borderSize, m_textBox.Size.Height);
Size = new Size(Size.Width, m_textBox.Size.Height + 2 * m_borderSize);
}
protected override void OnResize(EventArgs z_event)
{
base.OnResize(z_event);
ResizeComponent();
}
public BorderTextBox()
{
SuspendLayout();
// TextBox
m_textBox = new TextBox();
m_textBox.BorderStyle = BorderStyle.None;
m_textBox.Name = "textBox";
m_textBox.TabIndex = 0;
// Body
BackColor = Color.Black;
Name = "Body";
Controls.Add(m_textBox);
ResumeLayout(false);
PerformLayout();
}
public bool UsePasswordStyle
{
get { return m_textBox.UseSystemPasswordChar; }
set { m_textBox.UseSystemPasswordChar = value; }
}
public int BorderSize
{
get { return m_borderSize; }
set
{
m_borderSize = value;
m_textBox.Location = new Point(m_borderSize, m_borderSize);
ResizeComponent();
}
}
}
Edit 3
I'm having some problems in implementing the ReadOnly property. I was trying to prevent the edit box to process the OnClick event and show the intermitent cursor inside. When I define the OnClick method inside this class:
class BorderTextBox : UserControl
{
...
protected override void OnClick(EventArgs e)
{
if (!ReadOnly)
base.OnClick(e);
}
...
}
This method only gets the clicks on the border, but not inside the textBox. Is there a way to catch that events? or how can you remove the event handlers of an element inside your component?
m_textBox.Click -= //the EventHandler we don't want