I need black forecolor in a disabled combobox. Is it possible?
I have searched around for information in the past about this, and as far as I can tell, the best solution is to change the DrawMode of the combo box to OwnerDrawFixed or OwnerDrawVariable and then write your own drawing code in the DrawItem event of the combo box.
I found this article that goes into much more detail about it. Hope it helps.
A "hack" I've used in the past for textboxes is to leave the control enabled, but capture the "OnFocus" event and immediately set the focus to some other object on the form, preferably a label since it doesn't show as being selected. I think this should work for comboboxes, too.
Not sure if your app is Winforms or WPF. The code given below works in a WPF app.
combo1.Items.Add("Item 1");
combo1.Items.Add("Item 2");
combo1.SelectedIndex = 0;
combo1.Foreground = Brushes.Black;
In my XAML I added a combo box and set its IsEnabled property to "false" then in the code behind I used the code given above and it does work.
HTH
All you need to do is say
combobox1.ForeColor = Color.FromName("Black");
It doesn't matter if the control is disabled or not, it should change the foreground color.
comboBox1.BackColor=Color.Black;
Related
I have a simple form containing a main view and also some text boxes and an "add" button that I use for adding data that is displayed in the main view (and stored in a text file). What I want to do is to add a little button that will toggle hiding/showing of the adding controls. Such button usually is a small square containing two arrowheads pointing up/down depending on the state. How do I do that?
(I'm sorry for the terrible title, but I don't know the proper name for this. Could anyone tell me?)
I don't think there's something built-in in WinForms for that. When I needed to do something similar, I just changed the Height of the form...
this.ClientSize = new System.Drawing.Size(required_width, required_height);
use a bool for hiding/showing
You can use the forms Height property and the controls could be hidden with Control.Visible = false
I think the word you're looking for is "Collapsible panel".
A quick google/codeproject search will provide you with some links:
http://www.codeproject.com/KB/miscctrl/TgXPPanel.aspx
http://www.codeproject.com/KB/miscctrl/XPCollapsGroupBox.aspx
http://www.codeproject.com/KB/miscctrl/CollapsibleGroupBox.aspx
I suggest you use a SplitContainer control and play with the Panel2.Collapsed property by sitting it to true or false
put the control that you want to hide/show inside panel2 and put the button in panel1. Change the Orientation property to Vertical, and there you go
Hey I was just wondering the techniques everyone uses to style radio buttons in winForms. I find them very plain, and would like to add some color or different images for the controls. The only way I can think of is to actually use a button that looks like a radiobutton, and set it to true or false.
Just wondering if there is a way I can do this, but still use the radio control.
Here is the RadioButton MSDN.
Here you can see that you can, like many Controls :
change the Button Apparence.
change the Button Color.
change the Button BackGroundImage.
There are many options to create your CustomRadioButton.
Here are two links which you can use to customize your controls
http://www.devexpress.com
http://www.dotnetskin.net
I'm suspecting the answer is no, but I just want confirmation before I move on - is there any easy way (as in, not re-templating) to hide things like the box that gets checked on a CheckBox, the drop-down arrow of a combo box, etc. without hiding the actual content being displayed?
Try this! Example is for a radio button:
radioButton.Visibility = Visibility.Hidden;
You can play some around with the Background or BorderBrush, but the answer is as you excepted: No..
You will need to restyle the control, but don't let the whole styling and templating scare you though.. Its actually quite easy once you get the hang of it ;)
Notice that you can have a checkbox like button using "ToggleButton", so you could use more or less use the same template as for your normal buttons (if you need them for toggling states).
The answer is YES, as you can actually template all controls a lot, without the need of creading custom controls. Just set the template in a style and add the style to the control.
oh i just reread your question
.. the answer is NO, but have a look at the toggle button maybe its what you are looking for.
the simplest way to display the content of ComboBox, CheckBox, etc. is to display a TextBlock in readonly mode.
You can easily make an UserControl with a DependencyProperty and show/hide your content.
You can disable the control/s in which case they cannot be interacted with but the text is still displayed.
I have a list box with Checkboxes in it. I want to prevent the Checkbox from changing its status if the user clicks on the text next to it. I only want it to change if the small box is clicked directly.
Is there any way to do this in windows forms?
Greetings and thanks in advance.
Place the text next to it in a Label, instead of the Text property of the Checkbox. Or you could create your own control which has a Checkbox and a Label. The Text property of the control would then fill the Text in the Label, and you could expose all of the Checkboxes regular properties in your control.
That's fairly non-standard behavior. Users are going to expect to be able to change the checkbox when clicking on its label, and are going to be frustrated, confused, and surprised when it doesn't work. I'd recommend not doing this. I'm not the only one.
(Yes, it's about web design, but many of the concepts are applicable in desktop application design as well.)
You could always not fill in the Text property of the Checkbox and make a completely separate Label control.
Otherwise, you will probably have to do explicit hit testing within the control to see if they hit the box or text. And then you will have to worry about checking the margins, which side the box is on, and other things that can change the position of the box.
I personally was only able to freeze things.
I freeze the check boxes by handling the Click and ItemChecked events,
and change the check state back, when it gets modified.
I use a menu to check/uncheck items and let user decide to use the menu or classic behave.
Cheers, good luck.
I would like to set the focus on a TextBox in my custom document content in WPF. I set all those focusable parameters to true. Still, the focus is not on the TextBox. Any thought or comment ?
So far, I've added these:
textbox.Focus();
textbox.SelectAll();
to the constructor of my WPF page.
The TextBox is in a Canvas inside a DockPanel, and all of them are part of a custom:DocumentContent.
thank you in advance,
Take a look at this blog post and the MSDN Focus Overview article. From your question it sounds like you're trying to set focus in the constructor. The UI Elements have not been created at that point. You should set focus during the Loaded event of your control.
That should work. Check if textbox.Focus() is returning true, it will tell you if call did work. Also, try calling textbox.Focus() from Loaded event of Window/Page.