sessdlgfullcf.cs
来自「一个远程终端软件的源码」· CS 代码 · 共 407 行 · 第 1/2 页
CS
407 行
// Copyright (C) 2005, 2007 Rocky Lo. All Rights Reserved.
//
// This file is part of the VNC system.
//
// The VNC system is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
//
// If the source code for the VNC system is not available from the place
// whence you received this file, check http://www.uk.research.att.com/vnc or contact
// the authors on vnc@uk.research.att.com for information on obtaining it.
using System;
using System.IO;
using System.Xml;
using System.Drawing;
using System.Windows.Forms;
namespace Vnc.Viewer
{
internal abstract class SessDlgFullCf : SessDlg
{
protected TabControl tabCtrl = new TabControl();
protected Button okBtn = new Button();
protected Button cancelBtn = new Button();
protected Button aboutBtn = new Button();
protected TabPage generalPage = new TabPage();
protected ListBox recentBox = new ListBox();
protected TabPage connModePage = new TabPage();
protected TabPage displayPage = new TabPage();
protected TabPage scalingPage = new TabPage();
protected TabPage othersPage = new TabPage();
protected TabPage saveLoadPage = new TabPage();
protected Button saveConnOptsBtn = new Button();
protected Button saveConnOptsPwdBtn = new Button();
protected Button loadConnOptsBtn = new Button();
protected Button saveDefsBtn = new Button();
protected Button restoreDefsBtn = new Button();
internal SessDlgFullCf() : base()
{}
internal SessDlgFullCf(ViewOpts viewOpts) : base(viewOpts)
{}
private void KeyPressed(object sender, KeyPressEventArgs e)
{
e.Handled = true;
if(e.KeyChar == (UInt32)Keys.Enter)
{
// For buttons, we will not be here because KeyDown has dismissed the dialog.
Ok();
}
else if(e.KeyChar == (UInt32)Keys.Escape)
Cancel();
else
e.Handled = false;
}
private void SaveConnOpts(bool savePwd)
{
if(!ValidateCliScaling())
return;
GetConnMode();
if(ConnMode == ConnMode.Active)
{
if(!ValidateHostPort())
return;
}
else
{
if(!ValidateListenPort())
return;
}
GetPasswd();
GetOptions();
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = App.GetStr("VNC files (*.vncxml)|*.vncxml|All files (*.*)|*.*");
if(dlg.ShowDialog() != DialogResult.OK)
return;
try
{
ConnOpts.Save(dlg.FileName, savePwd);
}
catch(IOException)
{
MessageBox.Show(App.GetStr("Unable to save!"),
App.GetStr("Error"),
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
}
}
private void SaveConnOptsClicked(object sender, EventArgs e)
{
SaveConnOpts(false);
}
private void SaveConnOptsPwdClicked(object sender, EventArgs e)
{
SaveConnOpts(true);
}
private void LoadConnOptsClicked(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = App.GetStr("VNC files (*.vncxml)|*.vncxml|All files (*.*)|*.*");
if(dlg.ShowDialog() != DialogResult.OK)
return;
ConnOpts connOpts;
try
{
connOpts = new ConnOpts(dlg.FileName);
}
catch(FileNotFoundException)
{
MessageBox.Show(App.GetStr("Unable to open the file!"),
App.GetStr("Error"),
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
return;
}
catch(IOException)
{
MessageBox.Show(App.GetStr("Unable to read from the file!"),
App.GetStr("Error"),
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
return;
}
catch(XmlException)
{
MessageBox.Show(App.GetStr("The file is corrupted!"),
App.GetStr("Error"),
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
return;
}
catch(FormatException)
{
MessageBox.Show(App.GetStr("The file is corrupted!"),
App.GetStr("Error"),
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
return;
}
listenBox.Checked = connOpts.ConnMode == ConnMode.Passive;
if(connOpts.ConnMode == ConnMode.Active)
remoteEndPt.Text = connOpts.Host + "::" + connOpts.Port;
else
listenPortBox.Text = connOpts.Port.ToString();
passwdBox.Text = connOpts.Passwd;
SetOptions(connOpts.ViewOpts);
}
protected override void AddConnHistEntry(string entry)
{
recentBox.Items.Add(entry);
}
private void RecentBoxChanged(object sender, EventArgs e)
{
if(ConnMode == ConnMode.Active)
remoteEndPt.Text = recentBox.Text;
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
aboutBtn.Location = new Point(ClientRectangle.Right - App.DialogSpacing - aboutBtn.Width, ClientRectangle.Bottom - App.DialogSpacing - aboutBtn.Height);
cancelBtn.Location = new Point(aboutBtn.Left - App.DialogSpacing - cancelBtn.Width, ClientRectangle.Bottom - App.DialogSpacing - cancelBtn.Height);
okBtn.Location = new Point(cancelBtn.Left - App.DialogSpacing - okBtn.Width, cancelBtn.Top);
tabCtrl.Size = new Size(aboutBtn.Right - tabCtrl.Left, aboutBtn.Top - App.DialogSpacing - tabCtrl.Top);
remoteEndPt.Width = generalPage.ClientRectangle.Right - App.DialogSpacing - remoteEndPt.Left;
remoteEndPtLbl.Width = generalPage.ClientRectangle.Right - remoteEndPtLbl.Left;
passwdBox.Width = generalPage.ClientRectangle.Right - App.DialogSpacing - passwdBox.Left;
recentBox.Width = generalPage.ClientRectangle.Right - App.DialogSpacing - recentBox.Left;
recentBox.Height = generalPage.ClientRectangle.Bottom - App.DialogSpacing - recentBox.Top;
listenBox.Width = connModePage.ClientRectangle.Right - listenBox.Left;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?