How to change Label contrl's height and width runtime
-
Hello, I would like label control with fixed width but length should increase as per the text data. OR run time how can I control label control's width and height depending on text of label control.
Thanks & Regards, Kumar
-
Hello, I would like label control with fixed width but length should increase as per the text data. OR run time how can I control label control's width and height depending on text of label control.
Thanks & Regards, Kumar
-
Hello Kumar, If you would like your label's width to increase depending on the text property of the control, simply set the AutoSize property to true. By default in VS 2008 this property will be set to true
Hi Corayzon, This I had tried, but it is increasing form width also. I want form width should be fixed like 300 and label's text should be wrap to next line.
Thanks & Regards, Kumar
-
Hi Corayzon, This I had tried, but it is increasing form width also. I want form width should be fixed like 300 and label's text should be wrap to next line.
Thanks & Regards, Kumar
Hi, I have solved using Graphics.measurestring wih 3rd parameter as fixed width.
Thanks & Regards, Kumar
-
Hi, I have solved using Graphics.measurestring wih 3rd parameter as fixed width.
Thanks & Regards, Kumar
Ya thanks Kumar, Measurestring really helped it. IF any one wants the code snippet : int iTop = 0; for (int icounter = 0; icounter < someCollectionObject.Count; icounter++) { Label lblctrl = new Label(); lblctrl.Name = "lbl" + icounter.ToString(); lblctrl.Image = "Put the image locaiton here " lblctrl.ImageAlign = ContentAlignment.TopLeft; string txtToShow = string.Empty; txtToShow = " " + someCollectionObject[icounter]; lblctrl.Text = txtToShow; lblctrl.Font = new System.Drawing.Font("Arial", 7f, System.Drawing.FontStyle.Bold); lblctrl.ForeColor = Color.LemonChiffon; lblctrl.Top = iTop; Graphics g = Graphics.FromHwnd(this.Handle); SizeF sz = g.MeasureString(txtToShow, lblctrl.Font, 100); lblctrl.Width = "You can have any constant width you wanted"; lblctrl.Height = (int)sz.Height -10; iTop += lblctrl.Height; }