/// <summary> /// Chooses the most appropriate label based upon the space given /// by the interface generator. /// </summary> /// <param name="width">the width allowed for the tab label</param> public int ChooseLabel(int width) { try { GetControl().Text = _labels.GetLabelByPixelLength(GetControl().Parent.Font, width); } catch (Exception) { GetControl().Text = _labels.GetShortestLabel(); } return((int)Globals.MeasureString(GetControl().Text, GetControl().Parent.Font).Width); }
private void p_Resize(object sender, EventArgs e) { if (_listLabel != null) { _listLabel.Text = _listLabels.GetLabelByPixelLength(_listLabel.Font, GetControl().Width) + ":"; System.Drawing.SizeF size = Globals.MeasureString(_listLabel.Text, _listLabel.Font); _listLabel.Size = new System.Drawing.Size(GetControl().Width, (int)size.Height); _listView.Location = new System.Drawing.Point(0, _listLabel.Height + 3); _listView.Size = new System.Drawing.Size(GetControl().Width, GetControl().Height - _listView.Location.Y); } else { _listView.Size = new System.Drawing.Size(GetControl().Width, GetControl().Height); } }
public void SetLabelText() { string label = null; Control c = this.GetControl(); try { label = _labels.GetLabelByPixelLength(c.Font, c.ClientSize.Width) + ":"; } catch (Exception) { label = _labels.GetShortestLabel() + ":"; } c.Text = label; }
/* * Member Methods */ protected void refreshDisplay() { ApplianceState state = (ApplianceState)GetApplObj(); string lbl; if (!state.Defined) { lbl = ""; } else if (state.Type.ValueLabels == null) { lbl = state.Value.ToString(); } else { // find the right label library LabelDictionary labels = (LabelDictionary)state.Type.ValueLabels[state.Value]; if (labels == null) { lbl = state.Value.ToString(); } else { try { lbl = labels.GetLabelByPixelLength(GetControl().Font, GetControl().ClientSize.Width); } catch (Exception) { lbl = labels.GetShortestLabel(); } } } GetControl().Text = lbl; }
/* * Member Methods */ protected void typeChangeRefresh() { ApplianceState state = (ApplianceState)GetApplObj(); ComboBox cbox = (ComboBox)GetControl(); try { Hashtable labels = state.Type.ValueLabels; /* * This code may cause unneccesary flicker when displaying the * ComboBox. If it does, changes should be made here to add and * remove items based upon change in the state and its dependencies. */ object stateval = state.Value; if (state.Type.ValueSpace is PUC.Types.EnumeratedSpace) { PUC.Types.EnumeratedSpace espc = (PUC.Types.EnumeratedSpace)state.Type.ValueSpace; //cbox.BeginUpdate(); cbox.Items.Clear(); _itemIndexMap.Clear(); _indexItemMap.Clear(); for (int i = 1; i <= espc.GetItemCount(); i++) { object labelSpace = i; LabelDictionary ldict = (LabelDictionary)labels[labelSpace]; if (ldict.Enabled || (state.Defined && i == (int)stateval)) { string label = ldict.GetLabelByPixelLength(cbox.Font, cbox.ClientSize.Width); cbox.Items.Add(label); _itemIndexMap[cbox.Items.Count - 1] = i; _indexItemMap[i] = cbox.Items.Count - 1; if (state.Defined && i == (int)stateval) { cbox.SelectedIndex = cbox.Items.Count - 1; } } } if (!state.Defined) { object labelSpace = LabelDictionary.UndefinedToken; LabelDictionary ldict = (LabelDictionary)labels[labelSpace]; if (ldict != null) { string label = ldict.GetLabelByPixelLength(cbox.Font, cbox.ClientSize.Width); cbox.Items.Add(label); cbox.SelectedIndex = cbox.Items.Count - 1; } } //cbox.EndUpdate(); } else if (state.Type.ValueSpace is PUC.Types.BooleanSpace) { // cbox.BeginUpdate(); cbox.Items.Clear(); _itemIndexMap.Clear(); _indexItemMap.Clear(); for (int i = 0; i < 2; i++) { object labelSpace = (i == 1); LabelDictionary ldict = (LabelDictionary)labels[labelSpace]; if (ldict.Enabled) { string label = ldict.GetLabelByPixelLength(cbox.Font, cbox.Size.Width - MINIMUM_LEFT_PAD - MINIMUM_RIGHT_PAD); cbox.Items.Add(label); _itemIndexMap[cbox.Items.Count - 1] = (i == 1); _indexItemMap[(i == 1)] = cbox.Items.Count - 1; if (state.Defined && (i == 1) == (bool)stateval) { cbox.SelectedIndex = cbox.Items.Count - 1; } } } // TODO: think of a better way to do this // Currently undefined labels won't work if (!state.Defined) { object labelSpace = LabelDictionary.UndefinedToken; LabelDictionary ldict = (LabelDictionary)labels[labelSpace]; if (ldict != null) { string label = ldict.GetLabelByPixelLength(cbox.Font, cbox.ClientSize.Width); cbox.Items.Add(label); cbox.SelectedIndex = cbox.Items.Count - 1; } } // cbox.EndUpdate(); } else { Globals.GetFrame(GetApplObj().Appliance) .AddLogLine("SelectionListLinkedCIO does not know how to handle non-boolean/enumerated spaces"); } } catch (Exception) { cbox.Items.Add("--"); } }