Adding custom control to sheet disappears

Posted by: sparticus1701 on 8 September 2017, 2:29 pm EST

  • Posted 8 September 2017, 2:29 pm EST

    I am creating a grid where some rows are 'linked' to each other in that they are considered as a set. I need a way to visually show they are linked, beyond changing the background color, as well as a way to break the link.

    I created the following control and I can use the AddControl() function to add a new instance onto the sheet. It appears to work, but it only shows if I click on it and it disappears when I click anywhere else on the sheet control. Otherwise it all works fine.

    Am I missing something to keep it from disappearing?


    	public class RowLinkView : Control, FarPoint.Win.Spread.DrawingSpace.IEmbeddedControlSupport
    {
    private Boolean bOverCloseGlyph = false;
    private Boolean ShowCloseGlyph
    {
    get
    {
    return (this.bOverCloseGlyph);
    }
    set
    {
    if (value != this.bOverCloseGlyph)
    {
    this.bOverCloseGlyph = value;
    this.Invalidate();
    }
    }
    }
    private Rectangle rectCloseGlyph = new Rectangle();

    public event EventHandler CloseClicked = null;

    public RowLinkView ()
    : base()
    {
    this.Name = "RowLinkView";

    this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
    //this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
    //this.BackColor = Color.Transparent;
    this.BackColor = SystemColors.Control;
    this.Size = new System.Drawing.Size(25, 100);

    Int32 iQuarter = Convert.ToInt32(this.Width * 0.28);
    this.rectCloseGlyph = new Rectangle(this.Width - iQuarter - 1, this.Height - iQuarter - 1, iQuarter, iQuarter);
    }

    protected override void OnPaint (PaintEventArgs e)
    {
    Graphics g = e.Graphics;
    g.FillRectangle(new SolidBrush(this.BackColor), this.ClientRectangle);

    g.DrawLine(SystemPens.ControlText, 0, 0, this.Width / 4, 0);
    g.DrawLine(SystemPens.ControlText, 0, this.Height - 1, this.Width / 4, this.Height - 1);
    g.DrawLine(SystemPens.ControlText, this.Width / 4, 0, this.Width / 4, this.Height - 1);
    g.DrawLine(SystemPens.ControlText, this.Width / 4, this.Height / 2, this.Width / 2, this.Height / 2);

    if (this.bOverCloseGlyph)
    {
    g.DrawRectangle(SystemPens.ControlText, this.rectCloseGlyph);
    g.DrawLine(SystemPens.ControlText, this.rectCloseGlyph.Left, this.rectCloseGlyph.Top, this.rectCloseGlyph.Right, this.rectCloseGlyph.Bottom);
    g.DrawLine(SystemPens.ControlText, this.rectCloseGlyph.Right, this.rectCloseGlyph.Top, this.rectCloseGlyph.Left, this.rectCloseGlyph.Bottom);
    }

    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
    System.Drawing.StringFormat fmt = new System.Drawing.StringFormat(StringFormatFlags.DirectionVertical);
    fmt.Alignment = StringAlignment.Center;
    g.DrawString(this.Text, this.Font, SystemBrushes.ControlText, this.Width / 2, this.Height / 2, fmt);
    }

    protected override void OnMouseDown (MouseEventArgs e)
    {
    base.OnMouseDown(e);

    if (e.Button != MouseButtons.Left)
    return;

    if (this.rectCloseGlyph.Contains(e.Location))
    {
    if (this.CloseClicked != null)
    this.Invoke(this.CloseClicked, this, EventArgs.Empty);
    }

    this.Invalidate();
    }

    protected override void OnMouseMove (MouseEventArgs e)
    {
    base.OnMouseMove(e);
    this.ShowCloseGlyph = this.ClientRectangle.Contains(e.Location);
    this.Invalidate();
    }

    protected override void OnMouseLeave (EventArgs e)
    {
    base.OnMouseLeave(e);
    this.ShowCloseGlyph = false;
    this.Invalidate();
    }

    #region IEmbeddedControlSupport Members
    FarPoint.Win.Spread.DrawingSpace.ChildActivationPolicy FarPoint.Win.Spread.DrawingSpace.IEmbeddedControlSupport.ActivationPolicy
    {
    get
    {
    return (FarPoint.Win.Spread.DrawingSpace.ChildActivationPolicy.Click);
    }
    set
    {
    }
    }

    FarPoint.Win.Spread.DrawingSpace.Moving FarPoint.Win.Spread.DrawingSpace.IEmbeddedControlSupport.CanMove
    {
    get
    {
    return (FarPoint.Win.Spread.DrawingSpace.Moving.None);
    }
    set
    {
    }
    }

    FarPoint.Win.Spread.DrawingSpace.Sizing FarPoint.Win.Spread.DrawingSpace.IEmbeddedControlSupport.CanSize
    {
    get
    {
    return (FarPoint.Win.Spread.DrawingSpace.Sizing.None);
    }
    set
    {
    }
    }

    void FarPoint.Win.Spread.DrawingSpace.IEmbeddedControlSupport.ControlPaint (Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, Object value, Boolean bSelected, Boolean bLocked, Single fZoomFactor)
    {
    }
    #endregion
    }
  • Replied 8 September 2017, 2:29 pm EST

    I figured it out.  Apparently that is what ControlPaint() is supposed to do.  I implemented it at first, but the Rectangle r is relative to the sheet and not itself, making the behavior different than the OnPaint function.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels