473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

drawing label close to text box

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

Oct 17 '08 #1
3 3448
On Fri, 17 Oct 2008 14:10:39 -0700, Not-So-Lazy <os***@not.lazy.plwrote:
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?
No.
( not from UserControl because its imposible to align when anhors set to
Top and labels are not same width)
I don't entirely understand that comment. You can in fact create a
UserControl with a Label and a TextBox. As long as the Label control's
width is set large enough for your widest label, the controls should line
up fine. It's not necessarily convenient, but you can accomplish this
programmatically if need be. It's not literally "impossible".

Pete
Oct 17 '08 #2
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
Oct 17 '08 #3
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

Oct 18 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Toby Mathews | last post by:
Hi, In an ASP.Net application I want to convert open create a FileStream object from a System.Drawing.Image - is this possible? I create an instance of an Image object using the FromFile method,...
2
by: James Coburn's Grey Helmet Hair | last post by:
When I try to compile my GTK# app, the compiler says: jbailo@linux:~/mono> mcs buttons.cs -r gtk-sharp.dll -r glib-sharp.dll -r -o buttons.exe error CS2001: Source file 'buttons.exe' could not...
4
by: Stuart Norris | last post by:
Dear Readers, I am attempting to draw box around some text using unicode on multiline label. The label is forty characters wide and 12 lines deep. I have been trying to draw a box around text...
1
by: mhnazly | last post by:
i'm trying to read data from SQL Server database using data reader and assigned it to a label in my asp.net web application. but when the button is clicked, nothing appears. please help, thanks. ...
3
by: Paul | last post by:
Hi just wondering if there is an easy way to a box around a bunch of controls like ----------------------------------------------------- | control1 control2 control3 | | ...
2
by: John B | last post by:
I need to create a label with the last character drawn in red. My idea was to create a label and override OnPaint. So far so good. I then measure the character range for the last character. All...
1
by: Andrew | last post by:
Hello Everyone I am receiving an error in an application I am working on. The application when its done will be a Dungeons and Dragons Network game. I am having problems with the Networked...
1
by: cnixuser | last post by:
Hello, I am having a problem that I believe is related to the way a stream reader object looks for a text file by default. What I am doing is using a StreamReader object to read the text of a text...
18
by: navyjax2 | last post by:
What if your event handler has to be nonstatic?
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.