Not-So-Lazy schrieb:
Hi
In delphi we have something like Labeled Edit which is basically text
box which draws label side by it. Is it possible in C# when inheriting
from textbox class?
The following code might have some problems but it should show you how it might
be done.
public partial class MyLabeledTextBox : TextBox
{
private Label _myLabel = null;
public MyLabeledTextBox() : base()
{
}
protected override void OnParentChanged(EventArgs e)
{
if (this.Parent != null)
{
_myLabel = new Label();
_myLabel.Text = this.Name; // something mor intelligent needed here
_myLabel.Left = this.Left - 150; // and here also ;)
_myLabel.Top = this.Top;
this.Parent.Controls.Add(_myLabel);
}
base.OnParentChanged(e);
}
protected override void OnLocationChanged(EventArgs e)
{
if (_myLabel != null)
{
_myLabel.Left = this.Left - 150;
_myLabel.Top = this.Top;
}
base.OnLocationChanged(e);
}
protected override void Dispose(bool disposing)
{
if (_myLabel != null)
_myLabel.Dispose();
base.Dispose(disposing);
}
}
--
Ralf Jansen
deepinvent Software GmbH - Viersen, Germany -
http://www.deepinvent.com
Central Email Archiving The Easy Way -
http://www.mailstore.com