gpt4 book ai didi

c# - 甚至不知道如何开始解决这个问题

转载 作者:行者123 更新时间:2023-11-30 15:46:32 25 4
gpt4 key购买 nike

这是客户要求我创建的模型: alt text

这是我在实际软件中拥有的:

alt text

问题是我需要能够从下面的控件中删除图片。我不知道如何解决这个问题。有任何指导吗?

这是我制作的自定义用户控件的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WebServiceScanner
{
public partial class selectablePicture : UserControl
{
public selectablePicture(Image image)
{
InitializeComponent();
ptbImage.BackgroundImage = image;
ptbImage.BackgroundImageLayout = ImageLayout.Zoom;
}

public Image GetImage()
{
return ptbImage.BackgroundImage;
}

public bool IsSelected()
{
return chkSelected.Checked;
}

public void DisableCheckbox()
{
this.chkSelected.Enabled = false;
}

private void ptbImage_Click(object sender, EventArgs e)
{
SelectControl();
ptbImage.Focus();
ToggleCheckBox();
}

private void selectablePicture_Click(object sender, EventArgs e)
{
SelectControl();
this.Focus();
ToggleCheckBox();
}

private void ToggleCheckBox()
{
if (!chkSelected.Enabled == false)
{
if (chkSelected.Checked)
{
chkSelected.Checked = false;
}
else
{
chkSelected.Checked = true;
}
}
}

private void chkSelected_Click(object sender, EventArgs e)
{
SelectControl();
chkSelected.Focus();
}

private void SelectControl()
{
if (!chkSelected.Enabled == false)
{
this.BackColor = Color.FromArgb(89, 168, 248);
}
}

private void chkSelected_Leave(object sender, EventArgs e)
{
DeSelectControl();
}

private void ptbImage_Leave(object sender, EventArgs e)
{
DeSelectControl();
}

private void selectablePicture_Leave(object sender, EventArgs e)
{
DeSelectControl();
}

private void DeSelectControl()
{
//If none of the controls inside the usercontrol have focus, set this control to white.
if (!chkSelected.Enabled == false)
{
if (!this.Focused && !this.ptbImage.Focused && !this.chkSelected.Focused)
{
this.BackColor = Color.White;
}
}
}
}
}

下面是我如何使用它:

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;

namespace WebServiceScanner
{
public partial class MainForm : Form
{
int pictureXPosition = 0;
List<selectablePicture> Images;

public MainForm()
{
InitializeComponent();
ptbNewestPicture.BackgroundImageLayout = ImageLayout.Zoom;
Images = new List<selectablePicture>();
}

private void button1_Click(object sender, EventArgs e)
{
LoadImageFromScanner();
}

private void scanToolStripMenuItem_Click(object sender, EventArgs e)
{
LoadImageFromScanner();
}

private void scanBatchToolStripMenuItem_Click(object sender, EventArgs e)
{
LoadBatchImagesFromScanner();
}

private void btnScanBatch_Click(object sender, EventArgs e)
{
LoadBatchImagesFromScanner();
}

private void connectionSettingsToolStripMenuItem_Click(object sender, EventArgs e)
{
ShowConfigurationForm();
}


private void LoadImageFromScanner()
{
selectablePicture picture = new selectablePicture(Image.FromFile(@"C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg"));
ptbNewestPicture.BackgroundImage = picture.GetImage();

picture.Location = new Point(pictureXPosition + panel1.AutoScrollPosition.X, 0);
panel1.Controls.Add(picture);
pictureXPosition += 130;
}

private void LoadBatchImagesFromScanner()
{
throw new NotImplementedException();
}

private void ShowConfigurationForm()
{
ConnectionSettingsForm connectionConfig = new ConnectionSettingsForm();
connectionConfig.ShowDialog();
}

private void btnDeleteSelected_Click(object sender, EventArgs e)
{
DeleteSelectedPictures();
}

private void DeleteSelectedPictures()
{
foreach (Control c in panel1.Controls)
{
if (((selectablePicture)c).IsSelected())
{
DisablePicture(c);
Images.Remove((selectablePicture)c);
}
}
}

private void DisablePicture(Control c)
{
c.BackColor = Color.Gray;
((selectablePicture)c).DisableCheckbox();
}
}
}

我考虑维护一个用户控件列表,并在每次发生变化时重新绘制整个列表,但这并不好,因为如果有很多图片会怎样?

有什么指导吗?

如果我想能够拖动和重新排列图片,我需要遵循哪些步骤?谢谢!

最佳答案

一种解决方案是根本不将它们呈现为控件,而是创建一个从左到右呈现缩略图的控件(根据是否选择来修改所选图像的呈现)。

删除图像现在是微不足道的,就是这样,删除。然后你就不用再担心了,它已经不在你的渲染列表中了。无需删除控件。

此自定义控件的开销会更少(每个图像使用 1 个控件与“N”个控件)。

您现在可以轻松实现许多其他优势,例如将效果应用于附近的图像等等。当然,这可以通过单独的控件来完成,但这样就不会那么麻烦了。

一些指标

N        = Total number of images
T_WIDTH = Thumbnail width
MARGIN_W = Margin you want either side of the thumbnail
CELL_W = T_WIDTH + (MARGIN_W * 2) (Total width of a cell that contains a thumbnail)

// Pseudo code here!!!
Scrollbar.Width = CELL_W * N
Scrollbar.PageWidth = Control.ClientWidth / CELL_W

开始渲染的图像索引

Scrollbar.Pos / CELL_W

请记住根据滚动条位置落在 CELL_W 内的位置偏移开始渲染的实际 x 位置。

关于c# - 甚至不知道如何开始解决这个问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4239864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com