Click here to Skip to main content
15,940,373 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi All,

I am using a Button with FlatStyle = System.Windows.Forms.FlatStyle.Standard. Now the problem is in this I am using an Image which is dancing and button border is also changing on Mouse Enter and Mouse Leave time.

I don't know how to fix this problem and also how to make the Button border color as gray with a width of 1.


Thanks in advance.
Posted
Updated 4-Mar-11 20:39pm
v4

Try setting the property like so:

this.myButton.FlatAppearance.BorderSize = 0;
 
Share this answer
 
Hi,

The simple way would be ..

C#
class BorderlessButton:Button
{
    protected override void OnPaint(PaintEventArgs pevent)
    {
        base.OnPaint(pevent);
        pevent.Graphics.DrawRectangle(new Pen(this.BackColor,5), this.ClientRectangle);
    }
}


Once you compile this class. it will be available in the tool box. Drag to form. Set flat style. Display your image.
 
Share this answer
 
Comments
Henry Minute 4-Mar-11 11:26am    
Good answer.
sairam.bhat 5-Mar-11 3:44am    
good answer
AFAIK the only way to alter the border of a 'standard' button is to draw it yourself. This would also be the best way to overcome your problems with the Image.

Owner-draw button[^] is a good example from here on the Code Project.

If you don't like that one there are loads of other examples on the web just search on owner draw button.
 
Share this answer
 
Comments
Albin Abel 4-Mar-11 11:39am    
Owner draw is the way to customize appearance of windows form controls. My 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900