1. My namespace is called "MyNameSpace". So...
How to create that Form3 will inherit from Form2, which is already a child of Form1 (Form2 has class: public partial class Form2 : Form)

I would like to creat like: class Form3 : Form2

And do not forget, all are windows forms.

Is this how it goes:

public partial class Form3 : MyNameSpace.Form2

2. I would like to know something more:
How to pass values from Form2 to Form3 then?

I have some binary data in my variable "buffer, so how do I transfer them to Form3 and because inside its a text, how ten to put this text into a richTextBox?

This is my variable I have now in Form2:

byte[] buffer = (byte[])cmd1.ExecuteScalar();

As said, "buffer" has binary data insed, which I want to transfer to Form3 and show the data (its a text file) in richTextBox.
Any idea?

I'm not entirely sure why you are trying to inherit from your forms, i'll leave that to someone who knows more.

But your second question, the best way to pass data between forms, and maintain encapsulation, is to use a public property:

public partial class Form3
{
    private string _Value;

    public string Value
    {
          get {return _Value;}
          set {_Value = value;}
    }
}

public partial class Form2
{
     private void CreateForm3()
     {
           Form3 frm3 = new Form3();
           frm3.Value = "Test Value";
           frm3.Show();
     }
}

It was written on the fly so apologies for any typos.

If you're inheriting between two forms you're not passing data but rather you are sharing it. You need to mark members in the form as "protected" instead of "private" so you can access them in your inherited form. Upload a sample project with your forms and describe the desired behavior in greater detail.

Although a little unrelated to this thread, I have one doubt. Suppose I have a main form with a textbox in it. Also, I have another .cs file in my project. How can I access the contents of the textbox in this file?

@sathya8819 - my post above shows how to access data in one form from another whilst maintaining encapsulation. If you are trying to access the Text in a TextBox just modify the Value property:

public string Textbox1_Text
    {
          get {return Textbox1.Text;}
          set {Textbox1.Text = value;}
    }

@mitja - can you expand on why you want to inherit your forms? If you are trying to access data between the forms then you can use properties to do so. Generally Form Inheritance is used when you want to re-use the design/functionality of a Form.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.