/// ------------------------------------------------------------------------------------ public void Show(Control ctrl, HistogramBar bar) { if (!Enabled) { return; } Debug.Assert(ctrl != null); Debug.Assert(bar != null); if (!ShouldShowPopup(ctrl)) { return; } _popupTimer.Start(); // The desired bottom of the popup is 60 pixels down from the top of the bar. // If that's below the bar's bottom, then set the bottom of the popup to 5 // pixels above the bar's bottom edge. int popupTop = (bar.Height > 65 ? 60 : bar.Height - 5) - Height; // The desired left edge for the popup is on the right side of the bar, // overlapping 25% of its right side. If that causes the popup to extend // beyond the right edge of the screen, then move the popup so its shown // on the left side of the bar, overlapping 25% of it's left side. int popupLeft = bar.Width - (bar.Width / 4); Point ptPopup = bar.PointToScreen(new Point(popupLeft, popupTop)); bool tooWide; bool tooTall; CheckDesiredPopupLocation(ptPopup, out tooWide, out tooTall); if (tooWide) { ptPopup = bar.PointToScreen(new Point((bar.Width / 4) - Width, popupTop)); } _showRelativeToScreen = true; _ctrl = ctrl; _popupLocation = ptPopup; }
/// ------------------------------------------------------------------------------------ public bool LoadPhones(IEnumerable <string> phoneList) { pnlScroller.AutoScrollPosition = new Point(0, 0); pnlBars.Left = 0; // Dispose of the labels and clear the control arrays. pnlPhones.Controls.Clear(); pnlBars.Controls.Clear(); int xLocationOffset = 0; _maxTotalCount = 0; _phoneHeight = 0; var fnt = FontHelper.MakeRegularFontDerivative(App.PhoneticFont, _phoneFontSize); foreach (var phone in phoneList) { // Create phone labels that appear under the bar. var lblPhone = new Label(); lblPhone.Font = fnt; lblPhone.Text = phone; lblPhone.Location = new Point(xLocationOffset, 2); lblPhone.AutoSize = false; lblPhone.Paint += lbl_Paint; lblPhone.MouseEnter += HandleMouseEnter; lblPhone.MouseDoubleClick += HandleMouseDoubleClick; pnlPhones.Controls.Add(lblPhone); if (_phoneHeight == 0) { _phoneHeight = TextRenderer.MeasureText(phone, lblPhone.Font).Height + _extraPhoneHeight; } lblPhone.Size = new Size(_phoneLabelWidth, _phoneHeight); lblPhone.BringToFront(); // Set the phone's magnified tooltip. // Uncomment if the magnified tooltip of a histogram's phone is desired. //m_phoneToolTip.SetToolTip(lblPhone, lblPhone.Text); // Create the bars. var histBar = new HistogramBar(phone); histBar.MouseEnter += HandleMouseEnter; histBar.MouseDoubleClick += HandleMouseDoubleClick; pnlBars.Controls.Add(histBar); // Link the phone's label with its bar and vice versa. lblPhone.Tag = histBar; histBar.Tag = lblPhone; // Determine the tallest bar if (histBar.BarValue > _maxTotalCount) { _maxTotalCount = histBar.BarValue; } xLocationOffset += _phoneLabelWidth; // pixels between the characters } pnlPhones.Width = (pnlPhones.Controls.Count * _phoneLabelWidth); // Account for the fact that each phone's Y location is 2. _phoneHeight += 2; // Make sure the labels have enough vertical space. This will increase // room for the labels when the scroll bar appears underneath them and // decrease room when the scroll bar disappears. In other words, this // calculation will make sure there's only enough vertical space for // the phone labels as is necessary so they won't get clipped. if (_phoneHeight != pnlScroller.ClientSize.Height) { pnlScroller.Height += (_phoneHeight - pnlScroller.ClientSize.Height); } // Add 5 additional pixels of space between the right-most bar and border pnlBars.Width = (pnlPhones.Controls.Count * _phoneLabelWidth) + 5; // Force the bars to be resized. pnlFixedBorder_Resize(null, null); return(true); }