Results 1 to 6 of 6

Thread: Using Class Function to control a Window Form ?

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2003
    Posts
    4

    Question Using Class Function to control a Window Form ?

    I have a problem , which I need to write out a function which is to enabled and disabled button for a form.How can I do it ?

    my class function will recevied an Action and the FormName, then base on the Action and FormName, I will enabled and disabled button for that form.

    Example :

    Form1 :

    This form got 7 button :
    Button1,Button2,Button3,Button4,Button5,Button6,Button7

    When Button1 onclick , I will call the class function to enabled Button2,Button3,Button4
    and disabled Button5,Button6,Button7.

    I want to do like this, because I got 200 form , and If I not do like this , each form I also need to put in the same code to control to button.
    If I got this class function , I just call the function , then everthing will be done.

    Anyone can help me ?
    Thank you ~~~

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    It would be much easier if you passed a reference to an actual form instead of its name, but even better you should just use inheritance. Make one master form with this ability then inherit all other forms from it. This is especially useful if you have to change something later.

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2003
    Posts
    4
    thank for your reply.
    Can you give me example for more clear ?
    Sorry I still new in VB.Net.

    If I want to use this class of function for other program , Isn't I also doing the same way?
    Why not I create a class function , If I got any changing on the class function , I just replace the file , no need to changing on the program rite ?

    Got any diffrent with the method that you suggest and the method i using now ?

    Or for more clear , I want this class not only use for 1 proram. For the future or other that this program , I still can use it.
    Please help to solve this problem.
    Thank you ~~
    Last edited by fukali; May 22nd, 2003 at 11:28 PM.

  4. #4
    New Member
    Join Date
    Apr 2003
    Location
    Nottingham
    Posts
    14
    I think Ednnesis is suggesting something like this :

    Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Button2.Enabled = True
    Button3.Enabled = True
    Button4.Enabled = True
    Button5.Enabled = True
    Button6.Enabled = True
    Button7.Enabled = True

    End Sub
    End Class

    Public Class Form2
    Inherits MyApplication.Form1

    'Do specific stuff in this form...

    End Class

    Public Class Form3
    Inherits MyApplication.Form1

    'Do specific stuff in this form...

    End Class

    Now every time you click on Button1 in Form2 or Form3 it will enable the other buttons on the form.

    Hope this helps.

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Thats correct or use visual inheritance, but I don't have any specifics for you, try it and see how far you get or search the help.

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2003
    Posts
    4
    thanks for Edneeis and Jaycee.
    I get what your mean already.

    But here I got another problem. Which is when I apply this method , I will face some problem which I need to modified the class function, i need to recompile again the program and resend again the program to the client.

    While when I create out the public class function (dll), I just need to replace this file enough at all right ?
    And at the same time I also easy to apply the same class function to other program, right?

    Isn't this method more applicable ?

    Actually I not very familiar with vb.net, so I need advise or any suggestion from you all.
    Thank you.. Hope to get your reply soon ~~ !!!

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