I created a flat Button with a transparent border, also setting FlatAppearance.BorderSize = 0
.
The border is hidden on a mouse click and the Button background uses a custom Color when the Mouse button is pressed.
My problem is that cannot remove the border that is drawn when the Button becomes active, for example pressing the Tab key.
I can't use the TabStop
property (set it to false) because I want the functionalities I've designed.
I just want to paint the background color and hide the border (the same as mouse click colors).
The Button properties in the Form Designer:
this.importBtn.BackgroundImage = global::CompetitionManager.Properties.Resources.Open;
this.importBtn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
this.importBtn.Cursor = System.Windows.Forms.Cursors.Hand;
this.importBtn.Delta = 5;
this.importBtn.Dock = System.Windows.Forms.DockStyle.Fill;
this.importBtn.FlatAppearance.BorderSize = 0;
this.importBtn.FlatAppearance.MouseDownBackColor = System.Drawing.Color.SteelBlue;
this.importBtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;
this.importBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.importBtn.ForeColor = System.Drawing.Color.Transparent;
this.importBtn.Location = new System.Drawing.Point(3, 50);
this.importBtn.MoveXDirection = false;
this.importBtn.MoveYDirection = true;
this.importBtn.Name = "importBtn";
this.importBtn.Size = new System.Drawing.Size(183, 162);
this.importBtn.TabIndex = 0;
this.ToolTip.SetToolTip(this.importBtn, "Import Competitors (Excel/XML)");
this.importBtn.UseMargin = true;
this.importBtn.UseVisualStyleBackColor = true;
this.importBtn.Click += new System.EventHandler(this.ImportFile_Click);
As described in the question, the custom control - a Button, here - is showing its standard Focus Cues when it becomes the ActiveControl. The default rendering doesn't appears to fit in, because the Background color is rendered transparent in a specific context, causing the standard Focus Cue to become obnoxious.
▶ The standard Focus Cue rendering is disabled overriding Control.ShowFocusCues to always return
false
(except when the handle is not yet created).▶ The NotifyDefault method is also overridden, to avoid a similar effect when the Button is used to open a Windows that becomes active: in this case, the Button is rendered with a border meant as a visual clue that it's the ActiveControl of that Window.
▶ Some properties that define the Button specialization are removed from the PropertyGrid using a custom ControlDesigner, to avoid unwanted tampering with specific defining properties.
Finally, a custom Focus Cue is drawn at the bottom of the Custom Control's ClientRectangle, to give some feedback, otherwise a User would have no clue what the current Button/Control is.
The custom cue is not shown when the Mouse is hovering or the Button is being clicked.
It's an example of a possible custom rendering. Of course you can now paint whatever you want: a different border, background, translucent overlay etc.