Click here to Skip to main content
15,888,102 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello.

I am using the OpenTK toolkit to utilise OpenGL within my application.

I need to create a new class for the 'panel' object in C#.

I will then overide some of the methods and add the openGL stuff in there.

I have placed a panel on my form, but cant figure out what to do next.

In c++, I could simply double click it and it would add a full class for the object, but I can not figure it out.

Also, once this is done, how do I attach my panel on the form to this new class?

Thank you,
Regards,
Stephen
Posted

1 solution

To derive a class from the Panel object, you do something like this:
C#
public class MyPanel : System.Windows.Forms.Panel {
    override void OnPaint(PaintEventArgs e) {
        base.OnPaint(e);
    }
}

Override the Panel methods to extend its functionaliy. You can then place an instance of the MyPanel class in your form.
 
Share this answer
 
Comments
stephen.darling 3-Aug-11 10:39am    
Thank you,

I have managed to derive the class, however, when I add a panal to my form, I still cant figure out how to connect it to this new class?

Thank you,
Steve
BobJanova 3-Aug-11 12:17pm    
You don't add a Panel to your form. Instead, add an instance of MyPanel to the form. If you're using Visual Studio, any components in the project will appear inside new groups in the toolbox.
stephen.darling 3-Aug-11 12:25pm    
Hi.
Thats what I though, however, nothing new is showing up in the toolbox panal in devStudio. I am using Microsoft Visual Studio 2010 Professional.

I have created the following class...
<pre>
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using OpenTK.OpenGL;
using OpenTK.OpenGL.Enums;

namespace CellSim
{
public abstract class OpenGLPanel : System.Windows.Forms.Panel
{
private OpenTK.GLControl glControl1;

etc.......
</pre>

But I cant seem to connect it to a panel, or add a panel that can use this class.

I coppied the class directly form anouther open source app, and it is working fine in that app. Also, my app builds without any errors?

Thank you,
Stephen
[no name] 3-Aug-11 14:47pm    
There is nothing called attaching the class to a Panel. Your class "is the" Panel. When you build the project that contains the OpenGLPanel class, Visual Studio will add the control to your ToolBox. Instead of adding a Panel, add the OpenGLPanel control that shows up in your ToolBox.

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