|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MultiCtrls
{
public partial class LabeledTextBox : TextBox
{
public LabeledTextBox()
{
InitializeComponent();
}
protected Label _label = null; // our label
protected string _LabelText = ""; // caption of our label
protected int _offset = 5; // space between editbox and label
public int offset
{
get { return _offset; }
set
{
_offset = value;
setControlsPosition();
}
}
public string LabelText
{
get { return _LabelText; }
set
{
_LabelText = value;
setControlsPosition();
}
}
protected virtual void setControlsPosition()
{
if (_label != null)
{
_label.Text = _LabelText;
_label.AutoSize = true;
_label.Left = this.Left - _label.Width - _offset;
_label.Top = this.Top + 3;
}
}
protected override void OnParentChanged(EventArgs e)
{
if (this.Parent != null)
{
_label = new Label();
this.Parent.Controls.Add(_label);
setControlsPosition();
}
base.OnParentChanged(e);
}
protected override void OnLocationChanged(EventArgs e)
{
setControlsPosition();
base.OnLocationChanged(e);
}
protected override void Dispose(bool disposing)
{
if (_label != null)
_label.Dispose();
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I specialize at C#, developing Enterprise solutions. I have some knowledge of ASP.NET MVC - looking forward to use it together with Typescript.