private void setupMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         if (SetupForm != null || SetupForm.IsDisposed)
             SetupForm.Show();
         else
         {
             SetupForm = new Setup(this);
             SetupForm.Show();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error opening Setup!\n" + ex.ToString());
     }
 }
        public CWExpert()
        {
            booting = true;
            InitializeComponent();
            float dpi = this.CreateGraphics().DpiX;
            this.AutoScaleMode = AutoScaleMode.Dpi;
            SizeF d = this.AutoScaleDimensions;
            d.Height = dpi;
            d.Width = dpi;
            this.AutoScaleDimensions = d;
            float ratio = dpi / 96.0f;
            string font_name = this.Font.Name;
            float size = (float)(8.25 / ratio);
            System.Drawing.Font new_font = new System.Drawing.Font(font_name, size);
            this.Font = new_font;
            font_name = txtVFOA.Font.Name;
            size = 14.25f / ratio;
            new_font = new System.Drawing.Font(font_name, size);
            txtVFOA.Font = new_font;
            size = 9.75f / ratio;
            new_font = new System.Drawing.Font(font_name, size);
            txtVFOB.Font = new_font;
            txtLosc.Font = new_font;
            font_name = this.menuStrip1.Font.Name;
            this.menuStrip1.Font = new System.Drawing.Font(font_name, size);
            this.menuStrip1.Size = new Size(this.menuStrip1.Width, (int)(25 / ratio));
            this.PerformAutoScale();
            this.PerformLayout();

            SetStyle(ControlStyles.UserPaint |
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.OptimizedDoubleBuffer, true);
            UpdateStyles();
            this.Text = programVersion;
            tx_image_phase_table = new float[(int)Band.LAST];
            tx_image_gain_table = new float[(int)Band.LAST];
            rx_image_phase_table = new float[(int)Band.LAST];
            rx_image_gain_table = new float[(int)Band.LAST];
            msg = new MessageHelper();
            edits = new TextEdit[3];
            DB.AppDataPath = Application.StartupPath;
            DB.Init();
            Audio.MainForm = this;
            PA19.PA_Initialize();
            #if DirectX
            DX.MainForm = this;
            #endif
            Display_GDI.MainForm = this;
            SetupForm = new Setup(this);
            booting = false;
            DXClusterForm = new DXClusterClient(this, SetupForm.txtTelnetHostAddress.Text.ToString(),
                SetupForm.txtStnCALL.Text.ToString(), SetupForm.txtStnName.Text.ToString(),
                SetupForm.txtStnQTH.Text.ToString());
            SetupForm.chkIPV6_CheckedChanged(this, EventArgs.Empty);
            display_event = new AutoResetEvent(false);
            output_ring_buf = new RingBuffer(32768);
            mon_ring_buf = new RingBuffer(32768);
            tbFilterWidth.Visible = false;
            picMonitor_bmp = new Bitmap(picMonitor.Width, picMonitor.Height,
                System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            #if(DirectX)
            if (VideoDriver == DisplayDriver.DIRECTX)
            {
                DirectXInit();
            }
            else
            #endif
            {
                SMeter.displayEngine = AnalogGAuge.AGauge.DisplayDriver.GDI;
                Display_GDI.Target = picPanadapter;
                Display_GDI.Init(this);

                if (File.Exists(".\\picDisplay.png"))
                {
                    picPanadapter.BackgroundImage = Image.FromFile(".\\picDisplay.png");
                    picWaterfall.BackgroundImage = Image.FromFile(".\\picDisplay.png");
                }
            }

            display_buffer = new float[4096];
            AlwaysOnTop = always_on_top;
            txtFilterWidth.Visible = false;
            tbFilterWidth.Visible = false;
            lblFilterwidth.Visible = false;
            menuStrip1.BackColor = Color.Black;
            menuStrip1.ForeColor = Color.White;
            tbAFGain_Scroll(this, EventArgs.Empty);
            genesis = new G59(this.Handle);
            btnCH1.BackColor = Color.LimeGreen;
            btnCH2.BackColor = Color.WhiteSmoke;

            if (Audio.SDRmode)
            {
                genesis.booting = false;
                G59Init();
                genesis.si570_i2c_address = 170;
                genesis.si570_fxtal = 114272200.0;
                genesis.HSDiv = 11;
                bool conn = genesis.Connected;

                if (conn)
                {
                    lblUSB.BackColor = Color.Green;
                }
                else
                {
                    lblUSB.BackColor = Color.Red;
                }
            }

            cwDecoder = new CWDecode(this);
            cwEncoder = new CWEncode(this);
            rtty = new RTTY(this);
            psk = new PSK(this);
            cwEncoder.CWSpedd = (int)SetupForm.udCWSpeed.Value;
            cwDecoder.rx_only = SetupForm.chkRXOnly.Checked;
            cwEncoder.TXPhase = (float)SetupForm.udTXPhase.Value;
            cwEncoder.TXGain = (float)SetupForm.udTXGain.Value;
            cwEncoder.TXIfShift = (float)SetupForm.udTXIfShift.Value;
            cwEncoder.TXOffDelay = (int)SetupForm.udTXOffDelay.Value;
            cwEncoder.SetKeyerSpeed((float)SetupForm.udCWSpeed.Value);
            cwEncoder.SetKeyerWeight((int)SetupForm.udCWWeight.Value);
            cwEncoder.SetKeyerIambic(SetupForm.chkG59Iambic.Checked);
            chkAFC_CheckedChanged(this, EventArgs.Empty);
            psk.TXPreamble = psk_preamble;

            if (SetupForm.chkG59IambicBmode.Checked)
                cwEncoder.SetKeyerMode(1);
            else
                cwEncoder.SetKeyerMode(0);

            rtty.TXPhase = (float)SetupForm.udTXPhase.Value;
            rtty.TXGain = (float)SetupForm.udTXGain.Value;

            if (!once)
            {
                SetupSDR(Application.StartupPath.ToString() + "\\wisdom");
                ReleaseUpdate();
                SetSampleRate(Audio.SampleRate);
                ResizeSDR(0, 4096);
                SetAGC(agc_mode);

                ProcessSampleThreadController[] pstc = new ProcessSampleThreadController[1];
                audio_process_thread = new Thread[1];

                for (uint proc_thread = 0; proc_thread < 1; proc_thread++)
                {
                    pstc[proc_thread] = new ProcessSampleThreadController(proc_thread);
                    audio_process_thread[proc_thread] = new Thread(new ThreadStart(pstc[proc_thread].ProcessSampleThread));
                    audio_process_thread[proc_thread].Name = "Audio Process Thread " + proc_thread.ToString();
                    audio_process_thread[proc_thread].Priority = ThreadPriority.Highest;
                    audio_process_thread[proc_thread].IsBackground = true;
                    audio_process_thread[proc_thread].Start();
                }

                once = true;
            }

            get_state = true;
            GetState();
            get_state = false;
            DB.LOGFilePath = log_file_path;
            DB.LOG_Init();
            InitLOG();
            keyboard = new Keyboard(this);
            recorder = new Recorder(this);

            double vfoa_freq, vfob_freq, losc_freq;
            int filter_vfoA, filter_vfoB, zoom, pan;
            DB.GetBandStack(current_band.ToString(), out vfoa_freq, out vfob_freq, out losc_freq, out filter_vfoA,
                out filter_vfoB, out zoom, out pan);
            LOSC = losc_freq;
            VFOA = vfoa_freq;
            VFOB = vfob_freq;
            FilterWidthVFOA = filter_vfoA;
            FilterWidthVFOB = filter_vfoB;
            tbZoom.Value = zoom;
            tbPan.Value = pan;
            lblPan_Click(null, null);

            switch (op_mode_vfoA)
            {
                case Mode.BPSK31:
                case Mode.BPSK63:
                case Mode.BPSK125:
                case Mode.BPSK250:
                case Mode.QPSK31:
                case Mode.QPSK63:
                case Mode.QPSK125:
                case Mode.QPSK250:
                    this.grpChannels.Text = "VFOA " + op_mode_vfoA.ToString() + "     VFOB " +
                    op_mode_vfoB.ToString() + "     ";
                    grpMonitor.Text = "Mode PSK";
                    break;
            }

            if (iq_correction == IQ_correction.FIXED)
            {
                SetRXIQGainPhase(1, rx_image_gain_table[(int)current_band],
                    rx_image_phase_table[(int)current_band]);
                RX_phase_gain();
            }
            else if (iq_correction == IQ_correction.WBIR)
            {
                SetRXIQGainPhase(2, 0.0f, 0.0f);
                RX_phase_gain();
            }

            dxcc = new DXCC();
            dxcc.Init(SetupForm.txtStnLOC.Text.ToString());

            try
            {
                if (use_telnet)
                    telnet_server = new TelnetServer(SetupForm.txtTelnetHostAddress.Text.ToString(),
                        (int)SetupForm.udTelnetServerPort.Value, SetupForm.chkIPV6.Checked);

                SetupForm.chkIPV6_CheckedChanged(this, EventArgs.Empty);
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());
            }
        }