Solved

Caption alignment in check-box added at run-time

Posted on 2000-05-16
15
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month6 days, 2 hours left to enroll

626 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