Results 1 to 8 of 8

Thread: Reinitializing forms

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Posts
    4

    Smile Reinitializing forms

    Hello,
    I'm rather new to VB.net so I'm wondering how to reinitialize form (or to reset them)?
    I hava program that does something, I want to be able to reset it on button click (or something).
    Any help appreciated

    Thanx
    Krvolok

  2. #2
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Can you refresh the form instead? You can do myForm.Refresh().

    Or to re-instantiate you can do:

    frmForm = New frmForm(....)

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Posts
    4
    Thanx,

    Refresh is what I had in mind.
    When I try to do somethng like 'Form1.Refresh()' from Public Sub I do receive an error message: "Reference to a non-shared member requires an object reference"

    Any idea how to avoid this?

    Krvolok

  4. #4
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Are you using Shared methods?

    You have to first instantiate the form (using the "New" keyword) before you can refresh it.

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Posts
    4
    Thanx, I've made a new instance and it works (kinda). Also, myform.Show() does the job but it pops another form on the screen.
    Here is what I want exactly:
    I have a form with buttons, check boxes, text boxes, etc...
    They all get some values as the program runs. Now I want to reset all list boxes, check boxes etc.. on a button click.
    I've done that manualy for each element on the form.
    Is there a way to reset them all to their beginning state?

    Krvolok

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    You can loop through all controls on the form to have them set to your default values . You have to use For ...Next and TypeOf keywords in this case .

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Posts
    4
    Hmm..
    I've tried this:
    For i = i to Me.Controls.Count
    If TypeOf Me.Controls(i) is CheckBox then
    Controls(i).???
    Next

    How can I change properties of number 'i' control?
    In this case something like Controls(i).checked = false

    Krvolok

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Create three or more textboxes then paste this code in command to reset all these textboxes :

    VB Code:
    1. Dim ctrl As Control
    2.         Dim txtbox As Control
    3.  
    4.  
    5.         For Each txtbox In Me.Controls
    6.             If TypeOf txtbox Is TextBox Then
    7.                 txtbox.Text = ""
    8.             End If
    9.         Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width