I have LinkLabel. If i press hotkey, linklable got focus, but dotted area are not appear!
When it got focus by 'Tab', he have dotted focus area:
Next, if press hotkey, dotted area always appear.
How do I get the dotted area immediately appeared with the help of hotkeys?
I found the problem. All the matter in the protected property ShowFocusCues. It is set to the false by default. When you focus control by the "Tab", ShowFocusCues set to the true.
It is an example how to set ShowFocusCues to true:
public class UGLinkLabel : LinkLabel
{
private bool _displayFocusCues = true;
protected override bool ShowFocusCues
{
get
{
return _displayFocusCues;
}
}
public bool DisplayFocusCues
{
get
{
return _displayFocusCues;
}
set
{
_displayFocusCues = value;
}
}
}
Related
Background
In this winforms app, there are two radio buttons that I'm attempting to bind to properties on a model class.
Code
Related properties on the Model:
private bool _bTotalRowsLinear;
private bool _bTotalRowsLog;
public bool bTotalRowsLinear
{
get { return _bTotalRowsLinear; }
set { _bTotalRowsLinear = value; }
}
public bool bTotalRowsLog
{
get { return _bTotalRowsLog; }
set { _bTotalRowsLog = value; }
}
Code to create the bindings:
rdbTotalRowsLinear.DataBindings.Add("Checked",
objModel,
"bTotalRowsLinear",
false,
DataSourceUpdateMode.OnPropertyChanged);
rdbTotalRowsLog.DataBindings.Add("Checked",
objModel,
"bTotalRowsLog",
false,
DataSourceUpdateMode.OnPropertyChanged);
Issue
The initial binding works correctly. However, when I attempt to select the nonselected radio option, I first end up with neither radio button selected, forcing the user to click their desired option twice.
Initial State:
After Clicking Once (error state):
Full code available on Github: https://github.com/nickheidke/datavelocityvisualizer
In your model, set the opposites, eg
set {
_bTotalRowsLinear = value;
_bTotalRowsLog = !bTotalRowsLinear;
}
...
set {
_bTotalRowsLog = value;
_bTotalRowsLinear = !bTotalRowsLog;
}
I found this page, which outlines how to change the rendering for a MenuStrip and its items.
I want to use this, but the problem is that the highlight color when you hover over a button doesn't match it.
Is there any way to change the highlight color from blue to yellow? I've tried using the MouseHover and MouseLeave events, but for some reason they're really slow, and they change the button to a solid color, which looks bad, but leaves a border on the edge of the button that doesn't change.
In the designer:
this.ButtonName.MouseHover += new System.EventHandler(button_mousehover);
And then in the Code:
private void button_mousehover(object sender, EventArgs e)
{
Button btn = sender as Button;
btn.BackColor = Color.Yellow;
}
Is there anything as easy as in the link I posted above to change the highlight color from blue to something else?
Here's the code for changing the rendering of the menu strip:
private void myForm Load(object sender, EventArgs e)
{
myMenuStrip.Renderer = new MenuRenderer();
{
private class MenuRenderer : ToolStripProfessionalRenderer
{
public MenuRenderer() : base(new MyColors()) { }
}
private class MyColors : ProfessionalColorTable
{
public override Color MenuItemSelectedGradientBegin
{
get { return Color.Orange; }
}
public override Color MenuItemSelectedGradientEnd
{
get { return Color.Yellow; }
}
public override Color MenuItemPressedGradientBegin
{
get{ return Color.Yellow; }
}
public override Color MenuItemPressedGradientEnd
{
get { return Color.Orange; }
}
public override Color MenuItemSelected
{
get { return Color.Gold; }
}
}
So it'll change the background of a hovered-over menu item to an orange-yellow gradient, change it to a yellow-orange gradient on click, and any item in the menu will have a gold highlight on hovering.
What I'm trying to do is do that last part (change the highlight to gold/yellow) for the buttons in my form.
In the properties of the button:
under FlatStyle, select Flat.
Then, expand FlatAppearance and under MouseOverBackColor, select the highlight color you want. Alternatively, you can also enter the RGB color you want, under the MouseOverBackColor.
You can take a look at the Button Renderer.
Why do you want to override the renderer when you can simply subscribe to the MouseHover event like so:
this.someButtonName.MouseHover += (s,e) =>
{
this.someButtonName.BackColor = Color.Yellow;
};
I recommend you use a mouse leave too in order to reset the button to it's initial color when your mouse isn't on it anymore.
I have an application with a MenuStrip and every time I hover my mouse over a MenuItem, it highlights blue.
I have tried to change the BackColor and ForeColor but that wasn't the problem.
Is there a way to disable this?
This would be incredibly un-useful to the end user:
internal class NoHighlightRenderer : ToolStripProfessionalRenderer {
protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e) {
if (e.Item.OwnerItem == null) {
base.OnRenderMenuItemBackground(e);
}
}
}
Then apply it to your MenuStrip:
menuStrip1.Renderer = new NoHighlightRenderer();
I got a user control called PicturePanel. On the mouse events (MouseDown, MouseMove, MouseUp), I have the following:
protected override void OnMouseDown(MouseEventArgs e)
{
if (marquee == true && e.Button == MouseButtons.Left && BackgroundImage != null)
{
//Code to create rectangular marquee
}
else
{
}
}
Class level variable private bool marquee = false by default. And a public one.
private bool marquee = false;
public bool Marquee
{
get { return marquee; }
set { marquee = value; }
}
I even tried assigning the false at initialization:
public PicturePanel()
{
InitializeComponent();
marquee = false;
}
But marquee is always true by default. If I want to turn off marquee, I have to set it through the public variable picturePanel1.Marquee = false in the form. How can I make marquee false by default within the user control?
I'm not sure if this is what you're talking about, but if you're referring to the default value that you see in the designer, then you just need to add the following attribute to your property:
[DefaultValue(false)]
public bool Marquee
...
Well, booleans are always false by default. You don't happen to have a local variable called marquee or something?
Just set a breakpoint on private bool marquee = false; and step through your code and you'll find it pretty quick.
Your issue might be that when you use the designer to "draw" the control on the form, it might be registering the MouseDown event, setting the Marquee to true. You can prevent this by checking this.DesignMode in your event handler.
Example:
if (this.DesignMode) return;
I have a Windows Forms application with some buttons for the F keys. When you place the mouse over the buttons the get grey, and when you click they get a slightly lighyer grey. I would like to mimic that behaviour with F key keystrokes... how would you do it?
Set the Form's KeyPreview property to true, handle the KeyDown and KeyUp events, track which function key(s) are pressed, and call the Invalidate method on the button for each key the went down or up.
Then, handle the button's Paint event, and, if its key is down, use the ButtonRenderer class to draw the button as if it were pressed.
Use Button.PerformClick().
Finally I implemented the button changing the background:
class FunctionButton : Button
{
private Color m_colorOver;
private bool m_isPressed;
public FunctionButton() : base()
{
m_isPressed = false;
}
protected override void OnGotFocus(EventArgs e)
{
OnMouseEnter(null);
base.OnGotFocus(e);
}
protected override void OnLostFocus(EventArgs e)
{
if (!m_isPressed)
{
OnMouseLeave(null);
}
base.OnLostFocus(e);
}
protected override void OnMouseLeave(EventArgs e)
{
if (!Focused && !m_isPressed)
{
base.OnMouseLeave(e);
}
}
public void FunctionKeyPressed()
{
// Handle just the first event
if (!m_isPressed)
{
m_isPressed = true;
m_colorOver = FlatAppearance.MouseOverBackColor;
FlatAppearance.MouseOverBackColor = FlatAppearance.MouseDownBackColor;
OnMouseEnter(null);
PerformClick();
}
}
public void FunctionKeyReleased()
{
m_isPressed = false;
FlatAppearance.MouseOverBackColor = m_colorOver;
if (Focused)
{
OnMouseEnter(null);
}
else
{
base.OnMouseLeave(null);
}
}
}
It is not the most clean way but it works fine. I would like more examples doing this with a cleaner and more elegant style.
SetCapture and ReleaseCapture might work.