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 is easy
right click website or project, 'Add New Item'
Add a class file
add a public static method eg;

myGlobalClass.cs

public class myGlobalClass
{
    public static void myGlobalFunction()
    {
            //function logic ...
    }
}

Call it in your code:

myGlobalClass.myGlobalFunction();

2. Derived DataGrid
Create a separate class library project, add a class file myDataGrid.cs

public class myDataGrid : DataGrid
{
    //add your override members and methods here
}

Look up ToolboxBitMap, ToolboxData and Designer attributes to customise the icon for the toolbox, what is written to the aspx page when you drag your control into the designer and how it looks in the designer.

Build your class library, In your toolbox right click and choose items and browse to the dll you just built, select the control from the list.

3. I don't really understand what you mean with this one sorry.


What you're asking for is too much to explain properly in a single post in a forum, you need to get yourself a good book on the subject, there are hundreds. These forums are really for when you already have made your derived class, function or whatever and you need help tweaking it or getting it to work.

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 ?

You can't change that behavior. You have to remove it completely by setting the FormBorderStyle to None and make your own from scratch.

You can't change that behavior. You have to remove it completely by setting the FormBorderStyle to None and make your own from scratch.

the OP doesn't want to change the behaviour, he want's to add additional behaviour.

Check out the Form.Resize event, hook that event and add your
logic. You need to check the WindowState:

private void Form1_Resize(object sender, System.EventArgs e)
{
   //Check to see if the window has been Minimized:
   if (this.WindowState == FormWindowState.Minimized)
    {
           //do stuff...
     }
}

the OP doesn't want to change the behaviour, he want's to add additional behaviour.

Adding additional behavior is changing the behavior. ;)

Ok so you agree it can be changed now then, that's cool :)

I have to agree because you proved me wrong. You can't change things like the click event for the button but you can hook events further down the line and do stuff.

commented: for spotting my grammatical faux par +5

#3, you can't stop it from sending the a minimize command (without some Windows API calls), however if you want it to do more things before it minimizes, you can use the Deactivated Event handler or the SizeChanged event (http://www.thescripts.com/forum/thread275452.html). If you want to stop the minimize action, then you have to trap the message and do what you want... this calls for importing some WinAPI stuff, which like hollystyles said, is too much to go into this thread.
You also might want to look into a Notify component to trap the minimize event.

Hi :)

Thanks for all the answers.


I have a problem:
I tryed to do what Hollystyles sayd (question number 2)
But i couldnt use the DataGridView class as a base class.

How can i do it ?

Here is the code in the Class Library Project:

using System;
using System.Collections.Generic;
using System.Text;

namespace DataGridViewComponent
{
    public class DataGridView2: DataGridView
    {

    }
}

The error line:

Error 1: The type or namespace name 'DataGridView' could not be found (are you missing a using directive or an assembly reference?)

I tryed to add some Usings but it didnt helped,
what are the Usings that i need to add ?

What is the problem ?


Thanks.

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace DataGridViewComponent
{
    public class DataGridView2: DataGridView
    {

    }
}

Hi :)

I stll not working :/

I open a new Class Library project, write the code you wrote, i run
the project, and its not working.

Th error:

The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?) C:\Documents and Settings\adirim\My Documents\Visual Studio 2005\Projects\project\ClassLibrary1\Class1.cs 4 14 ClassLibrary1

What is the problem ?

Thanks.

You are missing a reference to the System.Windows.Forms.dll

In order to use the System.Windows.Forms namespace and classes in your code your project must reference the dll library in which those classes are compiled. When you create a windows application project this reference is included automatically by Visual Studio. When creating a class library you have to be explicit.

In the solution explorer right click the references folder below your class library project, select add reference. In the NET tab scroll down to System.Windows.Forms.dll and select it and click ok, now the using statement will be valid and the project should compile.

Not that it really matters, but 'global' methods and members are typically frowned upon in an OOP environment since they inherently have no associated object (instanceless) thus delving away from the object oriented nature. Having said that, feel free to ignore the norm and do what works best for you - I make use of static classes quite a bit myself. Another thing to note is that values marked const values are always static, and can be accessed with no instance of the object.

Just for clarity's sake, a private const is an instruction to the compiler to effect its use within the local class, and a public constant can be used outside of the class it is assigned by referencing the class name it is contained within (observing class scope). The compiler does not use an object assigned the const attribute like it does with a commonly defined variable.
A constant is however not a "static" object by the strict use of that definition within OOP. It is a more like a compiler directive than a variable. The compiler reads all the constant declarations for a project, then it performs a: Replace all references of this key word to this value within the source code.

Sorry for continuing such an out dated posting

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.