Question

I'm trying to make a bit of code that dynamically updates Windows Forms elements to integrate some back-end code I have with forms, but am running into a small speed-bump in the syntax.

Right now the code I have is this:

public virtual class DynamicDisplay
{
    private Control c;
    public DynamicDisplay(ref Control display)
    {
        c = display;
    }
    //interprets the attribute visually and shows it in the control
    public abstract void ShowVal(double valToDisplay);
}
public class ProgBarDynamicDisplay : DynamicDisplay
{
    private double max;
    public ProgBarDynamicDisplay(ProgressBar p, double nMax) : base(ref p)
    {
        max = nMax;
    }
}

But this is giving me a "mismatched methods" error. Does anyone know the syntax I should be using to pass the progress bar by reference to the superclass?

Was it helpful?

Solution

Perhaps something like this?

public abstract class DynamicDisplay
{
   private Control c;
   public DynamicDisplay(Control display)
   {
       c = display;
   }

   //interprets the attribute visually and shows it in the control
   public abstract void ShowVal(double valToDisplay);
}

public class ProgBarDynamicDisplay : DynamicDisplay
{
   private double max;
   public ProgBarDynamicDisplay(ProgressBar p, double nMax)
            : base( p)
   {
            max = nMax;
   }

 public override void ShowVal(double valToDisplay)
 {
      MessageBox.Show("Value : " + valToDisplay);
 }   
}

To test:

namespace TestProject3
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            ProgressBar p = new ProgressBar();
            TestProject3.Class1.ProgBarDynamicDisplay pbdr = new     TestProject3.Class1.ProgBarDynamicDisplay(p, 100);
            pbdr.ShowVal(10);
        }
    }
}

OTHER TIPS

You don't need the ref in the constructor for DynamicDisplay since you aren't reassigning to display in that function. Just drop the ref and you should be fine. Also get rid of ref where you call base(ref p)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top