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

  • SEARCH
  • Home
  • 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 6967037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:16:10+00:00 2026-05-27T16:16:10+00:00

public partial class Form1 : Form { public disp(string strVal) { lbl1.text = strVal;

  • 0
public partial class Form1 : Form 
{

    public disp(string strVal)
     {
                   lbl1.text = strVal;
      }     

     private void button1_Click(object sender, EventArgs e)
            {

            class1 cl  = new class1;
            cl.Show1("test",this);

        }

}

—————- Class ————

public class class1

{
 private Form  frm1;

    public void  Show1(string xName , object xfrmObj)
    {
        frm1 = (form) xfrmObj;
        frm1.disp(xName );  // here I am getting error .
    }

}

——————————————/

here i am trying to access ‘disp’ function from class and i have pass ‘form1’ as a object , but i am getting error

The error message that I am getting is

Error 3
‘System.Windows.Forms.Form’ does not contain a definition for ‘disp’
and no extension method ‘disp’ accepting a first argument of type ‘System.Windows.Forms.Form’ could be found
(are you missing a using directive or an assembly reference?)

this syntax in vb.net is working perfect.

please help me…..

Rajesh.

  • 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. Editorial Team
    Editorial Team
    2026-05-27T16:16:10+00:00Added an answer on May 27, 2026 at 4:16 pm

    you need to cast frm1 = (Form1)xfrmObj; instead of casting it to form in your Show1(xName,xfrmObj) method.

    EDIT: OP has stated in a comment that he needs this to work for several different forms.
    You can make all your forms implement the same Interface, like so:

    public partial class Form1 : Form, ICanDisplay
    { 
        public void disp(string strVal) 
        { //...
        } 
    }
    
    public partial class Form2 : Form, ICanDisplay
    {
        public void disp(string strVal) 
        { //...
        }
    }
    
    public interface ICanDisplay
    {
        void disp(string strVal);
    }
    

    then, change your method so it casts to ICanDisplay:

    public class class1
    {
    private Form  frm1;
    
    public void Show1(string xName , object xfrmObj)
    {
        frm1 = (ICanDisplay) xfrmObj;
        frm1.disp(xName);
    }
    

    }

    However, as @Heinzi has noted, you should change your Show1-method to the following:

    public void Show1(string xName, IDisplayForm xfrmObj)
    {
        xfrmObj.Disp(xName);
    }
    

    this will make the cast entirely unnecessary. The next step is to select meaningful names for your variables, functions and classes.

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

Sidebar

Related Questions

public partial class Form1 : Form { string[] id; private void button_Click(object sender, EventArgs
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void
Currently, I have something like: public partial class Form1 : Form { delegate void
public partial class Form1 : Form { protected override void WndProc(ref Message m) {
public partial class Form1 : Form { private EventThrower _Thrower; public Form1() { InitializeComponent();
public partial class Form1 : Form { String Path1 = Application.StartupPath + \\component.xml; XmlDataDocument
Consider this source: public partial class FormTest : Form { private Test test {
I did the following: public partial class Form1 : Form { public UserControl uc
I have the following: public partial class Form1 : Form { public Form1() {
I have this code: public partial class Form1 : Form { public Form1() {

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.