Solved

Caption alignment in check-box added at run-time

Posted on 2000-05-16
15
161 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

830 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