private void TryApplyVars(IElement ele, string varName, string varValue) { if (ele is TextElement) { TextElement txt = ele as TextElement; if (txt.Text.Contains(varName)) { txt.Text = txt.Text.Replace(varName, varValue); } } else if (ele is MultlineTextElement) { MultlineTextElement txt = ele as MultlineTextElement; if (txt.Text.Contains(varName)) { txt.Text = txt.Text.Replace(varName, varValue); } } else if (ele is IElementGroup) { foreach (IElement subEle in (ele as IElementGroup).Elements) { TryApplyVars(subEle, varName, varValue); } } }
private void GetTextFromMultilineTextBox(TextBox box) { string text = box.Text; if (_currentHost == null) { return; } MultlineTextElement ele = box.Tag as MultlineTextElement; if (ele == null) { return; } if (String.IsNullOrEmpty(text)) { _currentHost.Container.Controls.Remove(box); _txtEle.Visible = true; _currentHost.Render(); return; } _currentHost.Container.Controls.Remove(box); ele.Text = text; ele.Visible = true; //ele.ApplySize(box.Width - _txtEle.Size.Width * _scale, 0); _currentHost.Render(); box.Tag = null; box.Clear(); box.Visible = false; box = null; }
private void CreatMultlineTextbox(ILayoutHost host, MultlineTextElement multlineTextElement) { multlineTextElement.Visible = false; TextBox txtBox = new TextBox(); txtBox.Tag = multlineTextElement; txtBox.Multiline = true; txtBox.Capture = true; txtBox.Font = new Font(multlineTextElement.Font.FontFamily, multlineTextElement.Font.Size * _scale); //_txtEle.Font; txtBox.Text = multlineTextElement.Text; txtBox.BorderStyle = BorderStyle.FixedSingle; txtBox.ForeColor = multlineTextElement.Color; float x = multlineTextElement.Location.X; float y = multlineTextElement.Location.Y; host.LayoutRuntime.Layout2Screen(ref x, ref y); txtBox.Location = new Point((int)x + LayoutControl.RULER_HEIGHT + 4, (int)y + LayoutControl.RULER_HEIGHT + 2); txtBox.Width = (int)(multlineTextElement.Size.Width * _scale); txtBox.Height = (int)(multlineTextElement.Size.Height * _scale); _currentHost.Container.Controls.Add(txtBox); txtBox.BringToFront(); txtBox.Focus(); //必须在其它的属性设置完成之后设置焦点才有作用 //txtBox.KeyDown += new KeyEventHandler(txtBox_KeyDown); txtBox.TextChanged += new EventHandler(txtBox_TextChanged); //设置文本框的宽随文本的宽度改变 txtBox.LostFocus += new EventHandler(txtBox_LostFocus); _originWid = txtBox.Width; }
void txtBox_TextChanged(object sender, EventArgs e) { TextBox box = sender as TextBox; MultlineTextElement ele = box.Tag as MultlineTextElement; if (ele == null) { return; } //System.Drawing.Graphics grp = System.Drawing.Graphics.FromHwnd(box.Handle); //int width = (int)ele.Size.Width;//(int)grp.MeasureString(box.Text, box.Font).Width; //grp.Dispose(); //if (width > _originWid) // box.Width = width; }