winforms - c# changing window size automatically -
i student working on windows forms application. in application have form pop window shows label. want change window's size according label's size. example if label has 3 lines, should show of lines automatically. right shows 1 line. how can fix problem?
you need calculate size of text using font settings of label in pop-up form. here's example of pop-up form's load
event:
private void popup_load(object sender, eventargs e) { messagelabel.text = texttoshow; graphics gfx = this.creategraphics(); sizef textsize = gfx.measurestring(messagelabel.text, messagelabel.font); size borders = this.size - this.clientsize; this.size = new size((int)textsize.width, (int)textsize.height) + borders; }
this code presumes have property called texttoshow
pass message displayed form:
public string texttoshow { get; set; }
you can open pop-up form this:
popup popup = new popup(); popup.texttoshow = "test\nmult-line popup window\n\nline4\n\nline 6"; popup.showdialog(this);
the pop-up form scale label's size. try adjusting fonts, changing text, etc - should work correctly.
hope helps!
Comments
Post a Comment