本文介绍了如何从C#windows应用程序中的图片框中的当前选择移动上一个和下一个图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在c#windows应用程序中从所选图像的当前位置单击下一个和上一个按钮时移动下一个和上一个。说出解决方案。
I want to move next and previous when i click next and previous button from the current position of selected image in c# windows application. Say the solution for that.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Collections;
using System.Net;
using System.Web;
using MSaddin;
namespace MSaddin
{
public partial class formDisplay : Form
{
int locX = 15;
int locY = 20;
int sizeWidth = 140;
int sizeHeight = 135;
public formDisplay()
{
InitializeComponent();
DynamciLabel();
}
private void butView_Click(object sender, EventArgs e)
{
DirectoryInfo Folder;
FileInfo[] Images;
Folder = new DirectoryInfo(@"C:\Users\Public\Pictures\Sample Pictures");
Images = Folder.GetFiles();
panelDisplay.Controls.Clear();
int locnewX = locX;
int locnewY = locY;
foreach (FileInfo img in Images)
{
if (img.Extension.ToLower() == ".png" || img.Extension.ToLower() == ".jpg" || img.Extension.ToLower() == ".gif" || img.Extension.ToLower() == ".jpeg" || img.Extension.ToLower() == ".bmp" || img.Extension.ToLower() == ".tif")
{
if (locnewX >= panelDisplay.Width - sizeWidth - 10)
{
locnewX = locX;
locY = locY + sizeHeight + 30;
locnewY = locY;
}
else
{
locnewY = locY;
}
loadImagestoPanel(img.Name, img.FullName, locnewX, locnewY);
locnewY = locY + sizeHeight + 10;
locnewX = locnewX + sizeWidth + 30;
}
}
imagescount(Images.Length - 1);
}
private void butImage_Click(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(panelDisplay.Width, panelDisplay.Height);
panelDisplay.DrawToBitmap(bmp, new Rectangle(0, 0, panelDisplay.Width, panelDisplay.Height));
SaveFileDialog dlg = new SaveFileDialog();
// dlg.Filter = "JPG Files (*.JPG)|*.JPG";
dlg.FileName = "*";
dlg.DefaultExt = "bmp";
dlg.ValidateNames = true;
dlg.Filter = "Bitmap Image (.bmp)|*.bmp|Gif Image (.gif)|*.gif |JPEG Image (.jpeg)|*.jpeg |Png Image (.png)|*.png";
if (dlg.ShowDialog() == DialogResult.OK)
{
pictureDisplay.Image.Save(dlg.FileName);
}
}
private void DynamciLabel()
{
Label lab = new Label();
lab.Text = "Photogallery";
lab.Size = new Size(370, 50);
lab.Location = new Point(495, 16);
lab.Font = new Font("Times New Roman", 25);
lab.ForeColor = Color.White;
lab.AutoSize = false;
lab.TextAlign = ContentAlignment.MiddleLeft;
Color clr = Color.FromArgb(3, 186, 217);
lab.BackColor = clr;
Controls.Add(lab);
}
private void loadImagestoPanel(String imageName, String ImageFullName, int newLocX, int newLocY)
{
PictureBox ctrl = new PictureBox();
ctrl.Image = Image.FromFile(ImageFullName);
ctrl.BackColor = Color.White;
ctrl.Location = new Point(newLocX, newLocY);
ctrl.Size = new System.Drawing.Size(sizeWidth+20, sizeHeight+20);
ctrl.Padding = new System.Windows.Forms.Padding(10,20,10,20);
ctrl.BorderStyle = BorderStyle.None;
ctrl.SizeMode = PictureBoxSizeMode.StretchImage;
ctrl.
推荐答案
这篇关于如何从C#windows应用程序中的图片框中的当前选择移动上一个和下一个图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!