PC Review


Reply
Thread Tools Rate Thread

drawing label close to text box

 
 
Not-So-Lazy
Guest
Posts: n/a
 
      17th Oct 2008
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

 
Reply With Quote
 
 
 
 
Ralf Jansen
Guest
Posts: n/a
 
      17th Oct 2008
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


 
Reply With Quote
 
Not-So-Lazy
Guest
Posts: n/a
 
      18th Oct 2008

> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i insert a text on a drawing, still seeing the drawing ? =?Utf-8?B?Y20yMDA1NzA=?= Microsoft Word Document Management 2 31st Jul 2006 01:03 AM
System.Drawing For Drawing Text Images jjbutera@hotmail.com Microsoft ASP .NET 1 9th Jan 2006 09:55 PM
How do I add a clip art drawing to a address label? =?Utf-8?B?TXIuIFF1ZXN0aW9uIE1hcms=?= Microsoft Access 1 6th Oct 2005 06:35 AM
Label and Button text not drawing Don Dusich via .NET 247 Microsoft Dot NET Framework Forms 1 31st Mar 2005 01:54 AM
[Q] drawing box around text in a label Stuart Norris Microsoft C# .NET 4 30th Jun 2004 04:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:15 PM.