Hi guys,

i created a panel with few buttons, all buttons have the same size, most buttons hold images, 2 of them hold string (1 or 2 digit)

the string buttons will not align with the rest of them, and i have no idea why ?

anyone ?

Public Class AccountTypes
    Inherits System.Windows.Forms.Form
    Private grdAccountTypes As New DataGridView()
    Private bindingSource1 As New BindingSource()
    Private dataAdapter As New SqlDataAdapter()
    Private CurrentRow As New DataGridViewRow()
    ' Declare Form Componantes
    Private WithEvents btnReload As New Button()
    Private WithEvents btnSubmit As New Button()
    Private WithEvents btnDelete As New Button()
    Private WithEvents btnAddRecord As New Button()
    ' Record Nav Buttons
    Private WithEvents btnNextRow As New Button()
    Private WithEvents btnLastRow As New Button()
    Private WithEvents btnPreviousRow As New Button()
    Private WithEvents btnFirstRow As New Button()
    ' Labels
    Private WithEvents lblRowCounter As New Label()
    Private WithEvents lblof As New Label()
    Private WithEvents lblRecords As New Label()
    Private WithEvents lblCRM As New Label() ' CRM Current Row Number
    ' Tooltip
    Private WithEvents toolTip1 As System.Windows.Forms.ToolTip

    ' Initialize the form.
    Public Sub New()

        ' Button Size Variables
        Dim X, Y As Integer
        X = 24
        Y = 24

        ' DataGridView Style Definitions
        grdAccountTypes.Dock = DockStyle.None
        grdAccountTypes.ScrollBars = ScrollBars.None
        grdAccountTypes.MultiSelect = False
        grdAccountTypes.SelectionMode = DataGridViewSelectionMode.FullRowSelect

        'Declare form buttons
        'reload Button
        Me.btnReload.Size = New Size(X, Y)
        Me.btnReload.Image = Image.FromFile("C:\Yugo\reload16.png")
        'Submit Button'
        Me.btnSubmit.Image = Image.FromFile("C:\yugo\submit.png")
        Me.btnSubmit.Size = New Size(X, Y)

        'Delete Button
        Me.btnDelete.Size = New Size(X, Y)
        Me.btnDelete.Image = Image.FromFile("C:\Yugo\delete.png")

        'Add Record Button
        btnAddRecord.Image = Image.FromFile("C:\Yugo\deleteblack.png")
        Me.btnAddRecord.Size = New Size(X, Y)

        'Add First Row Button
        btnFirstRow.Image = Image.FromFile("C:\Yugo\FirstRow.png")
        Me.btnFirstRow.Size = New Size(X, Y)

        ' Add previous row button
        btnPreviousRow.Image = Image.FromFile("C:\Yugo\PreviousRow.png")
        Me.btnPreviousRow.Size = New Size(X, Y)

        ' Add Next Row Button
        btnNextRow.Image = Image.FromFile("C:\Yugo\NextRow.png")
        Me.btnNextRow.Size = New Size(X, Y)

        'Add last row button
        btnLastRow.Image = Image.FromFile("C:\Yugo\LastRow.png")
        Me.btnLastRow.Size = New Size(X, Y)

        lblCRM.Size = New Size(X, Y)
        lblCRM.BackColor = Color.White
        lblCRM.TextAlign = ContentAlignment.MiddleCenter
        lblCRM.Font = New System.Drawing.Font("Arial", 8)

        lblof.Size = New Size(X, Y)
        lblRowCounter.BackColor = Color.White
        lblof.TextAlign = ContentAlignment.MiddleCenter
        lblof.Text = "of"
        lblof.Font = New System.Drawing.Font("Arial", 9)

        lblRowCounter.Size = New Size(X, Y)
        lblRowCounter.BackColor = Color.White
        lblRowCounter.TextAlign = ContentAlignment.MiddleCenter
        lblRowCounter.Font = New System.Drawing.Font("Arial", 8)

        'Add the buttons panel to the form
        Dim panel1 As New FlowLayoutPanel()
        panel1.Dock = DockStyle.Bottom
        panel1.Width = 110
        panel1.Height = 28
        panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        panel1.AutoSize = True
        panel1.Controls.AddRange(New Control() {Me.btnReload, Me.btnSubmit, Me.btnDelete, Me.btnAddRecord, Me.btnFirstRow, Me.btnPreviousRow, Me.lblCRM, Me.lblof, Me.lblRowCounter, Me.btnNextRow, Me.btnLastRow})
        Me.Controls.AddRange(New Control() {panel1, Me.grdAccountTypes})

Edited 6 Years Ago by __avd: Added [code] tags.

I do not see declaration of buttons that do not use images. Lines 42 and 49 show buttons that are being sized first, then being setup with the image. Perhaps this could be a problem? Otherwise...
If you're using Visual Studio, there is a toolbar named Layout.
This will show a series of buttons that will automatically center horizontally/vertically, identical sizing, align to grid, and ...yes... align tops, align left side, align bottoms, and align right side

Not sure if this helps at all, but worth a try!

Edited 6 Years Ago by bklynman01: n/a

This article has been dead for over six months. Start a new discussion instead.