I have a multiple checkboxes on a Winforms without having the Text Property of all checkboxes,
so the problem is that when i hover a mouse on the checkbox it highlighted but when i go to the checkbox using tab key it never get highlighted..
If anyone have the similar issue and already solved it Please help..
The problem is that when a check box gets focus it highlights only the text portion of the control which is empty in your case. You have a few choices:
1) For all your "blank" text boxes, set the text property to a space. This will create a small highlighted portion when you tab to the control.
2) Program the OnEnter and OnLeave events of the checkbox, and draw/paint a square around the whole control.
3) If you want the default MouseEnter behaviour which creates a yellowish highlight on the check box itself, create your own check box control as follows:
public class MyCB : CheckBox
{
protected override void OnEnter(EventArgs e)
{
base.OnEnter(e);
base.OnMouseEnter(e);
}
protected override void OnLeave(EventArgs e)
{
base.OnLeave(e);
base.OnMouseLeave(e);
}
}
I added an event handler for the CheckBox.Paint event and added the following:
private void checkBox1_Paint(object sender, PaintEventArgs e)
{
CheckBox checkBox = sender as CheckBox;
if (checkBox.Focused)
{
// e.ClipRectangle is affected by checkBox.Padding. Be careful when changing the Padding.
ControlPaint.DrawFocusRectangle(e.Graphics, e.ClipRectangle, checkBox.ForeColor, checkBox.BackColor);
}
}
I also adjusted the CheckBox.Padding to be 2, 2, 0, 1 in order to get a border that was 1 pixel from the edge of the CheckBox.
You can fix this by setting the AutoSize property = False. When AutoSize is True, it acts like a Label with AutoSize set to true, in that an empty label will take up almost no space on the screen. With AutoSize = False, you can manually set the bounding rectangle for the checkbox.
If you draw border only, try to set these properties.
AutoSize : False
CheckAlign : MiddleCenter
Font: Courier New, 12.25pt
TextAlign: MiddleRight
Padding : 0, 5, 0, 0
Size : 26, 26
Text : " " (two spaces)
Related
We are using Infragistics' UltraCombo in a WinForms app.
Sometimes the displayed text (in the combo box itself, i.e. when it's not expanded) is too long to be completely shown.
Is there any way to only provide tooltips when this text is cut off and not to show the tooltip when the displayed text completely fits into the UltraCombo combobox?
Many thanks...
The only way I am aware is to manually determine if the current text is too wide.
Add a tooltip to the form. Then handle the TextChanging event on your combo box.
private void ultraCombo1_TextChanged( object sender, EventArgs e )
{
var textWidth = TextRenderer.MeasureText( ultraCombo1.Text, ultraCombo1.Font ).Width;
var textBoxWidth = ultraCombo1.ClientRectangle.Width - SystemInformation.VerticalScrollBarWidth;
if ( textWidth < textBoxWidth )
toolTip1.SetToolTip( ultraCombo1, "" );
else
toolTip1.SetToolTip( ultraCombo1, ultraCombo1.Text);
}
I'm working on an application where a user defines a the controls on a form and can set the tab index of any control. As each control is added to the Grid that comprises the viewable form area, the tab index is set to either 0 (default) or some user-defined tab index. Tabbing through the form works fine until the tabindex of one of the controls is changed at runtime(the index doesn't seem to matter.) After this, tabbing cycles only through some of the controls and in addition, the window menu items are now tab stops(they weren't prior to the tabindex change.) Also, the menu's tab properties aren't bound to any datacontext.
The control that's currently changed is a checkbox, but I'm unable to reproduce the behavior with a simplified layout, so any suggestions would help.
Our "form pages" user controls invisible and beneath the current visible page were never disabled when new ones were pushed on the top. Therefore they were included in the tab indexing behavior causing unwanted side effects.
This helped me get to the bottom of the issue:
void InitializeFocusLogger() {
//debug key logging to make focus bugs easier to track
EventManager.RegisterClassHandler(
typeof(UIElement),
Keyboard.PreviewGotKeyboardFocusEvent,
(KeyboardFocusChangedEventHandler)OnPreviewGotKeyboardFocus);
}
string lastID = string.Empty;
private void OnPreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) {
FrameworkElement control = e.NewFocus as FrameworkElement;
if (control == null) return;
ControlViewModel controlVM = control.DataContext as ControlViewModel;
if (controlVM == null || lastID == controlVM.ID) return;
lastID = controlVM.ID;
Debug.Print("Focused: {0} TabIndex: {1}", controlVM.ID, controlVM.TabIndex);
}
I've a Datagrid whose DataContext is assigned to a Dataview. When I try to edit the datagrid shown in the form there appears a red border around the cell being editted AFTER I click out or press Enter.
I then try double clicking on another cell but it won't allow me to be in edit mode.
I've tried following http://www.scottlogic.co.uk/blog/colin/2009/01/wpf-datagrid-committing-changes-cell-by-cell/ and http://codefluff.blogspot.com/2010/05/commiting-bound-cell-changes.html but neither appear to work on my case.
My Code for the CellEditEnding event
private void dgCompList_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
if (!isManualEditCommit)
{
isManualEditCommit = true;
System.Windows.Controls.DataGrid grid = (System.Windows.Controls.DataGrid)sender;
grid.CommitEdit(DataGridEditingUnit.Row, true);
isManualEditCommit = false;
}
}
I've also tried using CommitEdit() on the actual datagrid itself, but nada. Could someone explain to me what's going on and how to resolve this please?
normally, a red border around the cell is a error state, so it sounds like you have some type of validation error, to me.
In a Silverlight application I have a custom control with a number of custom properties. In the declaration class of the custom control additionally to defining its properties as dependency properties, I define showing a ToolTip:
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
Border bordercntr = base.GetTemplateChild("PART_SBorder") as Border;
bordercntr.MouseEnter += new MouseEventHandler(bordercntr_MouseEnter);
bordercntr.MouseLeave += new MouseEventHandler(bordercntr_MouseLeave);
}
private void bordercntr_MouseEnter(object sender, MouseEventArgs e)
{
string _sno = this.SomeProperty.ToString();
ToolTipService.SetToolTip(this, "Some text " + _sno);
VisualStateManager.GoToState(this, "Hovered",false);
}
The problem is, that a ToolTip pops up not the first time mouse points to a custom control, but only after the second time. After I reload page this happens again: the first time I hover over a control nothing is shown up and then from the second time and further on the ToolTip pops up again. (not always in a stable way, I mean not 100% each time mouse hovers).
What could prevent the ToolTip from showing up in a stable manner each time a mouse hovers over control and starting showing up from the very first time of hovering it after reloading the page?
Set the ToolTip in the setter for SomeProperty The ToolTip you define in the ToolTipService will behave like a normal ToolTip and only appear when the mouse is over the control. You shouldn't need to handle the MouseEnter and MouseLeave events at all.
I have a checkbox with no text specified. Now whenever I tab down to this checkbox, it doesnot get highlighted.I even tried setting focus in checkbox_Enter() event. I checked for focus in this event and focus is there in this checkbox. How to get it highlighted so that user can know that the cursor is there in checkbox.
Try putting just a space into the Checkbox
Or
setting AutoSize to false
Setting the size of the Checkbox
Then there may be somewhere for WinForms to draw the focus ret.
Otherwise you have to to custom draw the Checkbox, or draw the focus rec round the Checkbox yourself.
Whatever you do it will not look that good, as users expect the focus rec to be round the label of the checkbox, and you wish to have a checkbox with no label.
I managed to do it by the below mentioned way
Use a panel.Push the checkbox inside that panel.Set the dimensions of a panel as such that it looks like a rectangle around the checkbox.In checkbox_enter() event set the border
BorderStyle.FixedSingle;
And in checkbox_Leave() event set the border again to
BorderStyle.None;
So this way it will tell user that focus in inside the checkbox.
To make the checkbox appear highlighted I had it change color on got focus and change back on lost focus.
this part is in the Form1.Designer.cs:
private void InitializeComponent()
{...
ckBox1.GotFocus += new System.EventHandler(checkBox_Highlight);
ckBox1.LostFocus += new System.EventHandler(checkBox_EndHighlight);
ckBox1.MouseHover += new System.EventHandler(checkBox_Highlight);
ckBox1.MouseLeave += new System.EventHandler(checkBox_EndHighlight);
}
This part is in the Form1:
private void checkBox_Highlight(object sender, EventArgs e)
{
CheckBox control = (CheckBox)sender;
control.FlatStyle = FlatStyle.Flat;
control.ForeColor = Color.Blue;
}
private void checkBox_EndHighlight(object sender, EventArgs e)
{
CheckBox control = (CheckBox)sender;
if (!control.Focused)
{
control.ForeColor = DefaultForeColor;
}
}
While tabbing, this puts a light blue shadow beneath the CheckBox on Enter and on Leave - at least on my Windows7:
...
checkBox1.Enter += new System.EventHandler(check_Enter);
checkBox1.Leave += new System.EventHandler(check_Leave);
...
private void check_Enter(object sender, EventArgs e)
{
((CheckBox)sender).BackColor = SystemColors.Highlight;
}
private void check_Leave(object sender, EventArgs e)
{
((CheckBox)sender).BackColor = Color.Transparent;
}
Actually the highlights comes on the text of the checkbox not the checkbox itself
So, if I was you, I would put any control in the background of my check box and give it the focus when my checkbox is focused, to have the same look of default controls highlights.
which will be shown to end users as checkbox highlights.