private void MeasureTextSize(TCGlassButton btn ) { string text = btn.Text; int theight = (int)btn.Font.GetHeight()+25; int twidth = this.Width -20; int len = text.Length; int stidx = 0; for (int i = 1; i <= len; i++) { int slen = i - stidx-1; string str = text.Substring(stidx , slen ); Size msize = TextRenderer.MeasureText(str , btn.Font ); int h = msize.Height; int w = msize.Width; int wid = btn.Location.X * 2 + w; if (wid < this.Width) { continue; } else { theight += h+ 10; stidx = i-1; } } btn.Width = twidth; btn.Height = theight; btn.Left =( Width - twidth)/2; }
private void MeasureTextSize(TCGlassButton btn) { string text = btn.Text; int theight = (int)btn.Font.GetHeight() + 25; int twidth = this.Width - 20; int len = text.Length; int stidx = 0; for (int i = 1; i <= len; i++) { int slen = i - stidx - 1; string str = text.Substring(stidx, slen); Size msize = TextRenderer.MeasureText(str, btn.Font); int h = msize.Height; int w = msize.Width; int wid = btn.Location.X * 2 + w; if (wid < this.Width) { continue; } else { theight += h + 10; stidx = i - 1; } } btn.Width = twidth; btn.Height = theight; btn.Left = (Width - twidth) / 2; }
protected void LoadMenu() { TCGlassButton menu1 = GetMenu("HIS"); TCGlassButton menu3 = GetMenu("CRM"); TCGlassButton menu4 = GetMenu("SCM"); TCGlassButton menu5 = GetMenu("eYar门户"); this.Controls.Clear(); Point p = new Point(); int xspace = 1; int yspace = 15; p.X = this.Location.X + xspace; p.Y = this.Location.Y + yspace; menu1.Location = p; MeasureTextSize(menu1); this.Controls.Add(menu1); p.Y = p.Y + menu1.Height + yspace; menu3.Location = p; MeasureTextSize(menu3); this.Controls.Add(menu3); p.Y = p.Y + menu3.Height + yspace; menu4.Location = p; MeasureTextSize(menu4); this.Controls.Add(menu4); p.Y = p.Y + menu4.Height + yspace; menu5.Location = p; MeasureTextSize(menu5); this.Controls.Add(menu5); }
protected TCGlassButton GetMenu(string menuname) { TCGlassButton menu = new TCGlassButton(); menu.Cursor = Cursors.Hand; menu.Text = menuname; menu.AutoSize = false; menu.Tag = menuname; menu.Click += new EventHandler(menu_Click); return menu; }
protected TCGlassButton GetMenu(string menuname) { TCGlassButton menu = new TCGlassButton(); menu.Cursor = Cursors.Hand; menu.Text = menuname; menu.AutoSize = false; menu.Tag = menuname; menu.Click += new EventHandler(menu_Click); return(menu); }