Windows Form in a Library

I

Ian Semmel

Suppose I have a form in a library, say LibForm, and I add a button, say
helpButton, with a modifier of protected.

If I then add a form to a project and change the generated code to read

public partial class MyForm : LibForm
.....

If I go to LibForm and double-click on the 'Click' event for helpButton, it
generates
'private helpButton_Click (..)'

If I double-click on 'Click' event for helpButton in MyForm, it generates
another 'private helpButton_Click' procedure. This is OK.

Don't you think it should generate 'protected helpButton_Click (...)' in
LibForm so I can call it from MyForm ?

Question : If I manually change the private to protected in LibForm, will VS
always leave it so or are there circumstances when it will change it back to
private.
 
T

Tom Spink

Ian said:
Suppose I have a form in a library, say LibForm, and I add a button, say
helpButton, with a modifier of protected.

If I then add a form to a project and change the generated code to read

public partial class MyForm : LibForm
....

If I go to LibForm and double-click on the 'Click' event for helpButton,
it generates
'private helpButton_Click (..)'

If I double-click on 'Click' event for helpButton in MyForm, it generates
another 'private helpButton_Click' procedure. This is OK.

Don't you think it should generate 'protected helpButton_Click (...)' in
LibForm so I can call it from MyForm ?

Question : If I manually change the private to protected in LibForm, will
VS always leave it so or are there circumstances when it will change it
back to private.

Hi Ian,

As far as I can _remember_ VS will leave it alone, after you've created it.

I believe the behaviour you're experiencing, IMHO, is a design decision that
assumes event handlers should be private to the containing class... which
is pretty sensible - as .NET uses a pretty good design pattern for event
management, by means of the 'protected virtual' On* methods, which in turn
raise the events to which they relate.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top