Pergunta

Hey all i am currently looking for a way to calculate the width & left position of MAX 12 txtboxes on my report form. The height will always be 0.206 as well as top will always be 0.

This is what the code looks like with 12 (max) txtboxes:

txtData1.Width = 0.7
txtData1.Left = 0

txtData2.Width = 0.7
txtData2.Left = 0.708

txtData3.Width = 0.7
txtData3.Left = 1.416

txtData4.Width = 0.7
txtData4.Left = 2.124

txtData5.Width = 0.7
txtData5.Left = 2.832

txtData6.Width = 0.7
txtData6.Left = 3.54

txtData7.Width = 0.7
txtData7.Left = 4.248

txtData8.Width = 0.7
txtData8.Left = 4.956

txtData9.Width = 0.7
txtData9.Left = 5.664

txtData10.Width = 0.7
txtData10.Left = 6.372

txtData11.Width = 0.7
txtData11.Left = 7.08

txtData12.Width = 0.7
txtData12.Left = 7.788

According to my calculations (which i love math...math just doesn't love me :o)) the total width would be 8.4 in and the total left would be 7.788 in. The sheet is 8.5 in wide (landscape view).

layout

So now the hard part comes into play. For 11 boxes, the width would go up a little and the left position would also go up to accommodation the extra space not having the 12th box anymore.

I am trying to find a nice way of doing this with minimal code since i know i can do the same as above for each level (12 to 2 textboxes) but that would be a lot of code.

So any help with calculating the remaining 11-2 txtboxes would be a big help! :o)

Foi útil?

Solução

I'm not sure I completely understand your question, but what I am gathering is that you always want the textboxes to completely fill up the 8.5 inches.

If that is the case, I would do something as follows:

    Dim NumberOfBoxes As Integer = 11 ' Number of textboxes you'll have next to each other
    Dim AssignedWidthPerBox As Double = 8.5 / NumberOfBoxes
    Dim CurrentLeft As Double = 0   ' How Far left you are on your form - Increment this by AssignedWidthPerBox for each textbox

Then you assign the Textbox properties eaither through a loop (preferred) or by hand as follows:

    txtData1.Width = AssignedWidthPerBox
    txtData1.Left = CurrentLeft
    CurrentLeft += AssignedWidthPerBox

Hope this helps

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top