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

    <P>Hello all,</P>
    <P>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!</P>
  • 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.<br>
  • Replied 8 September 2017, 1:04 pm EST

    <P>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.</P> <PRE class=coloredcode><SPAN class=kwd>Public Class</SPAN> myButton
    <SPAN class=kwd>Inherits</SPAN> FarPoint.Win.Spread.CellType.ButtonCellType

    <SPAN class=kwd>Public Overrides Sub</SPAN> PaintCell(<SPAN class=kwd>ByVal</SPAN> g <SPAN class=kwd>As</SPAN> System.Drawing.Graphics, <SPAN class=kwd>ByVal</SPAN> r <SPAN class=kwd>As</SPAN> System.Drawing.Rectangle, <SPAN class=kwd>ByVal</SPAN> appearance <SPAN class=kwd>As</SPAN> FarPoint.Win.Spread.Appearance, <SPAN class=kwd>ByVal</SPAN> value <SPAN class=kwd>As Object</SPAN>, <SPAN class=kwd>ByVal</SPAN> isSelected <SPAN class=kwd>As Boolean</SPAN>, <SPAN class=kwd>ByVal</SPAN> isLocked <SPAN class=kwd>As Boolean</SPAN>, <SPAN class=kwd>ByVal</SPAN> zoomFactor <SPAN class=kwd>As Single</SPAN>)
    <SPAN class=kwd>Dim</SPAN> args <SPAN class=kwd>As New</SPAN> 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 = <SPAN class=kwd>False</SPAN>
    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 <SPAN class=cmt>'False
    args.prefix = HotkeyPrefix = appearance.VisualStyles
    args.mouseOver = <SPAN class=kwd>False</SPAN>
    args.backcolor2 = ButtonColor2
    args.backstyle = BackgroundStyle
    args.mode = GradientMode
    args.rightToLeft = appearance.RightToLeft
    args.txtRotationAngle = TextRotationAngle
    args.txtIndent = 0
    args.useVSBackColor = UseVisualStyleBackColor

    <SPAN class=kwd>End Sub</SPAN>
  • Replied 8 September 2017, 1:04 pm EST

    <P>Hello Scott,</P>
    <P>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:  </P><PRE class=coloredcode>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
  • 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

    <P>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. </P>
    <P>The border around the button is painted the color of the DarkColor and LightColor settings, but you would need to turn off the VisuelStyles (<FONT size=2> = FarPoint.Win.VisualStyles.Off) </FONT>for this to have affect.</P>
  • Replied 8 September 2017, 1:04 pm EST

    <P>Good idea. However they are not derived from the Control class. </P>
  • Replied 8 September 2017, 1:04 pm EST

    <p>When I use this custom control, Text property of Locked cell doesn't display Text:</p><p>           Dim buttonStatusCellType As myButton<br>            With buttonStatusCellType<br>               .Text = "On/Off"<br>            End With<br>            .Columns(intGridColumn).CellType = buttonStatusCellType<br>            .Columns(intGridColumn).Visible = True<br>            .Columns(intGridColumn).Locked = False<br>            .Columns(intGridColumn).Width = 80</p><p> </p><p>If Locked property is False, text appears OK <br></p><p> </p>
  • Replied 8 September 2017, 1:04 pm EST

    <p>Hello,</p><p>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. </p><p> </p><p>Thanks, <br></p><p> </p>
  • Replied 8 September 2017, 1:04 pm EST

    <P>Hello Scott,</P>
    <P>I found this thread which is a pretty complete example of subclassing a ButtonCellType:</P>
    <P>How to change button size of ButtonCellType: <FONT face=Arial size=2><A HREF="/Forums/forums/thread/10048.aspx"></A></FONT></P>
    <P><FONT face=Arial size=2><FONT face="Times New Roman" size=3>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?</FONT></P></FONT>
  • Replied 8 September 2017, 1:04 pm EST

    <p>Hello,</p><p>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.</p><p>Thanks<br></p>
  • Replied 8 September 2017, 1:04 pm EST

    <P>This custom ButtonCellType class worked great until we switched to version 5.0.3518.2008. Now code below does not render cells properly:</P>
    <P>       'Populate column #5 with custom cell type<BR>         With fpSpread1.ActiveSheet<BR>            <BR>            .ColumnHeader.Cells(0, 5).Text = "Custom Button"<BR>            Dim customButton As New myButton<BR>            customButton.Text = "Show"<BR>            .Columns(5).CellType = customButton<BR>         End With<BR></P>
    <P>Please let me know if there is any workaround.</P>
    <P> </P>
    <P>Thank you</P></BLOCKQUOTE>
  • Replied 8 September 2017, 1:04 pm EST

    <p>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</p><p>2. To workaround this issue, I tried to use custom CellType (derived from ButtonCellType) which was offered by Scott in this thread. </p><p>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).</p><p>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.</p><p>Thank you <br></p>
  • Replied 8 September 2017, 1:04 pm EST

    <p>Hello,</p><p>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.<br></p><p>Please check if VisualStyles is turned off.</p><p> </p><p>Thanks,  <br></p>
  • Replied 8 September 2017, 1:04 pm EST

    <p>Thank you for response. You are correct: behavior is different for 4.0.2001.2005 and latest 4.0.3510.2008.</p><p>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.</p><p> </p><p>Thank you for your support <br></p>
  • Replied 8 September 2017, 1:04 pm EST

    <p>Hello,</p><p>This issue has been defined as "As Intended". This is found to be an issue with the Paintcell method.</p><p>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:<br> 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)<br> {<br> GraphicsState state = g.Save(); <br> ////<br> //do paint cell here <br> //......<br> g.Restore(state); <br> } </p><p> </p><p>Thanks,</p><p> </p>
  • Replied 8 September 2017, 1:04 pm EST

    <p>Hello,</p><p>I have reported this as a bug to the QA team , bug id is <span class="dlgtitle">#99923004</span><span class="lockmsg">. It should be fixed in our next maintenance release of Spread for Windows.</span></p><p> </p><p>Thanks,</p><p> </p>
Need extra support?

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

Learn More

Forum Channels