c# - 未调用 C# 按钮事件
问题描述
为非常长的代码道歉。我的两个按钮 taskpagebackbtn 和 taskpagenextbtn 似乎没有被调用。我设置了一个消息框,但它没有显示,但我不确定为什么没有调用它们,因为当我打开表单时,当我单击按钮时,它们似乎不起作用。
public partial class Task_Page : Form
{
TextBox[] subjectnamearray { get; set; }
List<string> datatablesubjectnamearray { get; set; }
int numofsubjects { get; set; }
public Task_Page(TextBox[] subjectnamearray, List<string> datatablesubjectnamearray, int numofsubjects)
{
InitializeComponent();
numoftasks.SelectedIndexChanged += (sender2, e2) => numoftasks_SelectedIndexChanged(sender2, e2,subjectnamearray, datatablesubjectnamearray, numofsubjects);
}
private void taskpagebackbtn_Click(object sender, EventArgs e)
{
this.Hide();
var SubjectPage = new SubjectPage();
SubjectPage.Closed += (s, args) => this.Close();
SubjectPage.Show();
SubjectPage.StartPosition = FormStartPosition.Manual;
SubjectPage.Location = new Point(this.Location.X, this.Location.Y);
}
private void taskpagenextbtn_Click(object sender, EventArgs e)
{
Marks_and_Weighting_Table marksandweightingtable = new Marks_and_Weighting_Table(subjectnamearray, datatablesubjectnamearray, numofsubjects);
foreach (Control control in this.Controls)
{
if (control is TextBox)
{
if (control.Text.Trim() == string.Empty)
{
MessageBox.Show("Please fill out all textboxes.", "Error Message");
/*https://www.codeproject.com/Questions/496674/EmptyplusTextboxplusValidationplusinplusC*/
return;
}
}
}
this.Hide();
var MarksandWeightingTable = new Marks_and_Weighting_Table(subjectnamearray, datatablesubjectnamearray, numofsubjects);
MarksandWeightingTable.Closed += (s, args) => this.Close();
MarksandWeightingTable.Show();
MarksandWeightingTable.StartPosition = FormStartPosition.Manual;
MarksandWeightingTable.Location = new Point(this.Location.X, this.Location.Y);
}
private void numoftasks_SelectedIndexChanged(object sender, EventArgs e, TextBox[] subjectnamearray, List<string> datatablesubjectnamearray, int numofsubjects)
{
lblsubjectname1.Text = subjectnamearray[0].Text;
lblsubjectname2.Text = subjectnamearray[1].Text;
lblsubjectname3.Text = subjectnamearray[2].Text;
lblsubjectname4.Text = subjectnamearray[3].Text;
lblsubjectname5.Text = subjectnamearray[4].Text;
lblsubjectname6.Text = subjectnamearray[5].Text;
/*https://stackoverflow.com/questions/2916684/c-sharp-net-change-label-text*/
解决方案
推荐阅读
- c# - 如何在简单的计算器中将 Console.ReadLine() 转换为 double ?C# 异常问题
- firebase - Bigquery crashlytics 数据集计划间隔
- python - 将新值分配给特定索引处的张量
- python - 如何在 Django admin 中将内联 ForeignKey 查询集限制为实例本身
- intellij-idea - Intellij Idea 调试无法访问 maven 存储库:连接被拒绝
- javascript - 从图像 url 创建文件对象
- ios - 如何将 iphone 连接到在 mac 上运行的本地服务器?
- package - PSM 封装的替代方案
- python - 为什么这个url不能用python打开,而是可以直接从浏览器打开?
- migration - TYPO3 9.5:RealURL - 简单 GetVars 的迁移