How to deform a button? [closed]

0

How do I deform a button by using the button's Paint event to take the shape of the Enter key or even the shape of a circle?

    
asked by anonymous 22.08.2016 / 15:27

2 answers

7

A simple way is to respond to the event Paint button, draw the desired shape there and assign it to the Region of the button.

Example for a circular button ( source )

//Este método transforma a forma do botão standard em circular,
// criando um forma em circulo e atribuindo-a à propriedade region do botão
private void roundButton_Paint(object sender, 
    System.Windows.Forms.PaintEventArgs e)
{

    System.Drawing.Drawing2D.GraphicsPath buttonPath = 
        new System.Drawing.Drawing2D.GraphicsPath();

    //Cria um rectangulo com o mesmo tamanho que o botão
    System.Drawing.Rectangle newRectangle = roundButton.ClientRectangle;

    // Diminui o tamanho do ractangulo.
    newRectangle.Inflate(-10, -10);

    // Desenha a borda do botão.
    e.Graphics.DrawEllipse(System.Drawing.Pens.Black, newRectangle);

    // Aumenta o tamanho do rectangulo para incluir a borda.
    newRectangle.Inflate( 1,  1);

    // Cria um circulo dentr0 do rectangulo.
    buttonPath.AddEllipse(newRectangle);

    //Atribui o circuloa propriedade region
    roundButton.Region = new System.Drawing.Region(buttonPath);

}
    
22.08.2016 / 15:47
4

Pekita, the best that can be done with the standard WinForms Button (at least to my understanding) is to set your style to Flat (FlatStyle = Flat), remove its borders (FlatAppearence.BorderSize = 0), and set an image such as BackgroundImage.

Otherwise, you can create a custom component with the dimensions and specifications you want, but the implementation and layout of it must be done manually, obviously being able to inherit from the default Button object.

An example of how it could be done to my understanding would be the joining of several quadrangular images that would form together the shape of the "Enter" button and when any of these images is pressed the click of the button is fired.

Maybe this is not the most appropriate solution, but that's what I came up with to help you. I suggest you wait to identify other possible suggestions or answers.

    
22.08.2016 / 15:40