locked
I need help please RRS feed

  • Question

  • Hello, I'm trying to do multiplication tables and now I got a problem. I made one Formu1 and on this I have 100 Formi1 Buttons now I am interested in one that we each Buttons especially print result formu2 textbox1 which has just ...
    • Edited by Z llata R Tuesday, March 19, 2013 6:51 PM
    Tuesday, March 19, 2013 3:19 PM

Answers

  • If you added 100 controls using the form designer, then you still have extra work to do.

    You probably want to start with an integer and get at the corresponding control.  To do this, you might iterate over all the controls in the form and compare all their "Name" fields to whatever you named them.  (Presumably you named them like { button1, button2, button... } or { textBox1, textBox2, textBox... })

    Here's one approach to getting them, assuming you've named them with some logical naming scheme.

    Use the overload of the ControlCollection indexer that takes a string.  The string indexer is the Name field of the button, which you can set in the designer to be something logical.

    int index = 2;
    Button button = Controls["button" + index.ToString()] as Button;
    

    This looks for a button called "button2" and finds it by name.  You can change the value of index before searching for it.  If button turns out to be null, then there was no such control with that name, or it wasn't a Button control.

    If you had a two-dimensional grid of buttons, you could rename each one in the designer and use a naming scheme of something like "button_13_7" and search for it by column and row indices.

    string nameToSearchFor = string.format( "button_{0}_{1}", column, row )


    • Marked as answer by Z llata R Wednesday, March 20, 2013 2:37 PM
    Tuesday, March 19, 2013 3:43 PM
  • If you added 100 controls using the form designer, then you still have extra work to do.

    You probably want to start with an integer and get at the corresponding control.  To do this, you might iterate over all the controls in the form and compare all their "Name" fields to whatever you named them.  (Presumably you named them like { button1, button2, button... } or { textBox1, textBox2, textBox... })

    Here's one approach to getting them, assuming you've named them with some logical naming scheme.

    Use the overload of the ControlCollection indexer that takes a string.  The string indexer is the Name field of the button, which you can set in the designer to be something logical.

    int index = 2;
    Button button = Controls["button" + index.ToString()] as Button;

    This looks for a button called "button2" and finds it by name.  You can change the value of index before searching for it.  If button turns out to be null, then there was no such control with that name, or it wasn't a Button control.

    If you had a two-dimensional grid of buttons, you could rename each one in the designer and use a naming scheme of something like "button_13_7" and search for it by column and row indices.

    string nameToSearchFor = string.format( "button_{0}_{1}", column, row )


    So that will not work ...

    and whether it is possible to do it like how I imagined it ... Here are pictures that I plan to do .... is it possible and how?

    • Marked as answer by Z llata R Wednesday, March 20, 2013 2:36 PM
    Tuesday, March 19, 2013 4:22 PM

All replies

  • If you added 100 controls using the form designer, then you still have extra work to do.

    You probably want to start with an integer and get at the corresponding control.  To do this, you might iterate over all the controls in the form and compare all their "Name" fields to whatever you named them.  (Presumably you named them like { button1, button2, button... } or { textBox1, textBox2, textBox... })

    Here's one approach to getting them, assuming you've named them with some logical naming scheme.

    Use the overload of the ControlCollection indexer that takes a string.  The string indexer is the Name field of the button, which you can set in the designer to be something logical.

    int index = 2;
    Button button = Controls["button" + index.ToString()] as Button;
    

    This looks for a button called "button2" and finds it by name.  You can change the value of index before searching for it.  If button turns out to be null, then there was no such control with that name, or it wasn't a Button control.

    If you had a two-dimensional grid of buttons, you could rename each one in the designer and use a naming scheme of something like "button_13_7" and search for it by column and row indices.

    string nameToSearchFor = string.format( "button_{0}_{1}", column, row )


    • Marked as answer by Z llata R Wednesday, March 20, 2013 2:37 PM
    Tuesday, March 19, 2013 3:43 PM
  • If you added 100 controls using the form designer, then you still have extra work to do.

    You probably want to start with an integer and get at the corresponding control.  To do this, you might iterate over all the controls in the form and compare all their "Name" fields to whatever you named them.  (Presumably you named them like { button1, button2, button... } or { textBox1, textBox2, textBox... })

    Here's one approach to getting them, assuming you've named them with some logical naming scheme.

    Use the overload of the ControlCollection indexer that takes a string.  The string indexer is the Name field of the button, which you can set in the designer to be something logical.

    int index = 2;
    Button button = Controls["button" + index.ToString()] as Button;

    This looks for a button called "button2" and finds it by name.  You can change the value of index before searching for it.  If button turns out to be null, then there was no such control with that name, or it wasn't a Button control.

    If you had a two-dimensional grid of buttons, you could rename each one in the designer and use a naming scheme of something like "button_13_7" and search for it by column and row indices.

    string nameToSearchFor = string.format( "button_{0}_{1}", column, row )


    So that will not work ...

    and whether it is possible to do it like how I imagined it ... Here are pictures that I plan to do .... is it possible and how?

    • Marked as answer by Z llata R Wednesday, March 20, 2013 2:36 PM
    Tuesday, March 19, 2013 4:22 PM
  • So that will not work ...

    Why don't you think that will work?  Is it just because I described the technique in C# and you're using VB or is there some reason you won't do it that way?

    Would you rather create the buttons programmatically?  You can still create them with a name of the format that I described.

    I don't understand why you think that won't work.

    Tuesday, March 19, 2013 10:36 PM
  • Try this sample on our website

    http://www.vb-tips.com/DynamicControl.aspx

     It does the same as you show.


    Success
    Cor

    Wednesday, March 20, 2013 7:09 AM
  • So that will not work ...

    Why don't you think that will work?  Is it just because I described the technique in C# and you're using VB or is there some reason you won't do it that way?

    Would you rather create the buttons programmatically?  You can still create them with a name of the format that I described.

    I don't understand why you think that won't work.

    hi Wyck! I finished what I have asked for in this way, and now works

    This is Form1

    Public Class Tablica_Dijeljenja

        Private Sub Tablica_Dijeljenja_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        End Sub

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Tm1.Rezultat("1")
            Tm1.Show()
        End Sub

    This is Form2

    Public Class Tm1

        Dim rez As String

        Public Sub Rezultat(rezultat As String)
            rez = rezultat

        End Sub

        Private Sub Tm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load



            TimerTm1.Enabled = True
            TimerTm1.Interval = 3000
            TimerTm1.Start()


            TextBox1.Text = rez
            TextBox1.Select(0, 0)

        End Sub

        Private Sub TimerTm1_Tick(sender As Object, e As EventArgs) Handles TimerTm1.Tick

            Me.Close()
            TimerTm1.Stop()
            TimerTm1.Enabled = False

        End Sub

        Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

        End Sub
    End Class

    Wednesday, March 20, 2013 2:36 PM
  • I think you should make themin group...

    so suppose you have 7 group and each have 10 controls then...#

    or possible use fieldset/Fram/div/repeater/grid for group...

    div_1_button_1

    div_1_textbox_1

    div_1_Label_1

    div_1_dropdown_1..

    -use loop for group/parent control..

    -check for control type..

    -do action..


    alpa

    Wednesday, March 20, 2013 5:01 PM