|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Friend WithEventsHi,
What does it mean when VS automatically adds a line like this to code of my form: Friend WithEvents Label1 As System.Windows.Forms.Label Also, I noticed a modifier property for each control and the default is Friend. When modifier is set to Friend, I can access the control from anywhere with the application, while if it is set to private it can only be accessed within the form. If I don't need to access a control outside of a form, should I set the modifier to private? On the other hand, if friend is the default, maybe I should leave it as is (?). Thanks, Aaron On 2005-03-26, hartley_aa***@hotmail.com <hartley_aa***@hotmail.com> wrote:
> Hi, Basically, this means that Label1 is a variable representing a> > What does it mean when VS automatically adds a line like this to code > of my form: > > Friend WithEvents Label1 As System.Windows.Forms.Label Forms.Label object, the variable is visible throughout the Assembly, and it is registered for declarative events (the "FunctionName Handles Label1.Click" kinda stuff). > To be more precise, Friend properties can be accessed from anywhere in> Also, I noticed a modifier property for each control and the default is > Friend. When modifier is set to Friend, I can access the control from > anywhere with the application, while if it is set to private it can > only be accessed within the form. the Assembly. This will matter when you start having multi-assembly applications. > If I don't need to access a control Private is better. I presume that Friend is the default because lots of> outside of a form, should I set the modifier to private? On the other > hand, if friend is the default, maybe I should leave it as is (?). VB Classic code (and VB Classic programmers) manipulated controls from outside the form, so MS needed that for ease of migration. In practice though, I must admit I seldom bother to change the default, even though I probably should. BTW, you don't have to edit the code to do this, there's a "modifiers" property in the properties window for this. Thank you, David.
> Private is better. I presume that Friend is the default because lots Would private be better to preserve abstraction between forms? Inof > VB Classic code (and VB Classic programmers) manipulated controls from > outside the form, so MS needed that for ease of migration. other words, only those controls that were intended to accessed from elsewhere in the assembly will be available. Also, is there a memory/execution time performance benefit for private vs friend? Thank you, Aaron On 2005-03-27, hartley_aa***@hotmail.com <hartley_aa***@hotmail.com> wrote:
> Thank you, David. I'd prefer to say that it preserves encapsulation within the form, but> >> Private is better. I presume that Friend is the default because lots > of >> VB Classic code (and VB Classic programmers) manipulated controls > from >> outside the form, so MS needed that for ease of migration. > > Would private be better to preserve abstraction between forms? it's the same idea I think. > In With the caveat that it's probably never a good idea to access a form's> other words, only those controls that were intended to accessed from > elsewhere in the assembly will be available. controls from outside the form. > Also, is there a memory/execution time performance benefit for private Friend might be minutely faster, since making controls Private adds> vs friend? another level of indirection to accesses, but in normal circumstances the difference wouldn't even be measurable.
REALbasic 5.5 free to VB6 Users Untili March 31 2005
spice the boring default winforms treeview appearance up a bit... Help with SendMessage API calls Error with Custom Control Closing form... From VB.NET to Delphi7 convert. e.Cancel = True in MDI Child Closing event Object reference not set to an instance of an object. Tabcontrol tabpagebutton orientation Form Load Event |
|||||||||||||||||||||||