- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
第一次发帖,长期阅读。
我目前正在通过“Head First C#”学习 C#(我正在学习封装和获取/设置属性)
我正在为 friend 编写一个处理图片的小程序,我只是想知道我的 PictureController 类是否正在沿着正确的方向前进?我的主要问题是我在这个类中设置了很多表单项,并且在类中继续引用表单项感觉很不自然,我在下面粘贴我的代码,如果你可以让我知道我在做什么如果有任何问题,我将不胜感激 :)
非常感谢!
PictureController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace PictureController
{
class PictureController
{
private int arrayPosition = 0;
private int numFiles = 0;
private string[,] arrayPictures;
public PictureBox myPictureBox;
public RadioButton myCopyButton;
public RadioButton myDeleteButton;
public TextBox mySource;
public ComboBox myDestinations;
private FolderBrowserDialog sourceFolder;
private FolderBrowserDialog destFolder;
public void InitialisePicture()
{
if (arrayPictures != null && arrayPictures.Length > 0)
{
myPictureBox.ImageLocation = arrayPictures[arrayPosition, 0];
}
else
{
MessageBox.Show("The folder you have selected contains no pictures...");
myPictureBox.ImageLocation = null;
}
}
public void NavigatePicture(int direction)
{
if (arrayPosition + direction >= 0 && arrayPosition + direction < numFiles)
{
arrayPosition += direction;
myPictureBox.ImageLocation = arrayPictures[arrayPosition, 0];
myCopyButton.Checked = Convert.ToBoolean(arrayPictures[arrayPosition, 1]);
myDeleteButton.Checked = Convert.ToBoolean(arrayPictures[arrayPosition, 2]);
}
}
public void UpdateActions(bool copyChecked, bool deleteChecked)
{
if (arrayPictures != null)
{
arrayPictures[arrayPosition, 1] = copyChecked.ToString();
arrayPictures[arrayPosition, 2] = deleteChecked.ToString();
}
}
public void GetFiles()
{
sourceFolder = new FolderBrowserDialog();
sourceFolder.ShowDialog();
if (sourceFolder.SelectedPath != "")
{
string[] arrayTempFiles = Directory.GetFiles(sourceFolder.SelectedPath,"*.jpg");
numFiles = arrayTempFiles.Length;
arrayPictures = new string[arrayTempFiles.Length,3];
for (int i = 0; i < arrayTempFiles.Length; i++)
{
arrayPictures[i, 0] = arrayTempFiles[i];
arrayPictures[i, 1] = "false";
arrayPictures[i, 2] = "false";
}
mySource.Text = sourceFolder.SelectedPath;
InitialisePicture();
}
}
public void AddDestinationFolder()
{
destFolder = new FolderBrowserDialog();
destFolder.ShowDialog();
if (destFolder.SelectedPath != "")
{
myDestinations.Items.Add(destFolder.SelectedPath);
}
}
}
}
Form1.cs
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 PictureController
{
public partial class Form1 : Form
{
PictureController PicControl;
public Form1()
{
InitializeComponent();
PicControl = new PictureController() { myPictureBox = pbPhoto, myCopyButton = rbMove, myDeleteButton = rbDelete, mySource = tbSource, myDestinations = cbDestination };
}
private void btnPrev_Click(object sender, EventArgs e)
{
PicControl.NavigatePicture(-1);
}
private void btnNext_Click(object sender, EventArgs e)
{
PicControl.NavigatePicture(1);
}
private void rbMove_CheckedChanged(object sender, EventArgs e)
{
if (rbMove.Checked || rbDelete.Checked)
{
PicControl.UpdateActions(rbMove.Checked, rbDelete.Checked);
}
}
private void rbDelete_CheckedChanged(object sender, EventArgs e)
{
if (rbMove.Checked || rbDelete.Checked)
{
PicControl.UpdateActions(rbMove.Checked, rbDelete.Checked);
}
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.A:
PicControl.NavigatePicture(-1);
break;
case Keys.D:
PicControl.NavigatePicture(1);
break;
case Keys.W:
rbMove.Checked = true;
break;
case Keys.S:
rbDelete.Checked = true;
break;
}
}
private void btnGetFiles_Click(object sender, EventArgs e)
{
PicControl.GetFiles();
}
private void btnProcess_Click(object sender, EventArgs e)
{
}
private void btnAddDest_Click(object sender, EventArgs e)
{
PicControl.AddDestinationFolder();
}
}
}
最佳答案
我看不出在您的 PictureController
类中使用控件的原因。您应该只在那里使用非表单数据类型并处理您的 Form
中的交互,提供来自您的 PictureController
类的事件和方法以对其使用react和操作。
关于C# - OOP - 我走在正确的轨道上吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4251110/
我想递归地遍历一个目录,但我希望 python 在遇到包含超过 100 个文件的目录时从任何单个 listdir 中断。基本上,我正在搜索 (.TXT) 文件,但我想避免使用包含大型 DPX 图像序列
我正在尝试遍历列表(例如 sql 行)并为每一行触发例程。问题是传递给函数的值不会在运行时进行评估,因此根据函数执行所需的时间,它可能会使用下一行中的任何值而不是当前行。 我知道我可以在普通函数中提取
我需要以毫秒为单位的时间来处理大量事务,因此我想要正确且快速的东西。下面的工作会做得最好吗? : iMilli := int((time.Nanoseconds() % 1e6) / 1e3
我有以下目录/文件设置(已简化): Ce +---top.txt +---X0.0 | | | +---Y0.0 | | | | |
我遇到了类似的问题: Connecting to Redis To Go with PHP 基本上,我在 redis 中有这个 uri: redis://myusername:foopassword@
我阅读了下面的主题 Go: multiple value in single-value context 但我不明白这个解释在我的案例中。可能是因为我想使用 interface 在下面的情况下,我得到
我有一个模板,我想使用 text/template 评估各个字段包裹。我很难弄清楚评估应该如何工作,因为下面的代码似乎失败了。模板包是否足够强大以处理此类评估? type something stru
我编写了简单的服务器程序来从客户端接收数据。我有点不明白有时我从函数中得到错误 read tcp4 IP:PORT i/o timeoutint, err := conn.Read([]byte) 未
我只需要解码和更新 json 对象的特定值。问题是我不知道对象的完整结构。 encoding/json 包“忽略”/截断结构中未提供的字段,因此在编码时这些字段将丢失。 我想知道是否可以只解码我知道的
我正在尝试使用带有 C++ 目标的 ANTLR4 来实现 TSql 解析器。我抓取了语法文件 here .该jar用于制作相应的源文件(因冲突将TSqlParser.cpp中的NULL全部改为null
我在 win7 中使用 python 3.3.3 - 我只想列出网络目录中的所有文件。 import os for root, dirs, files in os.walk("X:\\network\
当我运行 go 脚本 ( go run example.go ) 时出现此错误 /home/travis/.gvm/gos/go1.1.2/src/pkg/github.com/user/exampl
我正在尝试通过 gmail API 发送电子邮件使用 Go但我发现文档非常有缺陷/令人困惑。这一次我看不到收据字段和电子邮件正文。 我不需要上传任何东西,所以我找到了 Simple upload ,
本人是一名专业的windows/.Net开发者,一直在慢慢学习rails/ruby/python/etc。在我有空的时候。在过去 8 年左右的时间里,我也一直在使用各种 Linux 发行版。然而,有一
我想知道是否可以使用 std http 来响应 http 请求打包并仍然保持 go 例程事件(例如运行任务密集型任务)。用例是我需要接收一个 http 请求,然后在几分钟后回调该服务 最佳答案 只需从
我想知道关于指针的最佳实践是什么。我应该在结构上还是在其字段上定义它们。我虽然定义一个指向结构本身的指针是有意义的,但这里有一个我觉得很有趣的例子。如果所有字段都是指针,为什么我不应该使用指向整个结构
我是一名优秀的程序员,十分优秀!