Array of Text Boxes

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
Fawsley
Posts: 2
Joined: Monday 15th November 2021 2:13pm

Array of Text Boxes

Post by Fawsley » Monday 15th November 2021 4:35pm

Hello,
I have just started with Gambas3 and decided to write a Suduko program as a way of learning the language. I have some questions about how the design the GUI:

I need an array of 9x9 textboxes to capture the users input. I have found a example of how to create such an array within a program but I can't see how to set the edits. If I add the 81 boxes to the form at the design stage I can use the group property to capture the keypress event to ensure the user can only input single numbers between 1 and 9. Is there a way of adding a group property if they are created by the program?

Also the keypress event is good at ensuring only 1 - 9 gets input but I also need it to respond to tab, del, and up and down arrow input. Not sure how to do this?

Finally, (sorry for all the questions) what is the best way of adding lines to the form to surround and go between the text boxes?

Many thanks for suggestions

User avatar
cogier
Site Admin
Posts: 825
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Array of Text Boxes

Post by cogier » Monday 15th November 2021 5:49pm

Welcome to the forum!
1/. There is a Sudoku program on the Gambas Farm (Tools>Software Farm) that could give you some ideas.
Image

2/. I have started a similar program myself. I have attached it for you to look at but, it is not finished! The GUI is quite nice when resizing the Form.
Sudoku-0.0.5.tar.gz
(15.17 KiB) Downloaded 42 times
If I add the 81 boxes to the form at the design stage I can use the group property to capture the keypress event to ensure the user can only input single numbers between 1 and 9. Is there a way of adding a group property if they are created by the program?
If you are adding the 'Boxes' in the IDE then you can modify the 'Group' property there. If you want to create the 'Boxes' in code here is an example (you will need to add a loop to add more than 1).
Public Sub Form_Open()

  Dim MyTextBox As TextBox

  With MyTextBox = New TextBox(Me) As "AllMyTextBoxes"
    .Height = 28
    .Width = 28
    .Text = "6"
  End With

End

Public Sub AllMyTextBoxes_Change()

  'Do stuff

End
The TextBox will be put on the Form (Me) and the Sub AllMyTextBoxes_Change() will capture any change made. Have a look at line 64 of FMain in my program.
This would also be a good place to check that only one number has been input, have a look at the Sub AllTBs_Change() at line 150 of FMain.
Finally, (sorry for all the questions) what is the best way of adding lines to the form to surround and go between the text boxes?
There is a Seporator in the ToolBox but, I tend to use a Panel and change the background to Black. This way you can make it as thick, or thin, as you wish.

I hope this helps. I hope you enjoy your time with Gambas.

Fawsley
Posts: 2
Joined: Monday 15th November 2021 2:13pm

Re: Array of Text Boxes

Post by Fawsley » Tuesday 16th November 2021 1:30pm

Many Thanks
This has got me going again!

crevilla
Posts: 4
Joined: Thursday 30th December 2021 10:22pm

Re: Array of Text Boxes

Post by crevilla » Friday 07th January 2022 9:22pm

My little commentary here.

You can use the "tag" property of each textbox to know which one is being edited. That way you have one group but the "tag" can help you decide which textbox was active.

Cheers,
CR
Dies ist kein Unterschrift.
Image

Post Reply