removing an object from a control box - c#

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";
}

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.

xamarin forms - changing button text on all carousel content pages

What would be the "best" (or a better) way to do the following?
In a carousel page (say 6 content pages), I click a button, part of the action changes the text on that button, but it also has to change for all the other content pages.
I currently have this happening in the carousel pages OnCurrentPageChanged(), where I call a function and pass in "this". helpers.ChangeAll(this);
public void ChangeAll(CarouselSwipePage page)
{
foreach (SwipePageContent v in page.Children)
{
Button b = v.Content.FindByName<Button>("pause");
if (GlobalSettings.Settings.Default.CarouselCountEnabled) //this is set elsewhere and is used to determine whether the carousel is changing automatically, if it is then set the text to pause
{
b.Text = FontAwesomeFont.PauseCircleO;
}
else
{
b.Text = FontAwesomeFont.PlayCircleO;
}
}
}
This works ok on android but on ios when the user swipes to the next content page after clicking the button, the button text is momentarily the old value before changing to the new value, due to the function being called OnCurrentPageChanged().
Apart from that I'm sure there must be a better way to do this, it looks rubbish.
What about creating a style for the buttons, and just change the text value of the style?
So, using binding properties or dynamic resources, when you change the value, it is going to change all the buttons of your application that use this style. I think this approach is pretty much better and simpler than a loop.

Need to use a color dialog result in a separate Windows Form

Please go easy on me I am very new to coding and stuck on something that I'm sure is very simple.
Currently I have an Options form in which the user can select from the standard colordialog.showdialog() and the result is displayed as a sample on the form as a label
If(backColorDialog.Showdialog() == DialogResult.OK);
backColorLabel.BackColor = backColorDialog.Color; // set to label to show option selected
I need to take that selected color and apply it to the background color of a "game board" in another Windows form. I have already added a reference from the "game board" form to the options form.
The "Game Board" is laid over a TableLayoutPanel so I need to be able to change the BackColor of the panel
TableLayoutPanel1.BackColor = (colordialog result from options form)
Like I said I am new to this and appreciate any help you can provide
Create a property on your configuration form:
Color SelectedColor { get; private set; }
And assign users choice to it:
if (backColorDialog.Showdialog() == DialogResult.OK)
{
backColorLabel.BackColor = backColorDialog.Color;
SelectedColor = backColorDialog.Color;
}
(note there was a mistake in your code - the ; after if line)
After this, in your main form you can read it from your configuration form:
TableLayoutPanel1.BackColor = optionsForm.SelectedColor;
As noted by justin.chmura in the comments below, you can also consider a different approach using events. Your options form would raise an event when user selects a different color, and main form's event handler would apply this color instantly on the game panel. The difference is that it would update the color immediately. When it's not needed the above solution with a property is enough.

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