protected override void setPosition(System.Drawing.PointF position) { // to position the border, first get the amount we'll be moving float deltaX = position.X - Label.GetX(); float deltaY = position.Y - Label.GetY(); Label.SetX(position.X); Label.SetY(position.Y); // now adjust the border by only the difference if (UnderlineView != null) { UnderlineView.SetX(UnderlineView.GetX( ) + deltaX); UnderlineView.SetY(UnderlineView.GetY( ) + deltaY); } }
void UpdateUnderline() { if (UnderlineView != null) { // first get the Y starting point of the font, relative to the control. // (the control's top might start 5 pixels above the actual font, for example) float fontYStart = (Label.LayoutParameters.Height - Label.TextSize) / 2; // Update the Y position of the border here, because // if the HEIGHT of the label changed, our starting Y position must change // so we stay at the bottom of the label. float borderYOffset = (fontYStart + Label.TextSize); UnderlineView.SetY((int)Label.GetY( ) + (int)borderYOffset); // Same for X UnderlineView.LayoutParameters.Width = (int)((float)Label.LayoutParameters.Width * BORDER_WIDTH_SCALER); float borderXOffset = (Label.LayoutParameters.Width - UnderlineView.LayoutParameters.Width) / 2; UnderlineView.SetX((int)Label.GetX( ) + (int)borderXOffset); } }