User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 391,913 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,718 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser:
Views: 4318 | Replies: 11
Reply
Join Date: Jul 2007
Posts: 17
Reputation: 1qaz2wsx7 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
1qaz2wsx7 1qaz2wsx7 is offline Offline
Newbie Poster

How to create a global function/class ?

  #1  
Aug 2nd, 2007
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,164
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Rep Power: 7
Solved Threads: 58
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: How to create a global function/class ?

  #2  
Aug 2nd, 2007
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.
Last edited by hollystyles : Aug 2nd, 2007 at 7:59 am.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote  
Join Date: Jun 2007
Posts: 321
Reputation: Hamrick will become famous soon enough Hamrick will become famous soon enough 
Rep Power: 3
Solved Threads: 33
Hamrick's Avatar
Hamrick Hamrick is offline Offline
Posting Whiz

Re: How to create a global function/class ?

  #3  
Aug 2nd, 2007
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.
The truth does not change according to our ability to stomach it.
Reply With Quote  
Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,164
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Rep Power: 7
Solved Threads: 58
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: How to create a global function/class ?

  #4  
Aug 2nd, 2007
Originally Posted by Hamrick View Post
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...
     }
}
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote  
Join Date: Jun 2007
Posts: 321
Reputation: Hamrick will become famous soon enough Hamrick will become famous soon enough 
Rep Power: 3
Solved Threads: 33
Hamrick's Avatar
Hamrick Hamrick is offline Offline
Posting Whiz

Re: How to create a global function/class ?

  #5  
Aug 2nd, 2007
the OP doesn't want to change the behaviour, he want's to add additional behaviour.
Adding additional behavior is changing the behavior.
The truth does not change according to our ability to stomach it.
Reply With Quote  
Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,164
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Rep Power: 7
Solved Threads: 58
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: How to create a global function/class ?

  #6  
Aug 2nd, 2007
Ok so you agree it can be changed now then, that's cool
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote  
Join Date: Jun 2007
Posts: 321
Reputation: Hamrick will become famous soon enough Hamrick will become famous soon enough 
Rep Power: 3
Solved Threads: 33
Hamrick's Avatar
Hamrick Hamrick is offline Offline
Posting Whiz

Re: How to create a global function/class ?

  #7  
Aug 2nd, 2007
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.
The truth does not change according to our ability to stomach it.
Reply With Quote  
Join Date: Nov 2006
Location: Bonners Ferry, ID
Posts: 279
Reputation: JerryShaw is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 38
JerryShaw JerryShaw is offline Offline
Posting Whiz in Training

Re: How to create a global function/class ?

  #8  
Aug 3rd, 2007
#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.
Reply With Quote  
Join Date: Jul 2007
Posts: 17
Reputation: 1qaz2wsx7 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
1qaz2wsx7 1qaz2wsx7 is offline Offline
Newbie Poster

Re: How to create a global function/class ?

  #9  
Aug 6th, 2007
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.
Reply With Quote  
Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,164
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Rep Power: 7
Solved Threads: 58
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: How to create a global function/class ?

  #10  
Aug 13th, 2007
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace DataGridViewComponent
{
    public class DataGridView2: DataGridView
    {

    }
}
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C# Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C# Forum

All times are GMT -4. The time now is 7:53 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC