Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Caption alignment in check-box added at run-time

Posted on 2000-05-16
15
Medium Priority
?
166 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code 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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

916 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