Solved

Caption alignment in check-box added at run-time

Posted on 2000-05-16
15
158 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

743 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

16 Experts available now in Live!

Get 1:1 Help Now