Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create a custom form property in c# .net

Please help me
Posted
Updated 24-Aug-10 21:37pm
v2
Comments
PSK_ 25-Aug-10 2:32am    
What is the issue? Custom form property is not different from the properties you normally defines.
senguptaamlan 25-Aug-10 2:40am    
didn't got the question...please explain a bit more
Dalek Dave 25-Aug-10 3:37am    
Minor Edit for Grammar.

Do you mean add a property to the Form class itself? If so, you can't but there are two easy solutions.

1. Create a new class derived from Form and use that in place when you need it.
C#
public class MyFormBase : Form
{
    // ...
    private int id;

    /// <summary>
    /// Gets or sets the identifier.
    /// </summary>
    public int ID
    {
        get{ return id; }
        set{ id = value; }
    }
}

So when adding a new form, change the declaration
C#
public partial class Form1 : MyFormBase
{
    // ...
    // Form1 instances automatically have ID property
}


2. Use Extension Methods[^]
 
Share this answer
 
Just add it. If you have a specific issue with doing so, post your code and explain it.
 
Share this answer
 
Comments
amitthakkar1987 25-Aug-10 4:30am    
i have two forms
form1 and form2
on form1 i have one button and form2 contains textbox

on buttton click i write the following code for create a any no of forms

form2 f2 = new form2();
f2.show();

now my question is that how i access the perticular textbox of a perticular form
amitthakkar1987 25-Aug-10 5:27am    
now i press the 3 time button click so genarate 3 forms and after i assign the unique name to forms name..
suppose frm1,frm2,frm3 so i want to access form1 textbox
DaveyM69 25-Aug-10 11:43am    
These comments do not relate to your original question. Have a look at this forum post which explains how: http://www.codeproject.com/Forums/1649/Csharp.aspx?fid=1649&select=3573386&fr=276#xx0xx
Basically, child forms raise events which are listened to by parent forms and parent forms set properties/call methods on child forms.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900