none
Arrotondamento Bottoni RRS feed

  • Domanda

  • Ho l'esigenza di visualizzare in VB dei bottoni arrotondati

    Dopo diversi tentativi con riultati insoddisfacenti ho trovato sul web la seguente routine

       Private Sub ArrotondaBottone(btn As Button)
            btn.FlatStyle = FlatStyle.Flat
            btn.FlatAppearance.BorderSize = 0
            btn.Cursor = Cursors.Hand
            Dim Raduis As New Drawing2D.GraphicsPath
            Raduis.StartFigure()
            'appends an elliptical arc to the current figure
            'left corner top
            Raduis.AddArc(New Rectangle(0, 0, 20, 20), 180, 90)
            'appends a line segment to the current figure
            Raduis.AddLine(10, 0, btn.Width - 20, 0)
            'appends an elliptical arc to the current figure
            'right corner top
            Raduis.AddArc(New Rectangle(btn.Width - 20, 0, 20, 20), -90, 90)
            'appends a line segment to the current figure
            'Raduis.AddLine(btnRound.Width, 20, btn.Width, btn.Height - 10)
            Raduis.AddLine(btn.Width, 20, btn.Width, btn.Height - 10)
            'appends an elliptical arc to the current figure 
            'right corner buttom
            Raduis.AddArc(New Rectangle(btn.Width - 25, btn.Height - 25, 25, 25), 0, 90)
            'appends a line segment to the current figure
            'left corner bottom
            Raduis.AddLine(btn.Width - 10, btn.Width, 20, btn.Height)
            'appends an elliptical arc to the current figure
            Raduis.AddArc(New Rectangle(0, btn.Height - 20, 20, 20), 90, 90)
            'Close the current figure and start a new one.
            Raduis.CloseFigure()
            'set the window associated with the control
            'btnRound.Region = New Region(Raduis)
            btn.Region = New Region(Raduis)
        End Sub
    

    Funziona tranne che per i bottoni con altezza > larghezza

    esempio :

    Qualcuno mi può aiutare suggerendo modifiche alla routine o proponendone un ' altra ?

    Grazie

    domenica 24 maggio 2020 06:40

Tutte le risposte

  • Ciao, controlla le istruzioni relative alla costruzione dell'angolo destro.
    Hai semplicemente usato "Width" dove ci andava "Height":

        Private Sub ArrotondaBottone(btn As Button)
            btn.FlatStyle = FlatStyle.Flat
            btn.FlatAppearance.BorderSize = 0
            btn.Cursor = Cursors.Hand
            Dim Raduis As New Drawing2D.GraphicsPath
            Raduis.StartFigure()
            'appends an elliptical arc to the current figure
            'left corner top
            Raduis.AddArc(New Rectangle(0, 0, 20, 20), 180, 90)
            'appends a line segment to the current figure
            Raduis.AddLine(10, 0, btn.Width - 20, 0)
            'appends an elliptical arc to the current figure
            'right corner top
            Raduis.AddArc(New Rectangle(btn.Width - 20, 0, 20, 20), -90, 90)
            'appends a line segment to the current figure
            'Raduis.AddLine(btnRound.Width, 20, btn.Width, btn.Height - 10)
            Raduis.AddLine(btn.Width, 20, btn.Width, btn.Height - 10)
            'appends an elliptical arc to the current figure 
            'right corner buttom
            Raduis.AddArc(New Rectangle(btn.Width - 20, btn.Height - 20, 20, 20), 0, 90)
            'appends a line segment to the current figure
            'left corner bottom
            Raduis.AddLine(btn.Width - 10, btn.Height, 20, btn.Height)
            'appends an elliptical arc to the current figure
            Raduis.AddArc(New Rectangle(0, btn.Height - 20, 20, 20), 90, 90)
            'Close the current figure and start a new one.
            Raduis.CloseFigure()
            'set the window associated with the control
            'btnRound.Region = New Region(Raduis)
            btn.Region = New Region(Raduis)
        End Sub

    domenica 24 maggio 2020 21:11
  • OK funziona

    ti ringrazio

    lunedì 25 maggio 2020 05:09