Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 108719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:57:22+00:00 2026-05-11T01:57:22+00:00

(I still feel like a complete newbie in MS Visual environments… so please bear

  • 0

(I still feel like a complete newbie in MS Visual environments… so please bear with!)

I’m using Microsoft Visual C# 2008 Express Edition.

I have a project and in that project are two different forms. The .cs file for each form starts out:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Common; using System.Drawing; using System.Text; using System.Windows.Forms;  namespace MyNameSpace {     public partial class MyFormName : Form     { ... 

(…and the second is ‘MyFormName2’ but no differences besides that)

I want to write a function that I know both forms are going to need to access. I right-clicked on my project, selected ‘Add’, selected ‘New Item’ then selected ‘Code File’ and named my file ‘Common.cs’ and it gave me a completely blank file that’s in my project.

How do I set this up…? I thought I should do the following…

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Common; using System.Drawing; using System.Text; using System.Windows.Forms;  namespace MyNameSpace { } 

…but then when I try to add a function like:

public void mytestfunc() { } within that namespace I get the following error:

‘Expected class, delegate, enum, interface, or struct’

How do I set things up so I can have ‘mytestfunc’ be available to both MyFormName and MyFormName2?

Thanks!

-Adeena

UPDATE: Understand (now) that everything must be in a class, but then I don’t understand how to really use it. Does that mean I have to create an object? This common function happens to just be some math…

so now if I have this:

namespace MyNameSpace {     public class MyCommonClass     {         public void testFunc()         {             MessageBox.Show('Hee hee!');             return;         }     } } 

…how do I call testFunc from my Form? Must I do the following:

MyCommonClass temp = new MyCommonClass; temp.testFunc(); 

or is there another way to call testFunc?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:57:22+00:00Added an answer on May 11, 2026 at 1:57 am

    If you do something like:

    namespace MyNameSpace {     public class myclass     {         public myMethod()         {             // Code         }     } } 

    You will be able to instantiate and access it. If you change it to:

    namespace MyNameSpace {     public class myclass     {         public static myMethod()         {             // Code         }     } } 

    You will be able to call myClass.myMethod without instantiating a new myClass.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 62k
  • Answers 62k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The lifecycle of an Applet (or JApplet) is more complicated… May 11, 2026 at 9:57 am
  • added an answer Do you have a monitoring application that connects to the… May 11, 2026 at 9:57 am
  • added an answer Another easy way to get started with this, before you… May 11, 2026 at 9:57 am

Related Questions

(I still feel like a complete newbie in MS Visual environments... so please bear
I still feel C++ offers some things that can't be beaten. It's not my
I have read around 4-5 books on design patterns, but still I don't feel
I used multiple threads in a few programs, but still don't feel very comfortable
I still very new using Subversion. Is it possible to have a working copy
I still have a large number of floppies. On some of them there probably
I still have a problem with the splash screen. I don't want to use
Should I still be using tables anyway? The table code I'd be replacing is:
I've grokked the code for all the aforementioned apps and I still can't find
I've gone through most of the example code and I still need some help.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.