This is a migrated thread and some comments may be shown as answers.

Label to the top of textbox?

4 Answers 510 Views
DataLayout
This is a migrated thread and some comments may be shown as answers.
Megan
Top achievements
Rank 1
Megan asked on 26 Jul 2019, 06:03 PM
Hi! I've found the TextPlacement property of DataLayoutControlItem, but the control is kept to the right of the label. Is it possible to place the control under the label with their lefts aligned?

4 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 29 Jul 2019, 06:05 AM
Hello Megan,

You need to set the TextPosition property as well, for example you can use the ItemInitializing event for this: 
private void RadDataLayout1_ItemInitializing(object sender, DataLayoutItemInitializingEventArgs e)
{
    e.Item.TextPosition = LayoutItemTextPosition.Top;
    e.Item.TextAlignment = ContentAlignment.MiddleCenter;
 
}

I hope this helps. Should you have any other questions, do not hesitate to ask.

Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Megan
Top achievements
Rank 1
answered on 29 Jul 2019, 01:36 PM

Thank you for the response. When I try this, the text isn't drawn properly above the control.

Complete example:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TestInterfaceDisplayName
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void RadDataLayout1_ItemInitializing(object sender, Telerik.WinControls.UI.DataLayoutItemInitializingEventArgs e)
        {
            e.Item.TextAlignment = ContentAlignment.MiddleCenter;
            e.Item.TextPosition = Telerik.WinControls.UI.LayoutItemTextPosition.Top;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            radDataLayout1.DataSource = new TestEntity();
        }

        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.radDataLayout1 = new Telerik.WinControls.UI.RadDataLayout();
            ((System.ComponentModel.ISupportInitialize)(this.radDataLayout1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.radDataLayout1.LayoutControl)).BeginInit();
            this.radDataLayout1.SuspendLayout();
            this.SuspendLayout();
            // 
            // radDataLayout1
            // 
            // 
            // radDataLayout1.LayoutControl
            // 
            this.radDataLayout1.LayoutControl.Dock = System.Windows.Forms.DockStyle.Fill;
            this.radDataLayout1.LayoutControl.DrawBorder = false;
            this.radDataLayout1.LayoutControl.Location = new System.Drawing.Point(0, 0);
            this.radDataLayout1.LayoutControl.Name = "LayoutControl";
            this.radDataLayout1.LayoutControl.Size = new System.Drawing.Size(678, 384);
            this.radDataLayout1.LayoutControl.TabIndex = 0;
            this.radDataLayout1.Location = new System.Drawing.Point(26, 22);
            this.radDataLayout1.Name = "radDataLayout1";
            this.radDataLayout1.Size = new System.Drawing.Size(680, 386);
            this.radDataLayout1.TabIndex = 0;
            this.radDataLayout1.ItemInitializing += new Telerik.WinControls.UI.DataLayoutItemInitializingEventHandler(this.RadDataLayout1_ItemInitializing);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(800, 450);
            this.Controls.Add(this.radDataLayout1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.radDataLayout1.LayoutControl)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.radDataLayout1)).EndInit();
            this.radDataLayout1.ResumeLayout(false);
            this.ResumeLayout(false);

        }

        #endregion

        private Telerik.WinControls.UI.RadDataLayout radDataLayout1;
    }

    public class TestEntity // : TestA, TestB
    {
        [DisplayName("TestA")]
        public string Name { get; set; } = "stuff";
        [DisplayName("TestA B")]
        public string NameA { get; set; } = "stuff";
        [DisplayName("TestA C")]
        public string NameB { get; set; } = "stuff";
    }
}

0
Megan
Top achievements
Rank 1
answered on 29 Jul 2019, 04:27 PM
I'm sorry, the RadDataLayout in the example above doesn't subscribe to the ItemInitializing event. The screenshot shows what happens with it subscribed, though. Just a goof when creating the sample.
0
Dimitar
Telerik team
answered on 30 Jul 2019, 07:57 AM
Hello Megan,

Thanks for the code, I was able to reproduce the issue. I can see that you have logged this on our public Feedback Portal. To workaround it you can set the following properties as well: 
private void RadDataLayout1_ItemInitializing1(object sender, DataLayoutItemInitializingEventArgs e)
{
    e.Item.ControlVerticalAlignment = RadVerticalAlignment.Bottom;
    e.Item.TextPosition = Telerik.WinControls.UI.LayoutItemTextPosition.Top;
    e.Item.TextAlignment = ContentAlignment.TopCenter;
    e.Item.MaxSize = new Size(0, 40); // so the last item does not fill the remaining space
}

Please let me know if there is something else I can help you with. 

Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
DataLayout
Asked by
Megan
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Megan
Top achievements
Rank 1
Share this question
or