Click here to Skip to main content
15,908,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good Day,

Please your help in

I have a UserControl which have a class as shown below. This Class a method Called DrawHistogram


C#
namespace Prog1
{
	/// <summary>
	/// Summary description for HistogramaDesenat.
	/// </summary>
	public class HistogramControlClass : System.Windows.Forms.UserControl
	{ ......// Codes 

        }
        public void DrawHistogram(long[] Values)
         {
            //Doing calculation 
         }
		
}


In other hand, I have a Form with the following

C#
namespace Prog1.ImageHistogram
{
    class HistogramEqualization:PNM, HistogramControlClass
    {
//I need to call DrawHistogram here where I used using and multi base class but 
// Still unable to call it

     }
}

Simply, I need to call DrawHistogram from the Form, using "using" and Multibase class but still unable to call it.
Any help is appreciated
Posted

Two things:

First, you put a method inside a namespace:
C#
namespace Prog1
{
	/// <summary>
	/// Summary description for HistogramaDesenat.
	/// </summary>
	public class HistogramControlClass : System.Windows.Forms.UserControl
	{ ......// Codes 

        }
        public void DrawHistogram(long[] Values)
         {
            //Doing calculation 
         }		
}

You can't put a method inside a namespace, you always have to put it inside a class.

Second, HistogramEqualization derives from two classes:
C#
class HistogramEqualization:PNM, HistogramControlClass

This is impossible, because C# does only support multiple inheritance for interfaces. If PNM is an interface, then multiple inheritance is possible in this case. If PNM is a class, then it is not possible.

Solution


First, put the DrawHistogram method inside the HistogramControlClass:
C#
namespace Prog1
{
	/// <summary>
	/// Summary description for HistogramaDesenat.
	/// </summary>
	public class HistogramControlClass : System.Windows.Forms.UserControl
	{ ......// Codes 
             public void DrawHistogram(long[] Values)
             {
                //Doing calculation 
             }
        }		
}

Then, solve the multiple inheritance problem. This is only necessary if PNM is not an interface. A possible solution is to move the properties/fields/methods of PNM to HistogramControlClass.

After solving these problems, you'll be able to call DrawHistogram in HistogramEqualization.
 
Share this answer
 
Comments
Stevea2000 9-Feb-14 13:24pm    
First Thanks for the reply

1- DrawHistogram it is inside the class HistogramControlClass
So My apology it is a typo error

2- PNM it is a class and not an interface

I inherited HistogramEqualization from PNM because I have most of the work there.
Moving PNM to HistogramControlClass, I am assuming will cause same problem.
Where inside PNM there are multiple inherited classes that have been used.

I am thinking about converting PNM into an interface but still not sure if this will cause a problem since there are many of inherited classes inside it and currently used by other parts of the program

Solution 2 is good approach but I am looking for advise to apply it

I am caution that I will face a problem if I do that
Thomas Daniels 10-Feb-14 12:42pm    
If you have more classes with multiple inheritance, then you'll probably face problems if you only fix this specific problem. I think it's the best idea to rethink the architecture of your program.
Your code fragment shows the DrawHistogram method as not a part of the HistogramControlClass - it is outside the class definition. So if your HistogramControlClass is nested in a different class, then DrawHistogram is a method of that class, not HistogramControlClass.

A quick check says this all works:
C#
public partial class Form1 : Form
    {
    ...
    private void MyMethod()
        {
        HistogramControlClass hcc = new HistogramControlClass();
        hcc.DrawHistogram(new long[10]);
        }
    }
public class HistogramControlClass : UserControl
    {
    public void DrawHistogram(long[] values)
        {
        }
    }
public class HistogramEqualization : HistogramControlClass
    {
    public void MyMethod()
        {
        DrawHistogram(new long[100]);
        }
    }
 
Share this answer
 

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