Results 1 to 36 of 36

Thread: Need Help Badly........(Problems...)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235

    Need Help Badly........(Problems...)

    Example I got a groupbox....

    I want to set some linklabels into this groupbox....

    how do i not use drag and drop linklabels as i want to control how many linklabels i want to put inside this groupbox...
    Last edited by hhh; Sep 27th, 2004 at 12:28 AM.

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    What?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    erm...okie..i got this groupbox...

    i want to add in labels inside this groupbox...but i do want to use the drag and drop way....

    ,manual way....

  4. #4
    Addicted Member
    Join Date
    Aug 2003
    Posts
    153
    I think he wants to be able to programatically declare the labels instead of using the designer.

    What you need to do is something like this..
    (I don't know the exact name of the linklabel control, but this will work for any sort of control)


    VB Code:
    1. 'Somewhere in the form as a private member
    2. Private m_Labels() As LinkLabels
    3.  
    4. Dim i As Integer
    5. 'X and Y co-ordinate position of the current label
    6. Dim x As Integer = 8
    7. Dim y As Integer = 8
    8. Dim labels(MAXLABELS - 1) As LinkLabels
    9. Dim newLabel As LinkLabel
    10.  
    11. 'Iterate thru as many labels as you want
    12. For i = 0 to MAXLABELS - 1
    13.     newLabel = New LinkLabel
    14.  
    15.     'Set the labels values    
    16.     With newLabel
    17.          .Name = "Label" & i.ToString
    18.          .Location = New Point(x, y)
    19.          .Size = (20, 40)
    20.          .Visible = True
    21.          .Text = "Whatever"
    22.     End With
    23.  
    24.     'Add the label to the groupbox
    25.     grpLabels.Controls.Add(newLabel)
    26.  
    27.     'Assign the label to the private array if you want to keep track of it
    28.      labels(i) = newLabel
    29.  
    30.      'Increment the location co-ordinates for the next label
    31.      '(Modify this to suit your form)
    32.      x = x + 48
    33.  
    34. Next
    35.  
    36. m_Labels = labels

    There you go! Bear in mind I haven't done this for a while and don't have VS.Net open at the moment so there may be some syntax errors there, but that should set you down the right path.
    Last edited by Carnifex; Sep 17th, 2004 at 04:54 AM.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    example...i need to create labels dynamically....

    I got this variables....

    start end increment
    0900 2100 0100

    i need to create labels starting from 0900 then using 0100 increment the label to like 1000 ...1100 until 2100...

    how do i achieve that ??

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,963
    Hi,

    Come on! Carnifex has already told you how to do it. Are you saying you do not know how to amend his loop so as to place the required text in the label?

    Amend his code as follows

    VB Code:
    1. For i = 900 to 2100 Step 100
    2.     newLabel = New LinkLabel
    3.  
    4.     'Set the labels values    
    5.     With newLabel
    6.          .Name = "Label" & i.ToString
    7.          .Location = New Point(x, y)
    8.          .Size = (20, 40)
    9.          .Visible = True
    10.           if i =900 then
    11.               .Text="0900"
    12.           Else
    13.               .Text = cstr(i)
    14.           End If
    15.     End With

    For your own sake you have to experiment with these problems and then ask for help with the code you produce - if it does not work.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    eh..how do you put those labels that just created into an array or arraylist ?

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    if i manually create those labels....
    how do i add an event handler for them...
    example like click event ?

  9. #9
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    you can do an array of linklabels
    VB Code:
    1. Dim l(100) As LinkLabel
    2.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3.         Dim i As Integer
    4.         Dim y As Integer = 10
    5.         For i = 0 To 99
    6.             l(i) = New LinkLabel()
    7.             l(i).Name = "linklabel" & i.ToString
    8.             l(i).Text = l(i).Name
    9.             l(i).Location = New Point(10, y)
    10.  
    11.             AddHandler l(i).Click, AddressOf l_click
    12.             y += 21
    13.             Me.Controls.Add(l(i))
    14.         Next
    15.     End Sub
    16.  
    17.     Sub l_click(ByVal sender As Object, ByVal e As EventArgs)
    18.         MessageBox.Show(CType(sender, LinkLabel).Name)
    19.     End Sub
    something like that

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    which the linklabels i create, how do i do the click event...
    like i click the linklabel, it will change the text

  11. #11
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    this?
    VB Code:
    1. Dim l(100) As LinkLabel
    2.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3.         Dim i As Integer
    4.         Dim y As Integer = 10
    5.         For i = 0 To 99
    6.             l(i) = New LinkLabel()
    7.             l(i).Name = "linklabel" & i.ToString
    8.             l(i).Text = l(i).Name
    9.             l(i).Location = New Point(10, y)
    10.  
    11.             AddHandler l(i).Click, AddressOf l_click
    12.             y += 21
    13.             Me.Controls.Add(l(i))
    14.         Next
    15.     End Sub
    16.  
    17.     Sub l_click(ByVal sender As Object, ByVal e As EventArgs)
    18.         CType(sender, LinkLabel).Text = "change"
    19.     End Sub

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    CType(sender, LinkLabel).Text

    i dont quite understand this line...

    what you mean by converting...and putting sender inside

  13. #13
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    we are adding handler to all linklabels with the address l_click. so everytime it get's fired we are never sure who triggered the event. let's say, linklabel(0) -- the first one. so, that's the sender -- the one who send/triggered the event. so we need to know who trigered it that's why the sender thing. now ctype is just for something for conversion. we need to convert the sender to type linklabel then change the property text to something you want. i converted it because it fails with sender.text="something" on option strict on. you can still off the strict and go for sender.text="something".

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    Dim newLinkLabel() As OpenNETCF.Windows.Forms.LinkLabel
    Dim newLabel() As Windows.Forms.Label
    For i = 0 To 3 Step 1
    newLinkLabel(i) = New OpenNETCF.Windows.Forms.LinkLabel
    newLabel(i) = New Windows.Forms.Label
    With newLinkLabel(i)
    .Location = New Point(x, y)
    .Visible = True
    .Size = New Size(40, 20)
    .Show()
    .Text = "Book"
    AddHandler newLinkLabel(i).Click, AddressOf newlinklabel_click
    End With
    end try

    I got an error when running....it highlighted this part OpenNETCF.Windows.Forms.LinkLabel nullreference exception

  15. #15
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    don't know about smart device mate but still i hope this helps
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim newLinkLabel(4) As System.Windows.Forms.LinkLabel
    3.         Dim i As Integer
    4.         Dim x As Integer = 10
    5.         Dim y As Integer = 10
    6.         For i = 0 To 3 Step 1
    7.             newLinkLabel(i) = New System.Windows.Forms.LinkLabel()
    8.             With newLinkLabel(i)
    9.                 .Location = New Point(x, y)
    10.                 .Visible = True
    11.                 .Size = New Size(40, 20)
    12.                 .Show()
    13.                 .Text = "Book"
    14.                 y += 21
    15.                 AddHandler newLinkLabel(i).Click, AddressOf newlinklabel_click
    16.             End With
    17.             Me.Controls.Add(newLinkLabel(i))
    18.         Next
    19.     End Sub
    20.  
    21.     Sub newlinklabel_click(ByVal sender As Object, ByVal e As EventArgs)
    22.  
    23.     End Sub

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    sorry...i would like to ask...

    must i really put dim linklabel(4) the 4 need to be put inside...or can just leave it blank...is it necessary ?

  17. #17
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    yep for allocation of 4 elements on your array cause you're counting from 0-3

  18. #18
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,963
    Originally posted by hhh
    sorry...i would like to ask...

    must i really put dim linklabel(4) the 4 need to be put inside...or can just leave it blank...is it necessary ?

    Two slight corrections to brown monkey's excellent responses:

    You CAN use dim LinkLabel(0) and then

    ReDim newLinkLabel(4)
    or

    ReDim newLinkLabel(cdbl(TextBox1.Text))

    if you wish to choose at runtime the number of LinkLabels to be created.

    Also, Dim newLinkLabel(3) creates the required 4 elements.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  19. #19
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    oops, i totally miss that. that should do it. 3 for 0-3 not 4. i'm kinda confuse about this vb thing cause i'm used to c-like programming languages as base 0 language.

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    I got this GUI from the above codes....

    Time Court
    0900 Book
    1300 Book
    1700 Book

    Now...I want to send something over to server using the LinkLabel Click Event which is the subroutine of l_click...What I want to send is the time which is the text of the labels that I have created....

    Meaning if I click the "Book" LinkLabel besides the time 0900, it will send "0900" over to the server

    If I click the "Book" LinkLabel besides the time 1300, it will send "1300" over to the server...

    How do I achieve that...


    Sub l_click(ByVal sender As Object, ByVal e As EventArgs)
    CType(sender, LinkLabel).Text = "Booked"

    End Sub

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    yupz...anyhelp will be appreciated...

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    yupz....anyone ??

  23. #23

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    anyone can help

  24. #24
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,963
    Hi,

    I think you are not getting a response because we are not quite clear on what you want to do.

    Are you saying that you have two linklabels side by side, one with the time and the other with the text "Booked" or "Available" and that you want to click on the "Available" label to initiate sending the appropriate time to a server?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  25. #25

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    all right...
    you got it....

    Time Court
    0900 Aviable
    1300 Aviable

    Example I click on the Aviable besides the 0900...it will send 0900 over to the server....

    yah..how do i achieve that...those labels and linklabels i create dynamically...

  26. #26
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,963
    Hi,

    I'm wondering why you are using LinkLabels as I thought their purpose was to display a hyperlink.

    If you are creating your Available labels in the same loop as the LinkLabels I would add a line setting the Tag property of the Available label equal to the Text property of the LinkLabel. Then, in the appropriate event of the Available Label forward the Tag contents.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  27. #27

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    cos that linklabel that i'm using would trigger another event...and because of that event...i need to get the time for it...

    you say about the tag...

    how do you go about doing it ??

    could you add it to the codes i have above??

    cos i really do not have any idea about doing it...

    appreciated.....

  28. #28
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,963
    Hi,

    Assuming your Available labels are named lblA1 etc (with acknowledgements to brown monkey)

    VB Code:
    1. Dim newLinkLabel(12) As LinkLabel
    2.         Dim lblA(13) As Label
    3.         Dim i As Integer
    4.         Dim iText As Integer = 900
    5.         Dim x As Integer = 10
    6.         Dim y As Integer = 10
    7.         For i = 0 To 12
    8.             newLinkLabel(i) = New LinkLabel
    9.             With newLinkLabel(i)
    10.                 .Location = New Point(x, y)
    11.                 .Visible = True
    12.                 .Size = New Size(40, 20)
    13.                 .Show()
    14.                 If iText = 900 Then
    15.                     .Text = "0900"
    16.                 Else
    17.                     .Text = CStr(iText)
    18.                 End If
    19.  
    20.                 AddHandler newLinkLabel(i).Click, AddressOf newlinklabel_click
    21.  
    22.             End With
    23.             Me.Controls.Add(newLinkLabel(i))
    24.             lblA(i) = New Label
    25.             With lblA(i)
    26.                 .Location = New Point(x + 60, y)
    27.                 .Visible = True
    28.                 .Size = New Size(40, 20)
    29.                 .Text = "Book"
    30.                 .Tag = newLinkLabel(i).Text
    31.  
    32.                 AddHandler lblA(i).Click, AddressOf lblA_click
    33.             End With
    34.             Me.Controls.Add(lblA(i))
    35.             iText = iText + 100
    36.             y = y + 21
    37.         Next
    38.  
    39.  
    40.     End Sub
    41.     Sub newlinklabel_click(ByVal sender As Object, ByVal e As EventArgs)
    42.         MessageBox.Show(sender.Text)
    43.     End Sub
    44.     Sub lblA_click(ByVal sender As Object, ByVal e As EventArgs)
    45.         MessageBox.Show(sender.tag)
    46.     End Sub
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  29. #29

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    Sub newlinklabel_click(ByVal sender As Object, ByVal e As EventArgs)
    MessageBox.Show(sender.Text)
    End Sub
    Sub lblA_click(ByVal sender As Object, ByVal e As EventArgs)
    MessageBox.Show(sender.tag)
    End Sub

    what does each returns ??

    sender.Text and sender.tag....

  30. #30

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    Sub newlinklabel_click(ByVal sender As Object, ByVal e As EventArgs)
    MessageBox.Show(sender.Text)
    End Sub

    are you saying that this method....when I click on the newlinklabel lets say the "Available" besides the 1300...
    this sender.Text will return me 1300 ??

  31. #31
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,963
    Hi,

    Yes. At least it does on my machine. (Except that in the code I suggested the Available control is a label not a linklabel but you could change that sequence.)

    Have you tried it?
    Last edited by taxes; Sep 25th, 2004 at 06:39 PM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  32. #32

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    hihi....i would like to ask, if i'm using compact framework, how should i go about doing it...as .Tag() property is not under compact framework...

    do u have a way ?

  33. #33

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    yupz

  34. #34
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,963
    Originally posted by hhh
    hihi....i would like to ask, if i'm using compact framework, how should i go about doing it...as .Tag() property is not under compact framework...

    do u have a way ?
    Sorry,

    I only use VB.NET 2003.

    Could you create your own custom label and put a tag property in it?

    EDIT: Just had a thought. Are you sure the tag property is not there? Check in the design view. I say this because intellisense did not reveal the Tag option when I was writing the code but it still accepted and successfully ran that code.
    Last edited by taxes; Sep 27th, 2004 at 04:24 AM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  35. #35

    Thread Starter
    Addicted Member
    Join Date
    Jul 2004
    Posts
    235
    what is this intellisense supposed to be ??
    an ide ?

  36. #36
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,963
    Originally posted by hhh
    what is this intellisense supposed to be ??
    an ide ?
    HI,

    In VB.NET when you are typing in your code, little messages or dropdown boxes appear making suggestions for suitable coding, so that you can just click on them, so eliminating spelling mistakes etc.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width