drawing label close to text box

N

Not-So-Lazy

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?
( not from UserControl because its imposible to align when anhors set to Top
and labels are not same width)

TIA

Adrian
 
R

Ralf Jansen

Not-So-Lazy said:
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);
}
}
 
N

Not-So-Lazy

protected override void Dispose(bool disposing)
{
if (_myLabel != null)
_myLabel.Dispose();
base.Dispose(disposing);
}
}

all works excellent except that i put disposing code into designer.cs file
protected override void Dispose(bool disposing)
{
if (_myLabel != null)
_myLabel.Dispose();
if (disposing && (components != null))
{

components.Dispose();
}
base.Dispose(disposing);
}

And now label is beign destroyed nicely... Thank You very much


PS any idea how to enforce VC# Express to rebuild code of my dll ? now i
just delete reference and place it one more time, but this is not very handy
especially when you making changes every minute. i added control project to
my test form solution and i do rebuild and it says rebuild all succeded, but
when i open properties of my control it doesnt show properties taht i just
added.... strange

Adrian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top