Solved

Caption alignment in check-box added at run-time

Posted on 2000-05-16
15
159 Views
Last Modified: 2010-05-02
VB6 sp3

Here's my form load code:

Private Sub Form_Load()
    Dim RecNo As Integer
    Dim CBName As String, CBCaption As String
    With DE.rsImportProviders
        .Open
        RecNo = 0
        .MoveFirst
        While Not .EOF
            RecNo = RecNo + 1
            CBName = "CB" + Trim(Str(RecNo))
            CBCaption = .Fields(1)
            frmIVUpdate.Controls.Add "VB.CheckBox", CBName, frProviders
            With frmIVUpdate.Controls(CBName)
                .Caption = CBCaption
                .Visible = True
                .Height = 200
                .Left = 120
                .Top = 110 + (RecNo * 250)
                .Width = 2000
            End With
            .MoveNext
        Wend
        .Close
    End With
End Sub

DE is a DataEnvironment
rsImportProviders is the recordset returned by the command ImportProviders
I am trying to add checkboxes into the Frame, frProviders.

Why is it that the checkbox's caption is not aligning (vertically) correctly with the checkbox itself? As the code stands, the caption is at least half a character height above where it should be and so the top of all the letters are being cut off.
0
Comment
Question by:sduckett
  • 7
  • 4
  • 4
15 Comments
 
LVL 9

Expert Comment

by:Ruchi
ID: 2814884
Try changing

..Top = 110 + (RecNo * 250)
..Width = 2000
to

..Top = 0 + (RecNo * 250)
..Width = 1000
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2814923
Or, you can do that by using the following code.

 .Top = 0 + (RecNo * 250)
 .Width = Me.TextWidth(CBCaption) + 300

Use TextWidth method to return the width of that CBCaption.
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2814943
Dim ochknew As CheckBox
 
Set ochknew = Controls.Add("VB.CheckBox", "ochknew", frProviders)
With ochknew
 .Caption = CBCaption
 .Visible = True
 .Height = 200
 .Left = 120
 .Top = 0 + (RecNo * 250)
 .Width = Me.TextWidth(CBCaption) + 300
End With

If this is to create an instance of an object, ochknew, is to use the Set command, it will provide you the Auto List Member. When you type the dot after the name of that checkbox, you can start typing the name of the property or method you want to access.

Hope this helps you.
0
 
LVL 3

Author Comment

by:sduckett
ID: 2816240
Ruchi,
Thanks for your comments but it is not the width of the control that is the problem.
It is where the caption appears in relation to the check-box; they are not lined up. It is if the caption sits on the horizontal centre-line of the check-box itself.
I want the height of the control to be 200 because this allows a nice spacing of 250.
With a height of 200, the text is cut in half and you can only see the bottom half of each letter. Experimenting, I changed the height to 400. This allowed me to see all of the caption but it was still out of alignment.
Do I have buggy controls?
0
 
LVL 3

Author Comment

by:sduckett
ID: 2816284
Adjusted points from 200 to 300
0
 
LVL 3

Author Comment

by:sduckett
ID: 2816332
I seem to have homed in on the problem a little.

The problem seems to be to do with the line:

     CBCaption = .Fields(1)

If I change this to:

     CBCaption = "Test"

or even

     CBCaption = .Fields(1).Name

the alignment is correct (but the caption is useless).

     CBCaption = .Fields(1).Value

doesn't help.

Does anybody know how to correct this?


0
 
LVL 13

Expert Comment

by:crazyman
ID: 2816453
what is .Fields(1).Value equal too?

0
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.

 
LVL 3

Author Comment

by:sduckett
ID: 2816480
crazyman:
'.Fields(1).Value' is the name of an import provider (Char field, retrieved from a SQL 7.0 database)
0
 
LVL 3

Author Comment

by:sduckett
ID: 2816526
I now have a more desirable solution using an extended list-box to present my users with a list from which to select.
I find this problem very strange though and I am going to leave it open for anybody who can reproduce the problem and provide a solution/explanation.
0
 
LVL 13

Accepted Solution

by:
crazyman earned 300 total points
ID: 2816868
Could it be you need to trim spaces off the end because if you input say
"this is a test" as the caption and it fits okay if you put "this is a test             " it will cause the caption to wrap and if the checkbox isnt big enough it will apear as if the top is chopped off and not aligned correctly.
0
 
LVL 13

Expert Comment

by:crazyman
ID: 2816871
In other words ensure all spaces are trimmed off the end then see.
0
 
LVL 3

Author Comment

by:sduckett
ID: 2817126
Clever guy,
Easy when you know how, Thanks.
0
 
LVL 3

Author Comment

by:sduckett
ID: 2817177
Ruchi:
Sorry I dismissed your answer.
After I accepted crazyman's answer and in the light of what his answer demonstrated to me, I realised that yours was a valid answer. I'm sorry I didn't try it out.
There is a new question for you in this forum.
0
 
LVL 13

Expert Comment

by:crazyman
ID: 2817540
Thanks for the points,glad i could help.
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2827159
Sduckett, I could not reply earlier because I had plans. Anyways, I am glad that Crazyman helped you more... :-)
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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

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