Windows Phone Checkbox Strikethrough/Change fontstyle - c#

I have a list of checkboxes which, when checked, the content (text) should then be strikethrough or even just to change the fontstyle (colour) of the checked item. I'm trying to do this in a checkbox_Tap event handler which is in my codebehind page.
Any ideas as to how I could change the fontstyle or how I could make it strikethough?

The Design Guidelines mention that you should always use the system font unless you have a specific "brand", although there isn't anything forcing you to follow this.
The CheckBox itself, though, has properties you can set in the code-behind for FontFamily, FontSize, FontStretch, FontStyle, Foreground, etc.
In your CheckBox_Tap event handler, you could do something like:
void CheckBox_Tap(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)sender;
cb.FontFamily = //<your new font here>
cb.FontStyle = // <new style here>
}
As for Strikethrough - it doesn't look like there is a built in way to do that (there isn't a specific property for Strikethrough that you can just set to True, for example).
However, I did run across this post, and there is an answer that shows a hacky way to do this in XAML (which I haven't tried) using a Border. I'm wondering if you could try this, and wrap your CheckBox in a Border which is invisible by default, and then make it visible when you want the Strikethrough?
Hope this helps!

Related

How do I create an invisible checkbox that remains clickable?

I'm creating an application in Forms for very non tech-savvy users. In doing so, I'm attempting to keep some more complicated buttons and menus hidden in the main program unless an invisible checkbox is checked- which only the QA/Dev team would need to use for troubleshooting.
I've attempted to use checkBox1.Hide() followed by checkBox1.Show on click as well as on CheckedChanged, however when the checkbox is hidden or has visibile set to false, the checkbox is unable to be checked. I've also looked at the checkbox's properties window in the Form design, but setting the bordercolor to white or the bordersize to 0 under FlatAppareance had no effect.
Any suggestions? Thanks for the help.
I agree with the comments this is not a good practice when designing a user interface, but there is a way to make an invisible button in winforms.
in your constructor or in a method set the properties of the button like so
button1.FlatStyle = FlatStyle.Flat;
button1.FlatAppearance.BorderColor = BackColor;
button1.FlatAppearance.MouseOverBackColor = BackColor;
button1.FlatAppearance.MouseDownBackColor = BackColor;
this will render a invisible to the user button that can be clicked. that is if your click event is already set up.

removing an object from a control box

I want to change the forecolor of radio buttons texts when the Group box Enabled property is set to false. The disabled color is so absurdly dark that you can't read the text in this state. I tried many things (like overriding the system default disabled color mode) without success.
I have no choice but to use this kind of controls, so I'm looking for a workaround. My idea was to superpose a lightly greyed label on the text, but this cause errors when initializing the control box.
I tried the following code to get the label out of the parent control box and avoid this problem:
RadioButtonLabel.Parent= Main_menu.Activeform;
I have no more errors, but the label now basically disappear in runtime.
Any solution?
instead of using dark color, try using this: (this is just an idea code)
if(groupbox.enable == false)
{
radiobutton.text = ""; //it means show nothing
}
else
{
radiobutton.text = "Whatever you like";
}

Refresh a control

I am trying to change a link label's fore color but the color won't graphically change.
I have a timer that updates the fore color of the control
private void Timer_Tick(object sender, EventArgs e)
{
MyLbl.ForeColor = shouldUpdate? Color.Blue: Color.Gray;
}
The update is successful and while debugging, I can see that the fore color property of myLbl is different. So why doesn't it change it graphically?
I also tried
MyLbl.ForeColor = Color.Gray;
And tried adding Application.DoEvents() after the change of the fore color.
Any solutions?
Unlike vanilla labels, link-labels don't use the ForeColor property in this manner to colour their text.
Use the LinkColor property instead.
Gets or sets the color used when displaying a normal link.
In your case, you need:
MyLbl.LinkColor = shouldUpdate? Color.Blue: Color.Gray;
Note that this not an update problem - you don't have to explicitly call Application.DoEvents (which is almost never the right thing to do) or Invalidate or Refresh to get the link-label to respond to the colour-change.

My RichTextBox change backgroundcolor when Enabled is set to false

How can I set the backgroundcolor and fontcolor to be "normal" on a disabled (i.e. Enabled = false) RichTextBox?
Thanks
Windows User Interface guidelines demand that a control that is disabled appears disabled. With the obvious benefit that the user can tell that it won't make sense to keep banging the mouse on the control, trying to set the focus to it. Like all controls in the toolbox, RichTextBox implements this guideline as well. Overriding its painting behavior is not practical. Consider the ReadOnly property.
I would create a new control that inherits from RichTextBox. You could the override the BackColor property to always return something like white for example. Something similar could be done with the font color. Off the top of my head I think you could do something such as:
class CustomRichTextBox : System.Windows.Forms.RichTextBox {
public override System.Drawing.Color BackColor {
get { return System.Drawing.Color.White; }
set { base.BackColor = System.Drawing.Color.White; }
}
}
Though that may not work because you would probably have to override the OnPaint method to get around default greyed out behavior.
Another option would be to simply use the readonly property instead. ReadOnly is almost the same as enabled = false, except that you can actually still click in the text box (you just can't edit it). When it is readonly, you still have control over the normal color properties without having to override anything.
If you wanted to be even more creative, you could add a delegate to the Enter event of the RichTextBox that set the focus to some other control to prevent the user from even clicking in the box (which enabled doesn't let you do)
Emulate the property of being disabled. Implement a property that when set to false the control won't get focus or all key strokes are ignored.
Pretty bizarre in my opinion but the programmer wants what the programmer wants! ;-]

Set a disabled TextBox's ForeColor to be the same as its BackColor in C#

How do I set a disabled TextBox's current text color to be the same as its current background color in C#?
Simply doing txtLala.ForeColor = txtLala.BackColor does not seems to work.
This works:
txtLala.Text = "Red";
txtLala.BackColor = System.Drawing.Color.Red;
txtLala.ForeColor = txtLala.BackColor;
txtLala.ReadOnly = true;
Try setting the color, before the readonly. And also check how you are setting the color!
EDIT
Try this
txtLala.Attributes.Add("style","background-color:Red;color:Red");
If you are trying to make it invisible, you know you can set it as
txtLala.Visible = False;
EDIT II
I finally tried
txtLala.Enabled = false;
... you see that grey shadow color! I don't think you can mess with that, it looks to be a browser property setting.
Why not set as ReadOnly or Visible = False?
Maybe you have a good reason for Enabled = false
But you should note:
Use the Enabled property to specify or determine whether a control is functional. When set to false, the control appears dimmed, preventing any input from being entered in the control.
Note The ability to enable or disable functionality is always available. However, dimming and locking the control only works in Microsoft Internet Explorer version 4 and later.
This property propagates down the control hierarchy. Therefore, disabling a container control will disable all child controls within that container.
Note Not all controls support this property. See the indivual controls for details.
It seems to only work for TextBox that is read only. If it is disabled (.Enabled = false). It does not seems to work.
If this is a readonly textbox, you need to explicitly set your BackColor first, then your statement will work.
txtLala.BackColor = System.Drawing.SystemColors.Info;
txtLala.ForeColor = txtLala.BackColor;
Ref: http://bytes.com/groups/net-c/233961-read-only-textbox
Then again, if it's readonly, a label might be better. If you're trying to hide it, perhaps setting .Visible = false would be better still.
Edit: This seems to be a common question on the web. With respect to winforms: This site suggests dropping the box into a frame and setting Enabled = false on the frame, not the textbox. Once you do that, you may be able to maintain control of the forecolor.

Categories