How to put buttons / titles with different design / style in C #? [closed]

4

In C # is there any way to put eg the buttons with a different design, or the title with a different style? I want to get my program fancy.

    
asked by anonymous 10.03.2014 / 15:12

2 answers

2

You are looking for Windows Presentation Foundation (WPF) >, Microsoft's solution for rich applications. But keep in mind that there is a sharp learning curve for WinForms developers . If you have any experience with rich application development (Flex , JavaFX or mainly Silverlight ) and a good understanding of markup languages modern the principles of WPF are more natural. Start by searching for XAML , a language based in XML, the C # counterpart (or any other .NET language) used in the declaration of components.

    
10.03.2014 / 15:36
4

For buttons or titles with different designs you could simply use a PictureBox and place a specific image. Now, if you want something a bit more complex, you can create a class by inheriting the Button class (in the case of a button) and change some details, override events using override according to your criteria etc.

At the level of curiosity, it follows the code of how to create a custom button using the class Graphics :

    public Form1()
    {
        InitializeComponent();

        BotaoPersonalizado objBotao = new BotaoPersonalizado(); //Inicializando o botão personalizado.

        //Incluindo a ele um evento Click:
        EventHandler evento = new EventHandler(objBotao_Click);
        objBotao.Click += evento;

        objBotao.Location = new System.Drawing.Point(100, 200); //Definindo sua posição na tela.
        objBotao.Size = new System.Drawing.Size(200, 305); //Definindo seu tamanho.

        this.Controls.Add(objBotao); //Adicionando o controle ao formulário.
    }

    public class BotaoPersonalizado : System.Windows.Forms.UserControl
    {
        //Sobrescrevendo o método OnPaint para desenhar o botão:
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics graphics = e.Graphics;
            Pen pen = new Pen(Color.Blue);

            float cordenadaX = 0, cordenadaY = 0, largura = 100, altura = 100; //Definindo características da elipse delimitada por um retângulo.
            graphics.DrawEllipse(pen, cordenadaX, cordenadaY, largura, altura); //Desenhando a elipse.
            pen.Dispose(); //Liberando os recursos usados.
        }
    }

    void objBotao_Click(Object sender, System.EventArgs e)
    {
        MessageBox.Show("Olá");
    }
    
10.03.2014 / 15:23