How would I give the appearnace of Enabled/Disabled to a Button cell type

Posted by: j2associates on 8 September 2017, 1:04 pm EST

  • Posted 8 September 2017, 1:04 pm EST

    Hello all,


    We have a spread that validates a series of files. One of the columns is a boolean that displays as a check box and is checked if the file for that row has errors. Column 0 is an empty column and contains a Button cell type. If the errors column is not checked, I would like to display the Fix button as disabled (eg text color is light gray instead of black, etc). How is the best way to do this? Do I do something with a renderer somewhere, trap the Paint event, use a NativeWindow class or something else entirely? Thanks in advance for any ideas and/or suggestions!

  • Replied 8 September 2017, 1:04 pm EST

    In what event are you doing your validation?  If the value of the checkbox is unchecked you should be able to change the color of the button text to the color of your choice and lock the cell.
  • Replied 8 September 2017, 1:04 pm EST

    Hello,


    Here is a custom ButtonCellType that will look at the Locked property of the Cell to see how to paint the text on the button.

     
    Public Class myButton
    Inherits FarPoint.Win.Spread.CellType.ButtonCellType

    Public Overrides Sub PaintCell(ByVal g As System.Drawing.Graphics, ByVal r As System.Drawing.Rectangle, ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal value As Object, ByVal isSelected As Boolean, ByVal isLocked As Boolean, ByVal zoomFactor As Single)
    Dim args As New FarPoint.Win.FpButtonPaintArgs
    args.g = g
    args.r = r
    args.rectTextIn = r
    args.backColor = appearance.BackColor
    args.foreColor = appearance.ForeColor
    args.font = appearance.Font
    args.halign = ToHorizontalAlignment(appearance.HorizontalAlignment)
    args.valign = ToVerticalAlignment(appearance.VerticalAlignment)
    args.focus = False
    args.text = Text
    args.textDown = TextDown
    args.nAlign = TextAlign
    args.textOrientation = TextOrientation
    args.wordWrap = WordWrap
    args.shadowSize = ShadowSize
    args.darkColor = DarkColor
    args.lightColor = LightColor
    args.pictUp = Picture
    args.pictDown = PictureDown
    args.bLocked = isLocked 'False

    args.prefix = HotkeyPrefix
    args.style = appearance.VisualStyles
    args.mouseOver = False
    args.backcolor2 = ButtonColor2
    args.backstyle = BackgroundStyle
    args.mode = GradientMode
    args.rightToLeft = appearance.RightToLeft
    args.txtRotationAngle = TextRotationAngle
    args.txtIndent = 0
    args.useVSBackColor = UseVisualStyleBackColor
    FarPoint.Win.FpButton.DoPaint(args)

    End Sub
     
  • Replied 8 September 2017, 1:04 pm EST

    Hello Scott,


    Excellent code as always! Thanks! This gets me pretty close. In the attached jpeg, note how the Windows button outline is also dimmed if it is disabled.If you can help me with a couple of questions, I think we are there:  

    1. How do I determine what cell is being accessed - I think I need GetCellFromPixel with the r coordinates but I am not sure how to apply it in this context
    2. Similarly, how to I determine what row is being accessed
    3. Once I have the above, then I can test the Errors column for the given row and make the following changes if an error is found
    a. TextColor = SystemColors.GrayText
    b. The displayed button should use SystemColors.InactiveBorder - not sure how do do this
     
    2008/03/DisbledButtons.JPG
  • Replied 8 September 2017, 1:04 pm EST

    Thanks, Scott! I also played around with the ControlPaint method and a regular Windows forms button and didn't have a lot of success there either. If the base class from which all of the CellType derive inherits Control, maybe you could just expose the Enabled property.
  • Replied 8 September 2017, 1:04 pm EST

    Hello,


    I can not get this to look exactly correct either. I reported this as a bug (#22138) since I believe you should only need to lock the cell and Spread should paint a disabled button.


    The border around the button is painted the color of the DarkColor and LightColor settings, but you would need to turn off the VisuelStyles (args.style = FarPoint.Win.VisualStyles.Off) for this to have affect.

  • Replied 8 September 2017, 1:04 pm EST

    Hello,


    Good idea. However they are not derived from the Control class.

  • Replied 8 September 2017, 1:04 pm EST

    When I use this custom control, Text property of Locked cell doesn't display Text:

               Dim buttonStatusCellType As myButton
                With buttonStatusCellType
                   .Text = "On/Off"
                End With
                .Columns(intGridColumn).CellType = buttonStatusCellType
                .Columns(intGridColumn).Visible = True
                .Columns(intGridColumn).Locked = False
                .Columns(intGridColumn).Width = 80

     

    If Locked property is False, text appears OK

     

  • Replied 8 September 2017, 1:04 pm EST

    Hello,

    With latest build of Spread for Windows Forms using the above code for custom control, the text for the locked cells is displayed. I have attached the image where the code and locked cells both are  displayed.If you are using an older version of Spread I would suggest you to test it with the latest build of Spread and let me know your observations.

     

    Thanks,

     


    2009/07/CustomCellTypeLocked.JPG
  • Replied 8 September 2017, 1:04 pm EST

    Hello Scott,


    I found this thread which is a pretty complete example of subclassing a ButtonCellType:


    How to change button size of ButtonCellType: http://www.clubfarpoint.com/Forums/forums/thread/10048.aspx


    I spent quite a bit of time playing around with the example code from that thread but I cannot figure out where the border around the button cell type is being painted. That is what needs to be set to SystemColors.InactiveBorder so that it appears disabled like a standard Windows form button. I am just about out of ideas of things to try. Anybody else have any suggestions?

  • Replied 8 September 2017, 1:04 pm EST

    Hello,

    I am not seeing the behavior as reported by you. When I set a column to be Button cell type and it's locked property to True, I can not click on it( it is un-ediatble) and the button's text also shows. However, when I set the Locked property to False i can click on the button cell and the text property also shows. Are you seeing different behavior? I have tested this issue with 4.0.2010.2005 version of Spread.

    Thanks

  • Replied 8 September 2017, 1:04 pm EST


    Hello:


    This custom ButtonCellType class worked great until we switched to version 5.0.3518.2008. Now code below does not render cells properly:


           'Populate column #5 with custom cell type
             With fpSpread1.ActiveSheet
               
                .ColumnHeader.Cells(0, 5).Text = "Custom Button"
                Dim customButton As New myButton
                customButton.Text = "Show"
                .Columns(5).CellType = customButton
             End With


    Please let me know if there is any workaround.


     


    Thank you

  • Replied 8 September 2017, 1:04 pm EST

    1. When I use built-in Button type, Text shows up in both cases  (.Locked = False/True) but appearance of the button doesn't allow to say whether button is enabled/disabled

    2. To workaround this issue, I tried to use custom CellType (derived from ButtonCellType) which was offered by Scott in this thread.

    When I applied this code at  4.0.2001.2005 Text on the Locked button disappears (Forecolor and BackColor are probably the same so you can't see the text).

    When I applied this code at  4.0.3510.2008 Text on the Locked button doesn't disappear but it's not any different from the text on not Locked button cell.

    Thank you

  • Replied 8 September 2017, 1:04 pm EST

    Hello,

    I see that the Button Cell is disabled when it is locked using the latest build of Spread and the Text is shown.The locked cell looks completely different from not locked cells while using a Button cell type. I have attached an image that shows the difference between the two.

    Please check if VisualStyles is turned off.

     

    Thanks, 


    2009/07/LockedButtonCellType.JPG
  • Replied 8 September 2017, 1:04 pm EST

    Thank you for response. You are correct: behavior is different for 4.0.2001.2005 and latest 4.0.3510.2008.

    The latest version doesn't produce expected result either: Text is shown but it's the same whether Locked property is true or not.  You can see it in your attachment as well.

     

    Thank you for your support

  • Replied 8 September 2017, 1:04 pm EST

    Hello,

    This issue has been defined as "As Intended". This is found to be an issue with the Paintcell method.

    This issue happens when in overriden PaintCell method don't save state of
    Graphics parameter g before paint cell and don't Restore state after
    paint cell. override PaintCell must rewrite:
    public override void
    PaintCell(System.Drawing.Graphics g, System.Drawing.Rectangle r,
    FarPoint.Win.Spread.Appearance appearance, object value, bool
    isSelected, bool isLocked, float zoomFactor)
    {
    GraphicsState state = g.Save();
    ////
    //do paint cell here
    //......
    g.Restore(state);
    }

     

    Thanks,

     

  • Replied 8 September 2017, 1:04 pm EST

    Hello,

    I have reported this as a bug to the QA team , bug id is #99923004. It should be fixed in our next maintenance release of Spread for Windows.

     

    Thanks,

     

Need extra support?

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

Learn More

Forum Channels