Public Methods in Forms

  • Thread starter Thread starter jp
  • Start date Start date
J

jp

Hi.
I'm new to C#, but I've been programing in C++ and VB for years.
I wrote a public method inside a form:

public bool bConnect(string strServerName, string strDBName,
string strUser, string strPassword)
{
return (true);

}

The thing is that there is no way to call it from outside the form. I
can't even see it with the autocomplete feature:

private void aplicacionesToolStripMenuItem_Click(object
sender, EventArgs e)
{
Form frmApps = new clsFormApps();
frmApps.bConnect("", "", "", ""); -> FAILS,
with error Error...

'System.Windows.Forms.Form' does not contain a definition for
'bConnect' and no extension method 'bConnect' accepting a first
argument of type 'System.Windows.Forms.Form' could be found (are you
missing a using directive or an assembly reference?) D:\tools
\ConfigPAL 2009\ConfigPAL\ConfigPAL\clsFormMain.cs 59 21 ConfigPAL

Thank you for your help.
 
change:
Form frmApps = new clsFormApps();

to:
clsFormApps frmApps = new clsFormApps();
 
Form frmApps = new clsFormApps();
'System.Windows.Forms.Form' does not contain a definition for
'bConnect'

Declare it as

clsFormApps frmApps = new clsFormApps();
 
I'm new to C#, but I've been programing in C++ and VB for years.

And it shows:
public bool bConnect(

I'm a VB guy, too, and I know how variants of Hungarian notation have been
beaten into our heads over the year, buy I IMPLORE you to try to give it up.
Please oh please drop the data type danglers from anything that's going to
be public.
 
I'm a VB guy, too, and I know how variants of Hungarian notation have been
beaten into our heads over the year, buy I IMPLORE you to try to give it
up. Please oh please drop the data type danglers from anything that's
going to be public.

I'd be interested to know why?
I am trying to give it up but about as successfully as giving up smoking :-(
 
I'd be interested to know why?
I am trying to give it up but about as successfully as giving up smoking
:-(

A) It's ugly.

B) It really is non-standard. Like it or not, I consider Microsoft to be an
authority when it comes to Windows programming, and I try to follow their
example. Let's go a little off-topic and look at some of the methods the VB6
Clipboard object exposes (in truth, the general concept applies equally to
..NET programming):

Function GetData([Format]) As IPictureDisp
Function GetFormat(Format As Integer) As Boolean
Function GetText([Format]) As String

Notice that they didn't name the functions objGetData, blnGetFormat, or
strGetText. In fact, no methods, properties, or events contain any of this
junk. Events, for example, aren't named ClickEvent, MoveEvent,
GotFocusEvent, but I've seen lots of people who think they need to beat it
into your head with a sledgehammer that you're dealing with an event.

If I were to use a third-party's library and every class started with "cls"
(oh GOD do I HATE this!!) and every non-void function was decorated with a
return type indicator I'd have second thoughts about ever dealing with that
third party again. Do you put a clsTextBox on a form? A clsLabel? No.
TextBox. Label. We know what they are!

Now, you may be writing something that's in-house only and will never be
used by anyone else, but on a personal level it doesn't matter to me. I
consider following MS's standards to be the professional way to do things,
and I strive to be a professional even if no one's ever going to see my
stuff but me.

It is, of course, just my opinion.
 
Back
Top