开发者

Dynamic resizing of DataGrid according to other control

I have 2 controls: dataGridView and Label. I load some files into datagrid and I show names of files in Label. Now i am dynamically changing maximum width of Label according to size of window but what can I do if I want to work with maximum height. I mean开发者_如何学C is there anyway how can I resize datagrid below Label if Label overfloating datagrid (some feature that say that these 2 controls can´t "overfloating" - i am sorry, I don´t know better english word for this). Or is there a way how can I add 3 dots at end of label and rest of content in label is show when I get mouse over it?

Dynamic resizing of DataGrid according to other control

Thank you


For the text shortening, use:

Label myLabel = new Label();
myLabel.Location = new System.Drawing.Point(10, 10);
myLabel.Size = new System.Drawing.Size(100, 15);
myLabel.AutoEllipsis = true;
myLabel.Text = "Some Text That Will Be Ellipsed";

Full length article can be found here.


Unless you want the size of your grid to be fixed for data display purposes, a flowing layout is probably the way to go.

However, you could modify your binding code so that if your label text is longer than some decided amount of characters you can store the full text in the Tooltip and do a .Remove on everything beyond that character count. Probably want to append an ellipsis on the label text also. Something like:

int maxLength = 1000; if (bindableText.Length > maxLength) { label.Tooltip = bindableText; label.Text = bindableText.Remove(maxLength) + "..."; }


Use a TableLayoutPanel to create dynamic flowing layouts. You can 'dock' the label to one cell of the layout, and let it grow automatically when the label grows. The DataGrid will automatically be resized and repositioned.


Or you can measure the pixel of your title and dynamically modify it :

System.Drawing.Graphics myG = Graphics.FromImage(new Bitmap(1, 1));
int numberPixel = myG.MeasureString(myTitle, myFontTitle);

if (numberPixel > XXX)
{
   myTitle = myTitle.Substring(0,YYY) + "...";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜