Skip to content

How to create a global function/class ?

eli

Asked Aug 2, 2007, 2:59 AM EDT1 answer
Share
LinkedInX

Hi :)

I have a caple of questions:

1) How can i create a global function or a global class
that will be available to the entire project ?
2) I want to create derived class from the DataGridView class
and change it so it will fit to my needs, and after that i want
that this new dataGridView will be available in the ToolBox.
How can i do that ?
3) I want that the Minimize button of the ControlBox in a form
will do more things besides Minimizing the specific form, how
can i change what this button does ?

Thanks.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0

    Hi Eli,

    Below are answers to your questions:

    1) How can i create a global function or a global class
    that will be available to the entire project ?

    All classes that have public access are global to the project.  If you want to use a class as a means to hold a bunch of global functions, then just make the methods in the class public and static.


    2) I want to create derived class from the DataGridView class
    and change it so it will fit to my needs, and after that i want
    that this new dataGridView will be available in the ToolBox.
    How can i do that ?

    CSS
    Create a separate control library from the projectt menu and then create a custom control inside that library.  Change the base class from Control to DataGridView and add your code here.  You can use the ToolBoxBitmap attribute to assign an icon for the toolbox for this dll.  After building, right click on the toolbox and choose items.  Then browse for your new control library dll assembly and add it to the toolbox.
    public partial class CustomDataGridView : DataGridView
    {
    public CustomDataGridView()
    {
    InitializeComponent();
    }


    3) I want that the Minimize button of the ControlBox in a form
    will do more things besides Minimizing the specific form, how
    can i change what this button does ?

    C#
    Go into the Form Controls events under the lightning bolt.  Choose the Resize event and double click to wire the resize event and create an event handler.  Then add to the event handler the following code:
    private void Form1_Resize(object sender, EventArgs e)
     {
        if (this.WindowState == FormWindowState.Minimized)
         {
             // do extra stuff after minimize
         }
     }

    Best,

    0