change theme of controls?

samiullah478

Newcomer
Joined
Dec 20, 2006
Messages
3
how to change themes for controls in vb fourm and assign a new window theme ? that is used in window xp. like i want to set default window xp classic theme.

secondly i want to use a same datagrid view i generated in one form in to others forms with same parameters. is it i make it class ? how to convert it in custom tool
 
Generally, it is considered most polite to use whatever theme the user has selected. The exception being if you are looking to skin your application (like windows media player). This thread might be a little old but it has some good information in it that will help get you on the right track.

Also, just for future reference, you will have more success with getting questions answered if you only ask one question in a thread at a time. Welcome to the forums!
 
For your datagridview question - you have lots of options, but two come to mind. Which one you use depends on how you've created the control.
1. Create a new class that inherits from DataGridView. Copy the code from your form's InitializeComponent that sets the properties for the DataGridView into the constructor of the new class. Then, use your new class instead of DataGridView. Your new class is a DataGridView so all code works exactly the same - you're just specifying some defaults for the properties.

2. If you create the control manually (not through the designer), then move that code into another class that returns the instance through a static method (the factor pattern). For example, if you have code on your form like the following:
C#:
private void SetupForm()
{
    DataGridView gv = new DataGridView();
    // Set properties of gv here...

    // Add the DataGridView to the form
    this.Controls.Add(gv);
}

Then you'll want something like this:
C#:
// Code in a new class
internal class DataGridViewUtility
internal static DataGridView CreateDefault()
{
    DataGridView gv = new DataGridView();
    // Set properties of gv here...

    // Add the DataGridView to the form
    return gv;
}

// Then in your form:
private void SetupForm()
{
    // Add the DataGridView to the form
    this.Controls.Add(DataGridViewUtility.CreateDefault());
}

-ner
 
Back
Top