I have a button on my form that has flat style applied and uses a background image, I have removed all borders from the button, but when I tab onto the button from another control a black border appears around the button.
This can be seen in the image below. On the left is the button with black border on the right is a different button but shows how the cancel button should look.
I do not get this border, if I set the BoderSize to 0 in the FlatAppearance section.
Further investigation shows that this border appears only when the button is the default button. You can create your own button, which does never show this border like this
public class NoNotifyButton: System.Windows.Forms.Button
{
public override void NotifyDefault(bool value)
{
}
}
Note: NotifyDefault remains intentionally empty.
You have to make a new button class using IButtonControl and change NotifyDefault to false:
base.NotifyDefault(false);
You don't have to create a derived class.
You can set the ForeColor to be the same as parent control BackColor.
As follows :
btn1.ForeColor = btn1.Parent.BackColor;
You can do it setting the button property "ForeColor" to transparent
I managed to get around this by setting the button TabStop property to False and then using this code on the button click event
private void sendBackTab()
{
System.Windows.Forms.SendKeys.SendWait("+{TAB}");
}
Related
I've been looking around everywhere but couldn't find any solutions.
My problem is that when pressing TAB (to move around the form focusing on different controls), the buttons get an ugly inset border that I do not want, there's no option to disable it either.
Note that these inset borders only show on the recently selected/clicked button, not on all at once, it displays on whatever button is focused/selected, here are a few examples:
How I want the button to look (and how it looks before pressing TAB)
How the button looks after pressing TAB
And that's what all buttons in the form look like when focused until the form is reopened
Any tips? Thanks in advance for help!
Have the ShowFocusCues return false, although that can be annoying for users who use tabs to navigate.
public class MyButton : Button {
protected override bool ShowFocusCues {
get {
return false;
}
}
}
I have created a windows form with two panels with width 25:75 ratio. That is 25 ratio is the sidemenu and the other panel is Main menu/screen of app.So i used usercontrol and dragged & dropped it on the Main screen of form when user clicks the respective button on the sidemenu then the usercontrol is seen.
Also the side menu has a partial hide feature the is a three lined button on top right of sidemenu panel when user clicks that button the menu partially hides (basically decreasing width of sidemenu and increasing the with of main menu).
The problem is usercontrol has a tabcontrol in it when user clicks hide button on sidemenu the mainmenu width increases but it leaves the width of tabcontrol as it is.
I want to also change the width of tabcontrol when user clicks hide button on sidemenu, i am not getting access to tabcontrols width which is in usercontrol in panel in form...
What I have tried:
I have tried to access the width of tab control as follows:
//inside hide button in panel1 of form1
private void hidemenu_click()
{
usercontrol1.tabcontrol1.width= mainmenu.width;
}
but there isn't any suggestion showing by intellisense.... simply showing error
error:
are you missing a using reference or an assembly reference?
Try removing usercontrol1 as when I drag&dropped a tabcontrol, I could acces the Width property of it.
This worked for me...!!!
Open the user control in the designer.
Select the tab control.
In the property grid, change the "Modifiers" to public.
Or, open the user control's code file, and add a public property to get and set the width of the tab control.
public int TabControlWidth
{
get { return tabcontrol1.Width; }
set { tabcontrol1.Width = value; }
}
I have created an Outlook add in which at some point displays a windows form with four buttons present on it. I am trying to default the focus to the first button, however the visual "selected" border will not appear around the button whenever I default this button as the focused one on start.
Any ideas how I could achieve this?
You can use either of these options to set the focus on a control in Load event of the form:
this.ActiveControl = this.button1;
this.button1.Select();
this.Show(); this.button1.Focus();.
You can use the Control.Focus method in the Load event of the form to set the focus on a control only after the Visible property of the form is set to true.
After selection the button, the border of the button will be drawn in a way that shows it's the active control, but the focus cues will not be drawn.
As a quick and dirty fix, you can send a Tab, and a Shift + Tab to your form:
SendKeys.SendWait("{TAB}");
SendKeys.SendWait("+{TAB}");
If you are interested to change the standard behavior of Button to see focus cues when you select button in code or using mouse, you can create your own button inheriting Button and override its ShowFocusCues to return Focused value. You can read more about it here:
public class MyCustomButton : Button
{
protected override bool ShowFocusCues
{
get { return this.Focused; }
}
}
I know this tab draw item event in the link below will work fine on form load for all tabs and changes the tab header colors in tab control, but I am wondering how can I call/fire this event on a button click?. For example on form load it would be white and on button click it be red
Set TabPage Header Color
The DrawItem event is fired when the Tab control is drawn. The drawing itself triggered by the area being "invalidated" (i.e. the graphics are no longer "valid" and need updating).
This can be seen in the cited question's answer's code.
private void SetTabHeader(TabPage page, Color color)
{
TabColors[page] = color;
tabControl1.Invalidate();
}
The key method call here is "tabControl1.Invalidate();" it is this call that in turn triggers the drawing.
Therefore you could either place similar code in the click event handler of your button, or simply call SetTabHeader if using that exact code sample.
I have a tab control and need to remove the dotted focus rectangle around the selected tab.
I have set the TabStop property of the TabControl to false. However if I click on a tab and press the Tab key, the dotted rectangle appears around the tabname.
I have tried creating my own TabControl and tried this
class MyTabControl : TabControl
{
public MyTabControl()
{
TabStop = false;
DrawMode = TabDrawMode.OwnerDrawFixed;
DrawItem += new DrawItemEventHandler(DoMoreTabControl_DrawItem);
Invalidate();
}
}
However, the dotted rectangle still appears.
I also tried overriding the MyTabControl.OnPaint() method but it doesn't help.
Is there any way to achieve this?
Set the focus to tab instead of header (like this)
private void tabControl1_Click(object sender, EventArgs e)
{
(sender as TabControl).SelectedTab.Focus();
}
You will see dotted rectangle for a millisecond, as soon as the above event gets executed it will disappear.
Also, to remove dotted rectangle for default selected tab on load
private void tabControl1_Enter(object sender, EventArgs e)
{
(sender as TabControl).SelectedTab.Focus();
}
Both this changes worked for me!
hope it helps somebody.
Yes, DrawItem event. You didn't post it, impossible to guess what's wrong with it. Just make sure that you don't call e.DrawFocusRectangle(), likely to present when you copied the MSDN sample code. Simply deleting the statement is sufficient. Consider using a different background color or text font style as an alternative so the focus hint isn't entirely lost.