Solved

LinkLabel Alignment

Posted on 2007-11-22
5
632 Views
Last Modified: 2013-11-06
Hello

I've created a hyperlink on my Visual Basic 2005 form using the linklabel class.  I was wondering how I can align the linklabel to the center of the form?

The linklabel width should be the same width as the form and the text within the linklabel should be centered.

Thanks
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 

        Dim LinkLabel1 As New LinkLabel()

        LinkLabel1.Text = "VB Forums"

        LinkLabel1.Location = New Point(136, 40)

        LinkLabel1.Size = New Size(700, 70)

        LinkLabel1.BackColor = Color.Transparent

        LinkLabel1.Font = New Font("Arial", 24)

        LinkLabel1.DisabledLinkColor = System.Drawing.Color.White

        LinkLabel1.VisitedLinkColor = System.Drawing.Color.White

        LinkLabel1.LinkColor = System.Drawing.Color.White

        Me.Controls.Add(LinkLabel1)
 

        AddHandler LinkLabel1.LinkClicked, AddressOf LinkLabel1_LinkClicked
 

End Sub
 
 

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
 

System.Diagnostics.Process.Start("http://www.vbforums.com")
 

End Sub

Open in new window

0
Comment
Question by:eagles396
  • 3
  • 2
5 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20335959
is it the unique control in the form? you can use set the control's Dock property to Fill and TextAlign to MiddleCenter
0
 

Author Comment

by:eagles396
ID: 20336071
Thanks for your help. I've added the below code and the link now appears to be aligned in the center. Is there anyway to change the height of the linklabel from TopCenter to 50 pixels from the top of the form?
LinkLabel1.Dock = DockStyle.Fill

LinkLabel1.TextAlign = ContentAlignment.TopCenter

       

Open in new window

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20336085
yes, but you have to use a different approach:
Set the DockStyle to None
Resize manually the control to have the size you want, with the current form size.
Set Anchor property to Left,Top,Right & bottom
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 350 total points
ID: 20336094
LinkLabel1.Dock = DockStyle.None
LinkLabel1.Anchor = AnchorStyles.Top Or AnchorStyles.Left Or AnchorStyles.Bottom Or AnchorStyles.Right

0
 

Author Comment

by:eagles396
ID: 20336149
Thanks for your help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Recommendation vb6 to vb.net or others 14 112
Receiving a string from a WebService Push 21 37
Close tabpage of custom control 9 23
Need a starter for ETL protocol? 4 42
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now