Background Click Event

Posted by: superjason on 8 September 2017, 12:31 pm EST

  • Posted 8 September 2017, 12:31 pm EST

    Is there an event that's fired when the user clicks on the background (the area behind the grid, but still within the control)?
  • Replied 8 September 2017, 12:31 pm EST


    The only event that will fire is the MouseDown event.

    This event fires anytime you do a mousedown over the control, but you
    could use the coordinates of e, the width and height of the control and
    the SystemInformation.VerticalScrollBarWidth and
    SystemInformation.HorizontalScrollBarHeight to determine if you clicked
    in the area in the bottom right of the control(background area).
  • Replied 8 September 2017, 12:31 pm EST

           Like this: <pre class="coloredcode"> <span class="kwd">Dim</span> sprwidth <span class="kwd">As Integer</span> = FpSpread1.Width
    <span class="kwd">Dim</span> sprheight <span class="kwd">As Integer</span> = FpSpread1.Height</pre> 
  • Replied 8 September 2017, 12:31 pm EST


    I reread your post and I think you may be refering to just the rows and columns portion of the control, not the entire control. If you want the height and width of those, you would have to loop through the rows and columns and get the height and width of each and increment a variable during each loop.

    For example: <pre class="coloredcode"> Dim w As Integer
    For i As Integer = 0 To FpSpread1.Sheets(0).ColumnCount - 1
    w += FpSpread1.Sheets(0).Columns(i).Width

    Dim h As Integer
    For x As Integer = 0 To FpSpread1.Sheets(0).RowCount - 1
    h += FpSpread1.Sheets(0).Rows(x).Height
  • Replied 8 September 2017, 12:31 pm EST

    Jason -

    In case you were wanting just the width and height of the actual grid and not the container you could use code similiar to this...

    Dim r, c, w, h As Integer

    For r = 0 To FpSpread1.ActiveSheet.RowCount - 1
    h += FpSpread1.ActiveSheet.Rows(i).Height


    h += FpSpread1.ActiveSheet.ColumnHeader.Rows(0).Height

    For c = 0 To FpSpread1.ActiveSheet.ColumnCount - 1
    w += FpSpread1.ActiveSheet.Columns(i).Width


    w += FpSpread1.ActiveSheet.RowHeader.Columns(0).Width

    If you don't want to include the headers in your calculation then remove that code.
  • Replied 8 September 2017, 12:31 pm EST

    Thanks.  I was about to ask you what the heck you were thinking.  I'll give this new method a try.
  • Replied 8 September 2017, 12:31 pm EST

    Here is the code I used if anyone else is interested:

     <pre class="coloredcode"> <span class="kwd">private</span> Rectangle getGridDimensions()
    <span class="kwd">double</span> height;
    <span class="kwd">double</span> width;

    height = _sheet.ColumnHeader.Rows[0].Height;
    <span class="kwd">foreach</span>(Row currRow <span class="kwd">in</span> _sheet.Rows)
    height += currRow.Height;

    width = _sheet.RowHeader.Columns[0].Width;
    <span class="kwd">foreach</span> (Column currCol <span class="kwd">in</span> _sheet.Columns)
    width += currCol.Width;

    <span class="kwd">return new</span> Rectangle(0, 0, (<span class="kwd">int</span>)Math.Round(width), (<span class="kwd">int</span>)Math.Round(height));
  • Replied 8 September 2017, 12:31 pm EST

    How do I know the height and width of the actual grid (and not the background)?
Need extra support?

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

Learn More

Forum Channels