 |
| Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 28th, 2003, 05:37 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Label array
Hello everyone
I am trying to build a calendar from labels.
I have a label array with 42 labels. First thing
I need to know is how do I check each label to see
if its caption = "", if it = "" then backcolor = vbGray
else backcolor = vbWhite.
Second thing is when the mouse is over one of the labels
I want the labels backcolor to = vbBlue but when the mouse is moved from that label, I want the labels backcolor to change back to what it was prior to the mousemove.
Can anyone give me some pointers?
Thanks
Rick
|
|

August 28th, 2003, 06:14 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You can loop through all the labels in the label array and change their back colour to the desired value thus:
Code:
Dim n as Integer
For n = LabelArray.LBound To LabelArray.UBound
If LabelArray(n).Caption = "" Then
LabelArray(n).BackColor = vbGray
Else
LabelArray(n).BackColor = vbWhite
End If
Next
Changing the back colour of the labels as the mouse moves over them is a little more complicated, however the principle is similar. Try this code:
Code:
Private Sub LabelArray_MouseMove(Index As Integer, _
Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
Dim n As Integer
'Loop through all the labels in the control array
For n = LabelArray.LBound To LabelArray.UBound
'If the index of the control array the mouse is
'over is equal to n and the labels caption is not
'nothing then change it's back colour to blue
If Index = n And LabelArray(n).Caption <> "" Then
LabelArray(n).BackColor = vbBlue
'Otherwise if the caption is not nothing then
'change it's back colour to white
ElseIf Index <> n And LabelArray(n).Caption <> "" Then
LabelArray(n).BackColor = vbWhite
End If
Next
End Sub
Private Sub Form_MouseMove(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
Dim n As Integer
'When the mouse is not over one of the labels the
'form will get the mouse move event, in this case
'loop through all the labels in the control array
'and change the back colour of all of the ones
'with a caption to white
For n = LabelArray.LBound To LabelArray.UBound
If LabelArray(n).Caption <> "" Then
LabelArray(n).BackColor = vbWhite
End If
Next
End Sub
There are much more efficient ways of doing this but at least it gives you a start. You could for example store the index of the label that the mouse is over, and only change the back colours if the index changes.
Regards
Owain Williams
|
|

August 28th, 2003, 11:36 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Owain
So far this seems to be what I am working towards.
You said about storing the index that the mouse was over.
I think this is what I need but in a bit different fashion.
What I need is when the mouse is over a label, there needs to be about a 2 second pause, then do the change (so I have time to move from the labels (which are arranged in a frame) and keep that index until I move the mouse over another label. Again this is for a calendar so maybe I am not taking the right approach. If need be I can paste the form text in a reply so someone could see what I am talking about. There are a few other things I need for this also but this is a work in progress.
Thanks again
Rick
|
|

August 29th, 2003, 05:10 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
For a 2 second pause add a timer control with an interval of 2000 and Enabled = False. Then add a form wide variable (Integer). When the label receives the mouse move compare the index to the form wide variable, if they are different then disable, then re-enable the timer. Move the code (with a couple of modifications) in the label's MouseMove event to the timers Timer event.
Why do you want a 2 second pause anyway? Why do you need "time to move from the labels?"
Regards
Owain Williams
|
|

August 29th, 2003, 08:31 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Let me explain how this thing is goint to hopefully work.
This is being designed as somewhat of a scheduler system for a garage. We will schedule jobs from day to day and we need a way to record each job by the date.
When I click on a label from the LabelArray with lets say tomorrow's date, I will have a form open with 2 text boxes, first box is for a discription of the job and the second holds the date that was selected from the labelArray click. (we save the 2 text box values in either a database or a file (which ever). We repeat this lets say 5 more times with different dates and job discriptions. Now we want to see if there are any jobs for a specific day so we move the mouse over a label and we fill a list view with the files or recordsets corresponding to the date the mouse is over, if we find the one we are looking for we go down and select it from the list view. OK, with that said, if we do not have a pause when we move the mouse then if we are on a lable, to get to the list view we move the mouse across another label causing the mouse move event again and the list view will change. Using the pause will give us enough time to leave the labelArray area and move to the list view.
Does this help any?
Rick
|
|

August 29th, 2003, 08:47 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How about this for a simpler implementation...
Use the Microsoft Calendar control, and have a single click fill the list view, and a double click bring up the message box.
This seems to me to be much easier to code, and maintain.
... Just a thought.
John R Lick
[email protected]
|
|

August 29th, 2003, 05:22 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
John is right, unless you can spend 90% of your time designing a more appropiate user interface (and maybe that is the case, because this will end up as a custom program) Instead of an array of labels, I would use a flex grid (yes, I love it) with a small change in your design: when you load the grid with this month dates, check for each date if there is a scheduled job, and in the case change the back color of the cell (or any other change, like fore color or added a number in parenthesis with the number of jobs, or add an icon etc). In this way the user will have an immediate feedback about which dates are full/empty. Then you can click on a cell and display the scheduled jobs for that date.
Just another thought. There are plenty of alternatives, depending on how much time you want to spend on the project, and how much in the user interface against the logic.
Marco
Quote:
quote:Originally posted by jlick
How about this for a simpler implementation...
Use the Microsoft Calendar control, and have a single click fill the list view, and a double click bring up the message box.
This seems to me to be much easier to code, and maintain.
... Just a thought.
John R Lick
[email protected]
|
|
|

August 29th, 2003, 06:36 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorry I didn't respond sooner, the garage gets crazy on Friday and I am
having trouble referencing the ms calendar 10.0.
I can't seem to get it added to the tool bar. Sorry John, I was going to try
my hand at it. maybe another time when I dump
this freaken machine and chase down the error. Marco, what would this grid
look like when implemented? I really had my heart set on the way I was going
but you guys are the pro's, i am just a grease monkey playing a programmer.
I am use to using labels, textboxes and list views. When I think of tree
views and flex grids, I cringe because I know nothing about them.
I just now learned about the Monthview.HitTest on the Monthview_mouseMove.
|
|
 |