drawing label close to text box

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Not-So-Lazy

    #1

    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

  • Peter Duniho

    #2
    Re: drawing label close to text box

    On Fri, 17 Oct 2008 14:10:39 -0700, Not-So-Lazy <osoba@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
    programmaticall y if need be. It's not literally "impossible ".

    Pete

    Comment

    • Ralf Jansen

      #3
      Re: drawing label close to text box

      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 MyLabeledTextBo x : TextBox
      {
      private Label _myLabel = null;

      public MyLabeledTextBo x() : 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.Con trols.Add(_myLa bel);
      }
      base.OnParentCh anged(e);
      }

      protected override void OnLocationChang ed(EventArgs e)
      {
      if (_myLabel != null)
      {
      _myLabel.Left = this.Left - 150;
      _myLabel.Top = this.Top;
      }
      base.OnLocation Changed(e);
      }

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


      --
      Ralf Jansen

      deepinvent Software GmbH - Viersen, Germany - http://www.deepinvent.com
      Central Email Archiving The Easy Way - http://www.mailstore.com


      Comment

      • Not-So-Lazy

        #4
        Re: drawing label close to text box

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

        components.Disp ose();
        }
        base.Dispose(di sposing);
        }

        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

        Comment

        Working...