📄 photospane.cs
字号:
// miDel
//
this.miDel.Index = 15;
this.miDel.Shortcut = System.Windows.Forms.Shortcut.Del;
this.miDel.Text = "删除";
this.miDel.Click += new System.EventHandler(this.miDel_Click);
//
// miRen
//
this.miRen.Index = 16;
this.miRen.Shortcut = System.Windows.Forms.Shortcut.F2;
this.miRen.Text = "重命名";
this.miRen.Click += new System.EventHandler(this.miRen_Click);
//
// menuItem9
//
this.menuItem9.Index = 17;
this.menuItem9.Text = "-";
//
// miPInfo
//
this.miPInfo.Index = 18;
this.miPInfo.Text = "图片信息";
this.miPInfo.Click += new System.EventHandler(this.miPInfo_Click);
//
// ilThumbs
//
this.ilThumbs.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
this.ilThumbs.ImageSize = new System.Drawing.Size(150, 113);
this.ilThumbs.TransparentColor = System.Drawing.Color.Transparent;
//
// paneTitle
//
this.paneTitle.Active = false;
this.paneTitle.Dock = System.Windows.Forms.DockStyle.Top;
this.paneTitle.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Bold);
this.paneTitle.Location = new System.Drawing.Point(0, 0);
this.paneTitle.Name = "paneTitle";
this.paneTitle.Size = new System.Drawing.Size(264, 20);
this.paneTitle.TabIndex = 2;
//
// ttPhotoInfo
//
this.ttPhotoInfo.AutoPopDelay = 5000;
this.ttPhotoInfo.InitialDelay = 500;
this.ttPhotoInfo.ReshowDelay = 500;
//
// timerToolTip
//
this.timerToolTip.Tick += new System.EventHandler(this.timerToolTip_Tick);
//
// PhotosPane
//
this.Controls.Add(this.paneTitle);
this.Controls.Add(this.lvPhotos);
this.Name = "PhotosPane";
this.Size = new System.Drawing.Size(264, 344);
this.Resize += new System.EventHandler(this.PhotosPane_Resize);
this.Enter += new System.EventHandler(this.PhotosPane_Enter);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.PhotosPane_KeyDown);
this.Leave += new System.EventHandler(this.PhotosPane_Leave);
this.ResumeLayout(false);
}
#endregion
private void PhotosPane_Resize(object sender, System.EventArgs e) {
lvPhotos.Width = this.Width;
lvPhotos.Height = this.Height - paneTitle.Height;
}
private void PhotosPane_Enter(object sender, System.EventArgs e) {
paneTitle.Active = true;
}
private void PhotosPane_Leave(object sender, System.EventArgs e) {
paneTitle.Active = false;
}
private void lvPhotos_SelectedIndexChanged(object sender, System.EventArgs e) {
if (Deleting != true && _Album != null) // i hope we are not currently deleting anything
{
// clear the selected photos list, update it and fire the selection changed event
SelPhotos.Clear();
foreach (int i in lvPhotos.SelectedIndices)
SelPhotos.Add(_Album.Photos[i]);
if (SelPhotos != null)
SelectedPhotosChanged(SelPhotos);
}
}
private void lvPhotos_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
if (e.Button == MouseButtons.Right)
contMenu.Show(lvPhotos, new Point(e.X, e.Y));
}
private void miOpen_Click(object sender, System.EventArgs e) {
OpenPhotoEditor();
}
private void miSlideSh_Click(object sender, System.EventArgs e) {
StartSlideShow();
}
private void miSelAll_Click(object sender, System.EventArgs e) {
foreach (ListViewItem i in lvPhotos.Items)
i.Selected = true;
}
private void miRLeft_Click(object sender, System.EventArgs e) {
RotateLeft();
}
private void miRRight_Click(object sender, System.EventArgs e) {
RotateRight();
}
private void miDel_Click(object sender, System.EventArgs e) {
if (Editing == false)
DeletePhoto();
}
private void miRen_Click(object sender, System.EventArgs e) {
RenamePhoto();
}
private void miPInfo_Click(object sender, System.EventArgs e) {
Dialogs.ImageInfoDialog ifd = new VirtualPhotoOrganizer.Dialogs.ImageInfoDialog(_Album, lvPhotos.SelectedIndices[0]);
ifd.Show();
}
private void contMenu_Popup(object sender, System.EventArgs e) {
if (lvPhotos.SelectedIndices.Count > 0) {
miOpen.Enabled = true;
miRLeft.Enabled = true;
miRRight.Enabled = true;
miDel.Enabled = true;
miRen.Enabled = true;
miPInfo.Enabled = true;
miPrint.Enabled = true;
miCopy.Enabled = true;
miCut.Enabled = true;
} else {
miOpen.Enabled = false;
miRLeft.Enabled = false;
miRRight.Enabled = false;
miDel.Enabled = false;
miRen.Enabled = false;
miPInfo.Enabled = false;
miPrint.Enabled = false;
miCopy.Enabled = false;
miCut.Enabled = false;
}
if (lvPhotos.Items.Count == 0) {
miSlideSh.Enabled = false;
miHTMLExp.Enabled = false;
miSelAll.Enabled = false;
miRenReo.Enabled = false;
} else {
miSlideSh.Enabled = true;
miHTMLExp.Enabled = true;
miSelAll.Enabled = true;
miRenReo.Enabled = true;
}
}
private void lvPhotos_AfterLabelEdit(object sender, System.Windows.Forms.LabelEditEventArgs e) {
if (e.Label != "" && e.Label != TitleBuffer) {
_Album.Photos[e.Item].Title = e.Label; // change the title of the current photo
AttemptSave(e); // attempt to save the album
} else
e.CancelEdit = true;
Editing = false;
}
private void lvPhotos_DoubleClick(object sender, System.EventArgs e) {
OpenPhotoEditor();
}
private void lvPhotos_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) {
miDel.Enabled = true;
if (e.KeyCode == Keys.Enter)
OpenPhotoEditor();
}
private void miHTMLExp_Click(object sender, System.EventArgs e) {
DoHTMLExport();
}
private void lvPhotos_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) {
MousePos.X = e.X;
MousePos.Y = e.Y;
timerToolTip.Enabled = false;
timerToolTip.Enabled = true;
}
private void lvPhotos_DragEnter(object sender, System.Windows.Forms.DragEventArgs e) {
if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false) == false)
e.Effect = DragDropEffects.Move;
else
e.Effect = DragDropEffects.None;
}
private void lvPhotos_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) {
// abort the operation if if no ListViewItem was selected
if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false) == true) {
// redraw lvPhotos
lvPhotos.Refresh();
// reset CurrItemIndex
CurrItemIndex = -1;
// destroy the gdi+ objects
PPrev.Brush.Dispose();
PPrev.Dispose();
GlvPhotos.Dispose();
return;
}
// get the current scroll bar info
ScrollInfo sbInf = new ScrollInfo();
sbInf.cbSize = (uint) Marshal.SizeOf(sbInf);
sbInf.fMask = 0x0004;
GetScrollInfo(lvPhotos.Handle, 0x1, ref sbInf);
// get the new location of the items
MousePos.X = e.X;
MousePos.Y = e.Y;
MousePos = lvPhotos.PointToClient(MousePos);
int destIndex = GetDestIndex();
if (destIndex == _Album.Photos.Count && lvPhotos.SelectedIndices[lvPhotos.SelectedIndices.Count - 1] == _Album.Photos.Count - 1)
destIndex--;
// create a new ListViewItems array
int[] selIndices = new int[lvPhotos.SelectedIndices.Count];
bool canAbort = true;
for (int i = 0; i < selIndices.Length; i++) {
if (i > 0) {
// if not all photos between selIndices[0] and selIndices[selIndices.Length - 1] have been seleceted do not abort the operation
if (lvPhotos.SelectedIndices[i] - lvPhotos.SelectedIndices[i - 1] > 1)
canAbort = false;
}
if (lvPhotos.SelectedIndices[i] == destIndex && canAbort == true) // if any of the selectedIndices is equal to the destIndex abort the operation
{
// redraw lvPhotos
lvPhotos.Refresh();
// reset CurrItemIndex
CurrItemIndex = -1;
// destroy the gdi+ objects
PPrev.Brush.Dispose();
PPrev.Dispose();
GlvPhotos.Dispose();
return;
}
// add the current selectedIndex to the selIndices array
selIndices[i] = lvPhotos.SelectedIndices[i];
}
// rearrange the photos in the album and break the operation if it can't be saved
if (DoAlbumDragDrop(selIndices, destIndex) == false) {
// redraw lvPhotos
lvPhotos.Refresh();
// reset CurrItemIndex
CurrItemIndex = -1;
// destroy the gdi+ objects
PPrev.Brush.Dispose();
PPrev.Dispose();
GlvPhotos.Dispose();
return;
}
// create a temp ImageCollection and a temp image array
ImageCollection icTemp = new ImageCollection();
Image[] tempImages = new Image[selIndices.Length];
// fill the temp ic with the images from ilThumbs
foreach (Image i in ilThumbs.Images)
icTemp.Add(i);
// fill the tempImages array with the images that are supposed to be moved
for (int i = 0; i < selIndices.Length; i++)
tempImages[i] = ilThumbs.Images[selIndices[i]];
// delete the old images
for (int i = 0; i < selIndices.Length; i++) {
if (selIndices[i] < destIndex)
destIndex--;
icTemp.RemoveAt(selIndices[i] - i);
}
// reinsert the tempImages at destIndex
for (int i = tempImages.Length - 1; i >= 0; i--)
icTemp.Insert(destIndex, tempImages[i]);
// clear ilThumbs and refill it
ilThumbs.Images.Clear();
if (icTemp.Count == lvPhotos.Items.Count) {
foreach (Image i in icTemp)
ilThumbs.Images.Add(i);
}
// rearrange the items in the lv
ReloadAlbum();
for (int i = destIndex; i < destIndex + selIndices.Length; i++)
lvPhotos.Items[i].Selected = true;
// redraw lvPhotos
lvPhotos.Refresh();
// reset CurrItemIndex
CurrItemIndex = -1;
// destroy the gdi+ objects
PPrev.Brush.Dispose();
PPrev.Dispose();
GlvPhotos.Dispose();
// reset the scroll bar
SetScrollInfo(lvPhotos.Handle, 0x1, ref sbInf, true);
}
private void lvPhotos_BeforeLabelEdit(object sender, System.Windows.Forms.LabelEditEventArgs e) {
Editing = true;
TitleBuffer = e.Label;
}
private void timerToolTip_Tick(object sender, System.EventArgs e) {
ListViewItem item = lvPhotos.GetItemAt(MousePos.X, MousePos.Y);
if (item != null) {
int itemIndex = item.Index;
if (itemIndex != CurrItemIndex) {
string information;
PhotoInfo pi = new PhotoInfo(this.Album, itemIndex);
if (ShowImgRes == true) // only show the image res if requested
{
Image img = Bitmap.FromFile(pi.PhotoPath);
information = String.Concat(pi.PhotoTitle, '\n', pi.ImageType, '\n', pi.FileSizeStr, '\n', img.Width.ToString(), " x ", img.Height.ToString(), ' ', LsPixels, '\n', pi.TimeTaken);
img.Dispose();
} else
information = String.Concat(pi.PhotoTitle, '\n', pi.ImageType, '\n', pi.FileSizeStr, '\n', pi.TimeTaken);
ttPhotoInfo.SetToolTip(lvPhotos, information);
CurrItemIndex = itemIndex;
}
} else {
CurrItemIndex = -1;
ttPhotoInfo.RemoveAll();
}
}
private void lvPhotos_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e) {
if (lvPhotos.SelectedItems.Count < lvPhotos.Items.Count) {
// create the gdi+ objects necessary for previewing the drag&drop destination
PPrev = new Pen(new SolidBrush(Color.Black), 3);
GlvPhotos = lvPhotos.CreateGraphics();
// get the itemOffset
try { ItemOffset = (int) Math.Round((double) (lvPhotos.Items[1].Bounds.Left - lvPhotos.Items[0].Bounds.Right), 0); }
catch { ItemOffset = 10; }
// start the drag&drop operation
lvPhotos.DoDragDrop(lvPhotos.SelectedItems, DragDropEffects.All);
}
}
private void lvPhotos_DragOver(object sender, System.Windows.Forms.DragEventArgs e) {
MousePos.X = e.X;
MousePos.Y = e.Y;
MousePos = lvPhotos.PointToClient(MousePos);
if (MousePos.Y > lvPhotos.Height - 10)
SendMessage(lvPhotos.Handle, 0x0115, 1, 0);
else
if (MousePos.Y < 10)
SendMessage(lvPhotos.Handle, 0x0115, 0, 0);
if (GlvPhotos != null)
PreviewDragDrop();
}
private void miPrint_Click(object sender, System.EventArgs e) {
PrintSelectedPhotos();
}
private void miRenTime_Click(object sender, System.EventArgs e) {
this.RenamePhotosAccToTime();
}
private void miReoAZ_Click(object sender, System.EventArgs e) {
RearrangePhotosAZ();
}
private void miReoZA_Click(object sender, System.EventArgs e) {
RearrangePhotosZA();
}
private void miReoChro_Click(object sender, System.EventArgs e) {
RearrangePhotosChro();
}
private void VPOClipboard_ClipboardChanged(int count) {
if (count > 0)
miPaste.Enabled = true;
else
miPaste.Enabled = false;
}
private void miCut_Click(object sender, System.EventArgs e) {
CutToClipboard();
}
private void miCopy_Click(object sender, System.EventArgs e) {
CopyToClipboard();
}
private void miPaste_Click(object sender, System.EventArgs e) {
PasteFromClipboard();
}
private void PhotosPane_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) {
miCopy.Enabled = true;
miCut.Enabled = true;
if (e.Control == true)
CtrlDown = true;
}
private void lvPhotos_DragLeave(object sender, System.EventArgs e) {
lvPhotos.Refresh();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -