📄 addalbumdialog.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using VirtualPhotoOrganizer.Util;
using TXML;
namespace VirtualPhotoOrganizer.Dialogs
{
/// <summary>
/// Used for adding an empty album to the root album
/// </summary>
internal class AddAlbumDialog : System.Windows.Forms.Form
{
// that's the only two global lang string we need
private string lsNewAlbum;
private string lsAlbumName;
// a lanugae string
private string LsExists;
// the albumName and albumPath strings
private string _AlbumName;
private string _AlbumPath;
private System.Windows.Forms.FolderBrowserDialog fbd;
private System.Windows.Forms.TextBox tbPath;
private System.Windows.Forms.Button bBrowse;
private System.Windows.Forms.Button bOK;
private System.Windows.Forms.Button bCancel;
private System.Windows.Forms.TextBox tbAlbumName;
private System.Windows.Forms.Label lbAlbumName;
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.Container components = null;
public AddAlbumDialog() {
//
// Erforderlich f黵 die Windows Form-Designerunterst黷zung
//
InitializeComponent();
// LoadLanguageStrings();
string albumPath = GetDefaultFolder();
tbPath.Text = albumPath;
tbAlbumName.Text = lsNewAlbum;
}
/// <summary>
/// Die verwendeten Ressourcen bereinigen.
/// </summary>
protected override void Dispose(bool disposing) {
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
private void LoadLanguageStrings() {
string lsTitle;
string lsBrowse;
string lsOK;
string lsCancel;
const string MN = "AddAlbumDialog";
try {
TXML.TXmlReader reader = XmlHandler.OpenLangFile();
lsTitle = reader.GetString(MN, "Title", "Add Album");
lsBrowse = reader.GetString(MN, "Browse", "Browse");
lsOK = reader.GetString(MN, "OK", "OK");
lsCancel = reader.GetString(MN, "Cancel", "Cancel");
lsNewAlbum = reader.GetString(MN, "NewAlbum", "NewAlbum");
lsAlbumName = reader.GetString(MN, "AlbumName", "Album name:");
LsExists = reader.GetString(MN, "Exists", "An album with that name already exists, please choose a different name!");
reader.Close();
}
catch {
lsTitle = "Add Album";
lsBrowse = "Browse";
lsOK = "OK";
lsCancel = "Cancel";
lsNewAlbum = "NewAlbum";
lsAlbumName = "Album name:";
LsExists = "An album with that name already exists, please choose a different name!";
}
this.Text = lsTitle;
this.lbAlbumName.Text = lsAlbumName;
bBrowse.Text = lsBrowse;
bOK.Text = lsOK;
bCancel.Text = lsCancel;
}
/// <summary>
/// returns the default folder for the new album
/// </summary>
/// <returns></returns>
private string GetDefaultFolder() {
/* keep probing the defaultAlbumFolder for the suggested directory name, while increasing
* the number at the end by 1 every turn*/
Settings settings = new Settings();
int i = 1;
string albumName = settings.DefaultAlbumFolder + '\\' + lsNewAlbum + i.ToString();
while (Directory.Exists(albumName)) {
i++;
albumName = settings.DefaultAlbumFolder + '\\' + lsNewAlbum + i.ToString();
}
return albumName;
}
public string AlbumPath {
get { return _AlbumPath; }
}
public string AlbumName {
get { return _AlbumName; }
}
/// <summary>
/// Removes the directories from a given path and returnes only the file name
/// </summary>
private string GetFileNameFromPath(string path) {
int i = 0;
for (i = path.Length - 1; i > 0; i--) {
if (path[i] == '\\')
break;
}
if (i != 0 && i != (path.Length - 1))
return path.Substring(i + 1, path.Length - 1);
else
return "";
}
#region Vom Windows Form-Designer generierter Code
/// <summary>
/// Erforderliche Methode f黵 die Designerunterst黷zung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor ge鋘dert werden.
/// </summary>
private void InitializeComponent() {
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(AddAlbumDialog));
this.bOK = new System.Windows.Forms.Button();
this.bCancel = new System.Windows.Forms.Button();
this.fbd = new System.Windows.Forms.FolderBrowserDialog();
this.tbPath = new System.Windows.Forms.TextBox();
this.bBrowse = new System.Windows.Forms.Button();
this.tbAlbumName = new System.Windows.Forms.TextBox();
this.lbAlbumName = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// bOK
//
this.bOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.bOK.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.bOK.Location = new System.Drawing.Point(470, 121);
this.bOK.Name = "bOK";
this.bOK.Size = new System.Drawing.Size(90, 24);
this.bOK.TabIndex = 0;
this.bOK.Text = "创建相册";
//
// bCancel
//
this.bCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.bCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.bCancel.Location = new System.Drawing.Point(576, 121);
this.bCancel.Name = "bCancel";
this.bCancel.Size = new System.Drawing.Size(90, 24);
this.bCancel.TabIndex = 1;
this.bCancel.Text = "取消创建";
//
// tbPath
//
this.tbPath.Location = new System.Drawing.Point(10, 69);
this.tbPath.Name = "tbPath";
this.tbPath.Size = new System.Drawing.Size(566, 21);
this.tbPath.TabIndex = 3;
this.tbPath.Text = "";
this.tbPath.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbPath_KeyDown);
this.tbPath.TextChanged += new System.EventHandler(this.tbPath_TextChanged);
//
// bBrowse
//
this.bBrowse.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.bBrowse.Location = new System.Drawing.Point(595, 69);
this.bBrowse.Name = "bBrowse";
this.bBrowse.Size = new System.Drawing.Size(90, 25);
this.bBrowse.TabIndex = 4;
this.bBrowse.Text = "浏览";
this.bBrowse.Click += new System.EventHandler(this.bBrowse_Click);
//
// tbAlbumName
//
this.tbAlbumName.Location = new System.Drawing.Point(154, 26);
this.tbAlbumName.Name = "tbAlbumName";
this.tbAlbumName.Size = new System.Drawing.Size(220, 21);
this.tbAlbumName.TabIndex = 2;
this.tbAlbumName.Text = "";
this.tbAlbumName.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tbAlbumName_KeyDown);
this.tbAlbumName.TextChanged += new System.EventHandler(this.tbAlbumName_TextChanged);
//
// lbAlbumName
//
this.lbAlbumName.Location = new System.Drawing.Point(19, 26);
this.lbAlbumName.Name = "lbAlbumName";
this.lbAlbumName.Size = new System.Drawing.Size(120, 25);
this.lbAlbumName.TabIndex = 5;
this.lbAlbumName.Text = "相册名称:";
//
// AddAlbumDialog
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(703, 191);
this.ControlBox = false;
this.Controls.Add(this.lbAlbumName);
this.Controls.Add(this.tbAlbumName);
this.Controls.Add(this.tbPath);
this.Controls.Add(this.bBrowse);
this.Controls.Add(this.bCancel);
this.Controls.Add(this.bOK);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "AddAlbumDialog";
this.Text = "创建新相册";
this.ResumeLayout(false);
}
#endregion
private void bBrowse_Click(object sender, System.EventArgs e) {
if (fbd.ShowDialog() == DialogResult.OK)
tbPath.Text = fbd.SelectedPath;
}
private void tbAlbumName_TextChanged(object sender, System.EventArgs e) {
_AlbumName = tbAlbumName.Text;
}
private void tbPath_TextChanged(object sender, System.EventArgs e) {
_AlbumPath = tbPath.Text;
}
private void tbAlbumName_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) {
if (e.KeyCode == Keys.Enter)
this.DialogResult = DialogResult.OK;
}
private void tbPath_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) {
if (e.KeyCode == Keys.Enter)
this.DialogResult = DialogResult.OK;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -