}//Lookup /// <summary> /// Takes controls value from attached controller /// </summary> public void TakeValue() { if (Field == null) { return; } bool has = Field.HasValue; m_TakeValueLatch = true; try { if (m_InternalTextBox != null) { if (has) { if (string.IsNullOrEmpty(m_DisplayFormat)) { m_InternalTextBox.Text = Field.ValueAsDisplayString; } else { object val = Field.ValueAsObject; m_InternalTextBox.Text = (val != null) ? string.Format("{0:" + m_DisplayFormat + "}", val) : string.Empty; } } else { m_InternalTextBox.Text = string.Empty; } }//txt else if (m_ActualControlType == ControlType.Check) { string val = Field.ValueAsString.Trim().ToUpperInvariant(); ((CheckBoxElement)m_DataEntryElement).Checked = ((val == "TRUE") || (val == "YES") || (val == "OK")); } else if (m_ActualControlType == ControlType.Radio) { RadioGroupElement rgrp = (RadioGroupElement)m_DataEntryElement; rgrp.CheckButtonWithKey(Field.ValueAsString); } else if (m_DataEntryElement is TextLabelElement) { ((TextLabelElement)m_DataEntryElement).Text = Field.ValueAsDisplayString; } } finally { m_TakeValueLatch = false; } }
/// <summary> /// Commits controls value into attached controller /// </summary> public void CommitValue() { if (m_TakeValueLatch) { return; } if (m_InternalTextBox != null) { if (m_FieldBinding.Field != null) { if (m_FieldBinding.Field is StringField) { m_FieldBinding.SetValueFromGUI(m_InternalTextBox.Text); } else { string val = m_InternalTextBox.Text.Trim(); if (val.Length == 0) { ClearValue(); } else { m_FieldBinding.SetValueFromGUI(val); } } } }//txt else if (m_ActualControlType == ControlType.Check) { m_FieldBinding.SetValueFromGUI(((CheckBoxElement)m_DataEntryElement).Checked); } else if (m_ActualControlType == ControlType.Radio) { RadioGroupElement rgrp = (RadioGroupElement)m_DataEntryElement; object val = string.Empty; if (rgrp.CheckedElement != null) { if (rgrp.CheckedElement.Key != null) { val = rgrp.CheckedElement.Key; } } m_FieldBinding.SetValueFromGUI(val); } }
//------------------------------------------------------------------------------------------------ #region Layout Elements /// <summary> /// Perfoms layout of all elements a control(host) consists of /// </summary> protected virtual void LayoutElements() { Themes.IPartRenderer renderer = BaseApplication.Theme.PartRenderer; int fh = FontHeight; bool symbol = Required || IsReadonly; Rectangle captionRegion = new Rectangle(); Rectangle dataEntryRegion = new Rectangle(); switch (m_CaptionPlacement) { case CaptionPlacement.Left: { captionRegion = new Rectangle( Padding.Left, (Height / 2) - (fh / 2), m_CaptionHIndent - m_ElementHSpacing, fh ); dataEntryRegion = new Rectangle( Padding.Left + m_CaptionHIndent, Padding.Top, Width - m_CaptionHIndent - Padding.Horizontal, GetDataEntryElementHeight()); break; } case CaptionPlacement.Right: { captionRegion = new Rectangle( Width - Padding.Right - m_CaptionHIndent + m_ElementHSpacing, (Height / 2) - (fh / 2), m_CaptionHIndent - m_ElementHSpacing, fh ); dataEntryRegion = new Rectangle( Padding.Left, Padding.Top, Width - m_CaptionHIndent - Padding.Horizontal, GetDataEntryElementHeight()); break; } case CaptionPlacement.Bottom: { captionRegion = new Rectangle( Padding.Left, Height - Padding.Bottom - fh, Width - Padding.Horizontal, fh ); dataEntryRegion = new Rectangle( Padding.Left, Padding.Top, Width - Padding.Horizontal, GetDataEntryElementHeight()); break; } default: /* and Top*/ { captionRegion = new Rectangle( Padding.Left, Padding.Top, Width - Padding.Horizontal, fh ); dataEntryRegion = new Rectangle( Padding.Left, Padding.Top + fh + m_ElementVSpacing, Width - Padding.Horizontal, GetDataEntryElementHeight()); break; } } //place caption and symbol if (symbol) { int symW = 6; int symH = 6; int symX; int symY = (captionRegion.Top + captionRegion.Height / 2) - (symH / 2); if (m_CaptionAlignment == StringAlignment.Far) { symX = captionRegion.Right - symW; captionRegion.Width -= symW + m_ElementHSpacing; } else { symX = captionRegion.Left; if (m_CaptionAlignment != StringAlignment.Center) { int delta = symW + m_ElementVSpacing; captionRegion.X += delta; captionRegion.Width -= delta; } } m_SymbolElement.Region = new Rectangle(symX, symY, symW, symH); m_SymbolElement.Visible = true; } else { m_SymbolElement.Visible = false; } m_CaptionElement.Region = captionRegion; m_CaptionElement.Alignment = m_CaptionAlignment; if (m_DataEntryElement != null) { if (m_DataEntryElement is CheckBoxElement) { //adjust region for checkbox Point midPoint = new Point( dataEntryRegion.Left + dataEntryRegion.Width / 2, dataEntryRegion.Top + dataEntryRegion.Height / 2); Padding cbm = renderer.CheckBoxMetrics; dataEntryRegion = new Rectangle(midPoint.X - fh / 2 - cbm.Left, midPoint.Y - fh / 2 - cbm.Top, fh + cbm.Right, fh + cbm.Bottom); } if (m_DataEntryElement is RadioGroupElement) { RadioGroupElement rgrp = (RadioGroupElement)m_DataEntryElement; rgrp.BeginUpdate(); rgrp.ButtonVSpacing = m_ElementVSpacing; rgrp.Padding = new Padding(m_ElementHSpacing, m_ElementVSpacing, m_ElementHSpacing, m_ElementVSpacing); rgrp.Region = dataEntryRegion; rgrp.EndUpdate(); if (rgrp.UpdateCount > 0) { rgrp.EndUpdate(); //rebuilds RadioGroup } } else { m_DataEntryElement.Region = dataEntryRegion; } } if (m_InternalTextBox != null) { if (Utils.IsControlDesignerHosted(this)) { m_InternalTextBox.SetBounds(-1000, -1000, 1, 1); //adornment painter fix } else { Padding tbm = renderer.FocusedTextBoxMetrics; Rectangle itbRect = new Rectangle(dataEntryRegion.Left + tbm.Left, dataEntryRegion.Top + tbm.Top, dataEntryRegion.Width - tbm.Horizontal, dataEntryRegion.Height - tbm.Vertical); if (m_DataEntryElement is ComboBoxElement && m_ComboButtonVisible) { itbRect.Width = ((int)renderer.ComboTextBoxWidthPercent * dataEntryRegion.Width) - tbm.Horizontal; int btnLeft = ((ComboBoxElement)m_DataEntryElement).ButtonRegion.Left - 1; if ((itbRect.Left + itbRect.Width) > btnLeft) { itbRect.Width = btnLeft - itbRect.Left; } } m_InternalTextBox.SetBounds( itbRect.Left, itbRect.Top, itbRect.Width, itbRect.Height); } if (m_LineCount > 1) { m_InternalTextBox.ScrollBars = ScrollBars.Vertical; m_InternalTextBox.WordWrap = true; } else { m_InternalTextBox.ScrollBars = ScrollBars.None; m_InternalTextBox.WordWrap = false; } m_InternalTextBox.BackColor = renderer.TextBoxBackgroundColor; } //m_InternalTextBox!=null } //LayoutElements()
private void createDataEntryElement() { switch (m_ActualControlType) { case ControlType.Check: { CheckBoxElement chk = new CheckBoxElement(this); chk.CheckedChanged += delegate(object sender, EventArgs e) { CommitValue(); }; m_DataEntryElement = chk; break; } case ControlType.Combo: { makeTextBox(); ComboBoxElement cmb = new ComboBoxElement(this, m_InternalTextBox); cmb.ButtonClick += delegate(object sender, EventArgs e) { Lookup(); }; cmb.Button.Visible = m_ComboButtonVisible; m_DataEntryElement = cmb; break; } case ControlType.Radio: { RadioGroupElement rgrp = new RadioGroupElement(this); rgrp.CheckedChanged += delegate(object sender, EventArgs e) { CommitValue(); }; if (Field != null) { if (Field.LookupType == LookupType.Dictionary) { rgrp.BeginUpdate(); foreach (string key in Field.LookupDictionary.Keys) { rgrp.AddItem(key, Field.LookupDictionary[key]); } rgrp.EndUpdate(); } } //commented 2011.02.25 //if (rgrp.UpdateCount==0) // rgrp.BeginUpdate(); m_DataEntryElement = rgrp; break; } case ControlType.Text: { makeTextBox(); m_DataEntryElement = new TextBoxElement(this, m_InternalTextBox); break; } default: { m_DataEntryElement = new TextLabelElement(this); break; } }//switch m_DataEntryElement.FieldControlContext = this; }