Custom Buttons in C# WinForms

前端 未结 2 422
梦谈多话
梦谈多话 2020-12-19 23:43

I have done a bit of research but cannot seem to find what I am looking for.

What I want to do is make a \"custom\" button in a windows form. This would basically ju

相关标签:
2条回答
  • 2020-12-20 00:16

    The solution I found was to set the FlatStyle of the button to Flat and set all the borders to 0. I then had a problem with the focus of the button (it displayed a little border). To solve this I followed this tutorial:

    http://dotnetstep.blogspot.com/2009/06/remove-focus-rectangle-from-button.html

    With this in place all I had to do was add events to the button so that the image was changed when a certain action was carried out on it:

        private void button1_MouseLeave(object sender, EventArgs e)
        {
            this.button1.Image = Properties.Resources._default;
        }
    
        private void button1_MouseEnter(object sender, EventArgs e)
        {
            this.button1.Image = Properties.Resources._hover;
        }        
    
        private void button1_MouseDown(object sender, MouseEventArgs e)
        {
            this.button1.Image = Properties.Resources._clicked;
        }
    
        private void button1_MouseUp(object sender, MouseEventArgs e)
        {
            this.button1.Image = Properties.Resources._default;
        }
    

    Hope this will help someone else!

    0 讨论(0)
  • 2020-12-20 00:18

    It is called owner-drawn button

    refer to:
    Mick Dohertys' .net Tips and Tricks - Tips / Button
    GlowButton - A Glowing Button Control
    A shiny orb button in GDI+

    0 讨论(0)
提交回复
热议问题