0

I am working to derive an ASCOM driver for an DIY astronomical dome from an example of a focuser.

Here the original for a focuser device:

ASCOM.EQFocuser.Focuser focuser;
        public MainWindow(Focuser focuser)
        {
            this.focuser = focuser;
            this.focuser.FocuserValueChanged += FocuserValueChanged;
            this.focuser.FocuserStateChanged += FocuserStateChanged;
            this.focuser.FocuserHumidityChanged += FocuserHumidityChanged;
            this.focuser.FocuserTemperatureChanged += FocuserTemperatureChanged;
            this.focuser.FocuserMotorChanged += FocuserMotorChanged;
            InitializeComponent();
            InitControls();

            this.FormBorderStyle = FormBorderStyle.FixedSingle;

        }

        delegate void SetCurrentPositionCallBack(int position);
        delegate void SetCurrentStateCallBack(bool isMoving);
        delegate void SetCurrentTemperatureCallBack(string temperature);
        delegate void SetCurrentHumidityCallBack(string humidity);
        delegate void SetCurrentMotorCallBack(int motorNumber);

        private void SetCurrentTemperature(string temperature)
        {
            txtBoxTemperature.InvokeIfRequired(txtBoxTemperature => { txtBoxTemperature.Text = temperature; });
            
        }

        private void SetCurrentHumidity(string humidity)
        {

            txtBoxHumidity.InvokeIfRequired(txtBoxHumidity => { txtBoxHumidity.Text = humidity; });
        }

        private void SetCurrentPosition(int position)
        {
            textBoxCurrentPosition.InvokeIfRequired(textBoxCurrentPosition => { textBoxCurrentPosition.Text = position.ToString(); });
        }

        private void FocuserValueChanged(object sender, FocuserValueChangedEventArgs e)
        {
            //this.textBoxCurrentPosition.Text = e.NewValue.ToString();
            SetCurrentPosition(e.NewValue);
        }

Now my code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
 
 
namespace ASCOM.SensDome
{
    public partial class MainWindow : Form
    {
        ASCOM.SensDome.Dome dome;
 
        public MainWindow(Dome dome)
        {
            this.dome = dome;
            this.dome.DomeStateChanged += DomeStateChanged;
            this.dome.DomeValueChanged += DomeValueChanged;
 
            // Eventhandler einbauen !!!!!!!
 
 
            InitializeComponent();
            InitControls();
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
        }
 
        delegate void SetCurrentPositionCallBack(int position);
        delegate void SetCurrentStateCallBack(bool isMoving);
 
        private void DomeValueChanged(object sender, DomeValueChangedEventArgs e)
        {
            SetCurrentPosition(e.NewValue);
        }
 
 
 
        private void SetCurrentPosition(int position)
 
        {
            textBoxCurrentPosition.I
 
        }
 

Screenshot showing that the method is not offered

In the original the InvokeIfRequired is available for the textbox object. In my project I do not get it offered. The settings, the EventArgs are of identical structure.

What am i doing wrong?

I kindly ask for advice. Christian

reprogramming of eventhanlers and eventargs. Comparing to the original on differences in the code and the used forms and the project properties. No differences found. Checking on stackoverflow for similar problems and solutions.

autoguider
  • 11
  • 3
  • A control does not have such a method. So you presumably have an extension method somewhere written in what you call the "original". So find out where it comes from in the original code. For example by clicking on it in the original code and selecting "go to definition" in the context menu. Then have a hard look at the namespace that extension is defined in and add the namespace to the list of usings in your new code. – Ralf Nov 16 '22 at 20:38
  • create a class file with the name `ExtensionMethods.cs` and then copy and paste the code of `InvokeIfRequired()` function, The problem will be solved ,see that:[link](https://github.com/EverettQuebral/EQFocuser/blob/43fdbb04e6baffbc26315e831ac11619cde10cbf/ExtensionMethods.cs) – Zakaria Najim Nov 16 '22 at 21:39
  • Problem is solved Many thanks – autoguider Nov 16 '22 at 22:18

0 Answers0