-
Sep 17th, 2004, 03:33 AM
#1
Thread Starter
Addicted Member
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.
-
Sep 17th, 2004, 03:54 AM
#2
Retired VBF Adm1nistrator
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Sep 17th, 2004, 03:58 AM
#3
Thread Starter
Addicted Member
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....
-
Sep 17th, 2004, 04:48 AM
#4
Addicted Member
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:
'Somewhere in the form as a private member
Private m_Labels() As LinkLabels
Dim i As Integer
'X and Y co-ordinate position of the current label
Dim x As Integer = 8
Dim y As Integer = 8
Dim labels(MAXLABELS - 1) As LinkLabels
Dim newLabel As LinkLabel
'Iterate thru as many labels as you want
For i = 0 to MAXLABELS - 1
newLabel = New LinkLabel
'Set the labels values
With newLabel
.Name = "Label" & i.ToString
.Location = New Point(x, y)
.Size = (20, 40)
.Visible = True
.Text = "Whatever"
End With
'Add the label to the groupbox
grpLabels.Controls.Add(newLabel)
'Assign the label to the private array if you want to keep track of it
labels(i) = newLabel
'Increment the location co-ordinates for the next label
'(Modify this to suit your form)
x = x + 48
Next
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.
-
Sep 21st, 2004, 05:17 AM
#5
Thread Starter
Addicted Member
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 ??
-
Sep 21st, 2004, 02:56 PM
#6
PowerPoster
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:
For i = 900 to 2100 Step 100
newLabel = New LinkLabel
'Set the labels values
With newLabel
.Name = "Label" & i.ToString
.Location = New Point(x, y)
.Size = (20, 40)
.Visible = True
if i =900 then
.Text="0900"
Else
.Text = cstr(i)
End If
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.
-
Sep 21st, 2004, 11:51 PM
#7
Thread Starter
Addicted Member
eh..how do you put those labels that just created into an array or arraylist ?
-
Sep 22nd, 2004, 03:41 AM
#8
Thread Starter
Addicted Member
if i manually create those labels....
how do i add an event handler for them...
example like click event ?
-
Sep 22nd, 2004, 03:50 AM
#9
Fanatic Member
you can do an array of linklabels
VB Code:
Dim l(100) As LinkLabel
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
Dim y As Integer = 10
For i = 0 To 99
l(i) = New LinkLabel()
l(i).Name = "linklabel" & i.ToString
l(i).Text = l(i).Name
l(i).Location = New Point(10, y)
AddHandler l(i).Click, AddressOf l_click
y += 21
Me.Controls.Add(l(i))
Next
End Sub
Sub l_click(ByVal sender As Object, ByVal e As EventArgs)
MessageBox.Show(CType(sender, LinkLabel).Name)
End Sub
something like that
-
Sep 22nd, 2004, 04:00 AM
#10
Thread Starter
Addicted Member
which the linklabels i create, how do i do the click event...
like i click the linklabel, it will change the text
-
Sep 22nd, 2004, 04:02 AM
#11
Fanatic Member
this?
VB Code:
Dim l(100) As LinkLabel
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
Dim y As Integer = 10
For i = 0 To 99
l(i) = New LinkLabel()
l(i).Name = "linklabel" & i.ToString
l(i).Text = l(i).Name
l(i).Location = New Point(10, y)
AddHandler l(i).Click, AddressOf l_click
y += 21
Me.Controls.Add(l(i))
Next
End Sub
Sub l_click(ByVal sender As Object, ByVal e As EventArgs)
CType(sender, LinkLabel).Text = "change"
End Sub
-
Sep 22nd, 2004, 04:11 AM
#12
Thread Starter
Addicted Member
CType(sender, LinkLabel).Text
i dont quite understand this line...
what you mean by converting...and putting sender inside
-
Sep 22nd, 2004, 04:16 AM
#13
Fanatic Member
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".
-
Sep 22nd, 2004, 04:38 AM
#14
Thread Starter
Addicted Member
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
-
Sep 22nd, 2004, 04:44 AM
#15
Fanatic Member
don't know about smart device mate but still i hope this helps
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim newLinkLabel(4) As System.Windows.Forms.LinkLabel
Dim i As Integer
Dim x As Integer = 10
Dim y As Integer = 10
For i = 0 To 3 Step 1
newLinkLabel(i) = New System.Windows.Forms.LinkLabel()
With newLinkLabel(i)
.Location = New Point(x, y)
.Visible = True
.Size = New Size(40, 20)
.Show()
.Text = "Book"
y += 21
AddHandler newLinkLabel(i).Click, AddressOf newlinklabel_click
End With
Me.Controls.Add(newLinkLabel(i))
Next
End Sub
Sub newlinklabel_click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
-
Sep 22nd, 2004, 04:46 AM
#16
Thread Starter
Addicted Member
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 ?
-
Sep 22nd, 2004, 04:48 AM
#17
Fanatic Member
yep for allocation of 4 elements on your array cause you're counting from 0-3
-
Sep 22nd, 2004, 10:22 AM
#18
PowerPoster
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.
-
Sep 22nd, 2004, 07:58 PM
#19
Fanatic Member
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.
-
Sep 23rd, 2004, 09:34 AM
#20
Thread Starter
Addicted Member
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
-
Sep 23rd, 2004, 08:27 PM
#21
Thread Starter
Addicted Member
yupz...anyhelp will be appreciated...
-
Sep 23rd, 2004, 09:25 PM
#22
Thread Starter
Addicted Member
-
Sep 24th, 2004, 03:18 AM
#23
Thread Starter
Addicted Member
-
Sep 24th, 2004, 08:26 AM
#24
PowerPoster
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.
-
Sep 24th, 2004, 10:40 AM
#25
Thread Starter
Addicted Member
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...
-
Sep 24th, 2004, 11:13 AM
#26
PowerPoster
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.
-
Sep 24th, 2004, 11:17 AM
#27
Thread Starter
Addicted Member
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.....
-
Sep 24th, 2004, 01:05 PM
#28
PowerPoster
Hi,
Assuming your Available labels are named lblA1 etc (with acknowledgements to brown monkey)
VB Code:
Dim newLinkLabel(12) As LinkLabel
Dim lblA(13) As Label
Dim i As Integer
Dim iText As Integer = 900
Dim x As Integer = 10
Dim y As Integer = 10
For i = 0 To 12
newLinkLabel(i) = New LinkLabel
With newLinkLabel(i)
.Location = New Point(x, y)
.Visible = True
.Size = New Size(40, 20)
.Show()
If iText = 900 Then
.Text = "0900"
Else
.Text = CStr(iText)
End If
AddHandler newLinkLabel(i).Click, AddressOf newlinklabel_click
End With
Me.Controls.Add(newLinkLabel(i))
lblA(i) = New Label
With lblA(i)
.Location = New Point(x + 60, y)
.Visible = True
.Size = New Size(40, 20)
.Text = "Book"
.Tag = newLinkLabel(i).Text
AddHandler lblA(i).Click, AddressOf lblA_click
End With
Me.Controls.Add(lblA(i))
iText = iText + 100
y = y + 21
Next
End Sub
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
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.
-
Sep 24th, 2004, 09:17 PM
#29
Thread Starter
Addicted Member
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....
-
Sep 24th, 2004, 09:22 PM
#30
Thread Starter
Addicted Member
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 ??
-
Sep 25th, 2004, 09:21 AM
#31
PowerPoster
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.
-
Sep 26th, 2004, 08:26 PM
#32
Thread Starter
Addicted Member
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 ?
-
Sep 27th, 2004, 03:11 AM
#33
Thread Starter
Addicted Member
-
Sep 27th, 2004, 04:21 AM
#34
PowerPoster
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.
-
Sep 27th, 2004, 08:20 AM
#35
Thread Starter
Addicted Member
what is this intellisense supposed to be ??
an ide ?
-
Sep 27th, 2004, 09:00 AM
#36
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|