Visual Basic .NET Nightmare or Guide to upgrading a Guru.

Page 8

Hyper Mart  


Me.LinkLabel1.Links.Add(0, 4, "")
Private Sub LinkLabel1_LinkClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked


End Sub

Me.LinkLabel1.Text = "Home      Search      VBnet      Mikeyville      MSDN"
Public Sub New()


'This call is required by the Windows Form Designer.


Me.LinkLabel1.Links.Add(0, 4, "")

Me.LinkLabel1.Links.Add(9, 6, "")

Me.LinkLabel1.Links.Add(20, 5, "")

Me.LinkLabel1.Links.Add(30, 10, "")

Me.LinkLabel1.Links.Add(45, 4, "")

'Add any initialization after the InitializeComponent() call

End Sub

  • As a final touch we want to change .TextAlign property for our link label to center. This centers our link menu nicely at the bottom of our form even when it has been resized.
  • So what did I forget? Well for starters adding some lovely code to set the visited color. In an app I hardly see the point. Okay you might be wondering how to quickly set the link's color to visited. Here's the code straight from the help file.
LinkLabel1.Links(LinkLabel1.Links.IndexOf(e.Link)).Visited = True
  • We know that what's inside of our first set of Parens is signifying the index of the Links collection.  We are getting the index from the method belonging to the Link Object called .IndexOf. This returns the index of the  link object passed to it from our passed object. After that is our .Visited property which we are then setting to true, this magically makes the link's color change to the designated visited color.

  • Maybe this could be useful in the way someone works in your app.  Perhaps working with a database and entering each item.  What then takes place is the end user clicks a link to signify that a certain portion of their work is done and helps them keep track of what they need to do next or each link could point to helpful information for each task they are working on. As with any app, the possibilities are endless.

Not to be under whelmed by all the link label stuff is the power of the System.Diagnostics.Process Object. In fact let's take a closer look at this thing.

  • Let's start with a different way of getting this into our app. Bring up your form view. Then from the tools click the components section. Now let's drag and drop a process into our form's area.  This is not a visible control so it goes neatly below your form and doesn't get in the way of you designing the look of your window.

  • Now what do I do with it? Well you want to set it up to handle a process for your app.  Go into it's properties and click the plus next to .StartInfo. In the .FileName property type in notepad. then let's name our process MyProcess. Next let's add a button and name it btnNote.

  • Generate the click event for your button and add this line in for code.

Private Sub btnNote_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNote.Click


End Sub

  • Could this be any simpler? You can launch another application and already be hooked into it with your own drag and drop process object.  This is relevant to VB6's API calls to which you can launch apps and retain their process ID or Handle. From within our app we can either kill the process or request it to close (if it's a windowed app.) Or we can simply wait for it to close and then do something further if needs be.

  • Also we are not restricted to calling just apps, we can call files associated with apps and send parameters to them when we open them.  Let's say we have a MyDoc.Doc in our My Documents folder. With the assumption that Word is part of your Kingdom, the we can add the .FileName to our process's .StartInfo. Make sure .UseShellExecute=True. This is probably familiar to you if you have used the same API call to open another program. next time you click the Note button when you start your process the document opens inside of wordomatical.  You can alternatively set up your Hyperlink's collection to access a series of related documents to whatever it is your app is doing.

  • Also we want to note that the .StartInfo property is a collection of properties this is why it's expanded in the properties window.

We now have some good info on how to get around our system via links and process control.  This easily extends our app's power to using more than just files in directories, with both combined we are slowly mastering the techniques we need to have a serious application.

Page 9