⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sessdlg.cs

📁 一个远程终端软件的源码
💻 CS
📖 第 1 页 / 共 2 页
字号:
    protected virtual void GetOptions()
    {
      viewOpts.IsFullScrn = fullScrnBox.Checked;
      switch(rotateBox.SelectedIndex)
      {
        case 0:
          viewOpts.Orientation = Orientation.Portrait;
          break;
        case 1:
          viewOpts.Orientation = Orientation.Landscape90;
          break;
        case 2:
          viewOpts.Orientation = Orientation.Landscape270;
          break;
        case 3:
          viewOpts.Orientation = Orientation.Portrait180;
          break;
      }
      switch(pixelSizeBox.SelectedIndex)
      {
        case 0:
          viewOpts.PixelSize = PixelSize.Unspec;
          break;
        case 1:
          viewOpts.PixelSize = PixelSize.Force8Bit;
          break;
        case 2:
          viewOpts.PixelSize = PixelSize.Force16Bit;
          break;
      }
      viewOpts.CliScalingWidth = 0;
      viewOpts.CliScalingHeight = 0;
      switch(cliScalingBox.SelectedIndex)
      {
        case 0:
          viewOpts.CliScaling = CliScaling.None;
          break;
        case 1:
          viewOpts.CliScaling = CliScaling.Auto;
          break;
        case 2:
          viewOpts.CliScaling = CliScaling.OneHalf;
          break;
        case 3:
          viewOpts.CliScaling = CliScaling.OneThird;
          break;
        case 4:
          viewOpts.CliScaling = CliScaling.OneFourth;
          break;
        case 5:
          viewOpts.CliScaling = CliScaling.OneFifth;
          break;
        case 6:
          viewOpts.CliScaling = CliScaling.Double;
          break;
        case 7:
          viewOpts.CliScaling = CliScaling.Custom;
          // Assuming we have validated the input.
          viewOpts.CliScalingWidth = UInt16.Parse(cliScalingWidthBox.Text);
          viewOpts.CliScalingHeight = UInt16.Parse(cliScalingHeightBox.Text);
          break;
      }
      viewOpts.ServScaling = (ServScaling)servScalingBox.SelectedIndex;
      viewOpts.ViewOnly = viewOnlyBox.Checked;
      viewOpts.ShareServ = !shareServBox.Checked;
      viewOpts.ScrnUpdAlgo = scrnUpdAlgoBox.Checked? ScrnUpdAlgo.Asap : ScrnUpdAlgo.Batch;
    }

    protected virtual void SetOptions(ViewOpts viewOpts)
    {
      this.viewOpts = viewOpts;
      fullScrnBox.Checked = viewOpts.IsFullScrn;
      switch(viewOpts.Orientation)
      {
        case Orientation.Portrait:
          rotateBox.SelectedIndex = 0;
          break;
        case Orientation.Landscape90:
          rotateBox.SelectedIndex = 1;
          break;
        case Orientation.Portrait180:
          rotateBox.SelectedIndex = 3;
          break;
        case Orientation.Landscape270:
          rotateBox.SelectedIndex = 2;
          break;
      }
      switch(viewOpts.PixelSize)
      {
        case PixelSize.Unspec:
          pixelSizeBox.SelectedIndex = 0;
          break;
        case PixelSize.Force8Bit:
          pixelSizeBox.SelectedIndex = 1;
          break;
        case PixelSize.Force16Bit:
          pixelSizeBox.SelectedIndex = 2;
          break;
      }
      cliScalingWidthBox.Text = String.Empty;
      cliScalingHeightBox.Text = String.Empty;
      switch(viewOpts.CliScaling)
      {
        case CliScaling.None:
          cliScalingBox.SelectedIndex = 0;
          break;
        case CliScaling.Auto:
          cliScalingBox.SelectedIndex = 1;
          break;
        case CliScaling.OneHalf:
          cliScalingBox.SelectedIndex = 2;
          break;
        case CliScaling.OneThird:
          cliScalingBox.SelectedIndex = 3;
          break;
        case CliScaling.OneFourth:
          cliScalingBox.SelectedIndex = 4;
          break;
        case CliScaling.OneFifth:
          cliScalingBox.SelectedIndex = 5;
          break;
        case CliScaling.Double:
          cliScalingBox.SelectedIndex = 6;
          break;
        case CliScaling.Custom:
          cliScalingBox.SelectedIndex = 7;
          cliScalingWidthBox.Text = viewOpts.CliScalingWidth.ToString();
          cliScalingHeightBox.Text = viewOpts.CliScalingHeight.ToString();
          break;
      }
      servScalingBox.SelectedIndex = (int)viewOpts.ServScaling;
      viewOnlyBox.Checked = viewOpts.ViewOnly;
      shareServBox.Checked = !viewOpts.ShareServ;
      scrnUpdAlgoBox.Checked = viewOpts.ScrnUpdAlgo == ScrnUpdAlgo.Asap;
    }

    private void SaveConnHist()
    {
      try
      {
        ConnHist connHist = new ConnHist(App.ConnHistFileName);
        connHist.Add(host + "::" + port);
        connHist.Save(App.ConnHistFileName);
      }
      catch(IOException)
      {
        MessageBox.Show(App.GetStr("Unable to save the history file!"),
                        App.GetStr("Error!"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation,
                        MessageBoxDefaultButton.Button1);
      }
      catch(XmlException)
      {
        MessageBox.Show(App.GetStr("The history file is corrupted!"),
                        App.GetStr("Error!"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation,
                        MessageBoxDefaultButton.Button1);
      }
    }

    protected abstract void AddConnHistEntry(string entry);

    private void LoadConnHist()
    {
      try
      {
        ConnHist connHist = new ConnHist(App.ConnHistFileName);
        for(byte i = 0; i < connHist.Count; i++)
          AddConnHistEntry(connHist[i]);
      }
      catch(XmlException)
      {
        MessageBox.Show(App.GetStr("The history file is corrupted."),
                        App.GetStr("Error"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation,
                        MessageBoxDefaultButton.Button1);
      }
    }

    private void SaveDefsClicked(object sender, EventArgs e)
    {
      if(!ValidateCliScaling())
        return;
      GetOptions();
      try
      {
        viewOpts.Save(App.SettingsFileName);
      }
      catch(IOException)
      {
        MessageBox.Show(App.GetStr("Unable to save defaults!"),
                        App.GetStr("Error"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation,
                        MessageBoxDefaultButton.Button1);
      }
    }

    private void RestoreDefsClicked(object sender, EventArgs e)
    {
      try
      {
        viewOpts.Load(App.SettingsFileName);
      }
      catch(FileNotFoundException)
      {
        viewOpts = new ViewOpts();
      }
      catch(IOException)
      {
        MessageBox.Show(App.GetStr("Unable to read from the setting file!"),
                        App.GetStr("Error"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation,
                        MessageBoxDefaultButton.Button1);
        return;
      }
      catch(XmlException)
      {
        MessageBox.Show(App.GetStr("The setting file is corrupted!"),
                        App.GetStr("Error"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation,
                        MessageBoxDefaultButton.Button1);
        return;
      }
      catch(FormatException)
      {
        MessageBox.Show(App.GetStr("The setting file is corrupted!"),
                        App.GetStr("Error"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation,
                        MessageBoxDefaultButton.Button1);
        return;
      }
      SetOptions(viewOpts);
    }

    private void ListenBoxChanged(object sender, EventArgs e)
    {
      if(listenBox.Checked)
        remoteEndPt.Text = "";
      else
        listenPortBox.Text = "";
      remoteEndPt.Enabled = !listenBox.Checked;
      listenPortBox.Enabled = listenBox.Checked;
    }

    private void CliScalingBoxChanged(object sender, EventArgs e)
    {
      cliScalingWidthBox.Enabled = cliScalingBox.Text == App.GetStr("Custom");
      cliScalingHeightBox.Enabled = cliScalingBox.Text == App.GetStr("Custom");
    }

    protected override void OnLoad(EventArgs e)
    {
      base.OnLoad(e);

      ControlBox = false;
      MinimizeBox = false;
      MaximizeBox = false;
      Text = App.GetStr("New VNC Connection");
      Menu = new MainMenu();

      servLbl.Text = App.GetStr("Server:");
      remoteEndPtLbl.Text = App.GetStr("(host:display or host::port)");
      passwdLbl.Text = App.GetStr("Password:");
      passwdBox.PasswordChar = '*';
      recentLbl.Text = App.GetStr("Recent:");

      listenBox.Text = App.GetStr("Listen mode");
      listenBox.CheckStateChanged += new EventHandler(ListenBoxChanged);
      listenPortLbl.Text = App.GetStr("Port:");
      listenPortBox.Enabled = false;

      fullScrnBox.Text = App.GetStr("Full screen mode");
      rotateLbl.Text = App.GetStr("Orientation:");
      rotateBox.DropDownStyle = ComboBoxStyle.DropDownList;
      rotateBox.Items.Add(App.GetStr("Portrait"));
      rotateBox.Items.Add(App.GetStr("Screen rotated clockwise"));
      rotateBox.Items.Add(App.GetStr("Screen rotated counter-clockwise"));
      rotateBox.Items.Add(App.GetStr("Upside down"));
      pixelSizeLbl.Text = App.GetStr("Pixel size:");
      pixelSizeBox.DropDownStyle = ComboBoxStyle.DropDownList;
      pixelSizeBox.Items.Add(App.GetStr("Server decides"));
      pixelSizeBox.Items.Add(App.GetStr("Force 8-bit"));
      pixelSizeBox.Items.Add(App.GetStr("Force 16-bit"));

      cliScalingLbl.Text = App.GetStr("Client-side scaling:");
      cliScalingBox.DropDownStyle = ComboBoxStyle.DropDownList;
      cliScalingBox.Items.Add(App.GetStr("None"));
      cliScalingBox.Items.Add(App.GetStr("Auto"));
      cliScalingBox.Items.Add(App.GetStr("1/2 of server"));
      cliScalingBox.Items.Add(App.GetStr("1/3 of server"));
      cliScalingBox.Items.Add(App.GetStr("1/4 of server"));
      cliScalingBox.Items.Add(App.GetStr("1/5 of server"));
      cliScalingBox.Items.Add(App.GetStr("2 of server"));
      cliScalingBox.Items.Add(App.GetStr("Custom"));
      cliScalingBox.SelectedIndexChanged += new EventHandler(CliScalingBoxChanged);
      cliScalingWidthLbl.Text = App.GetStr("Width (pixel):");
      cliScalingHeightLbl.Text = App.GetStr("Height (pixel):");
      servScalingLbl.Text = App.GetStr("Server-side scaling:");
      servScalingBox.DropDownStyle = ComboBoxStyle.DropDownList;
      servScalingBox.Items.Add(App.GetStr("Default"));
      servScalingBox.Items.Add(App.GetStr("None"));
      servScalingBox.Items.Add(App.GetStr("1/2"));
      servScalingBox.Items.Add(App.GetStr("1/3"));
      servScalingBox.Items.Add(App.GetStr("1/4"));
      servScalingBox.Items.Add(App.GetStr("1/5"));
      servScalingBox.Items.Add(App.GetStr("1/6"));
      servScalingBox.Items.Add(App.GetStr("1/7"));
      servScalingBox.Items.Add(App.GetStr("1/8"));
      servScalingBox.Items.Add(App.GetStr("1/9"));

      viewOnlyBox.Text = App.GetStr("View only (ignore input)");
      shareServBox.Text = App.GetStr("Disconnect other viewers upon connect");
      scrnUpdAlgoBox.Text = App.GetStr("Update screen ASAP");

      SetOptions(viewOpts);
      LoadConnHist();
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -