FalconDEW Posted November 30, 2003 Posted November 30, 2003 I have a single form program and I would like to control text boxes on the form via a class. How can I create a proper reference to the form from the class? Thanks! -Falcon Quote
Leaders Iceplug Posted November 30, 2003 Leaders Posted November 30, 2003 Pass the form reference to the class's constructor. If the class is coming first, then you can create the form from the class. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Administrators PlausiblyDamp Posted November 30, 2003 Administrators Posted November 30, 2003 Easiest way is give the class a Sub New that accepts the form as a parameter. public class Test private frm as Form1 sub new (f as Form1) frm = f end sub public sub Something () 'You could now refer to the form via the variable frm frm.Text = "Hello" end sub from within form1 you could then do dim c as new class1(me) c.something() Is there any reason you need to control the textboxes from a class? Could the code not be part of the form? Could the class not simply return data from it's functions that methods in the form use to update the textboxes? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
FalconDEW Posted November 30, 2003 Author Posted November 30, 2003 That worked great! Thanks guys - that did the trick. I appreciate the code example too! Now I understand how this works. PlausiblyDamp - in response to your questions... my main form class has become massive with about 60+ subs/functions - and I'm not even close to finishing. I have already grouped most of the code into regions so I can close them off - but I wanted to use classes for the sake of breaking out my code more. Will I suffer any type of performance loss by doing this? I guess my background in C++ is making me feel like I need to write classes for everthing... haha. -Falcon Quote
Moderators Robby Posted November 30, 2003 Moderators Posted November 30, 2003 Instead of simply Encapsulating your code, why not divide your project into let's say Data Layer, Business Logic and UI. The data layer can handle all of your data access without any knowledge of the other classes, the business logic can inherit or instantiate from the data layer and so on. Quote Visit...Bassic Software
FalconDEW Posted November 30, 2003 Author Posted November 30, 2003 Not sure... I'm not sure I understand how you would implement the data layer, etc that you recommended. Can you elaborate on what you use to create these... e.g. forms, classes, modules, etc? -Falcon Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.