留学狗作业做不出来!老师要求,有一个球队名单显示在主窗口,同时旁边附有三个按钮:修改,新增,删除。当选中一个球队,选中项会高亮,然后再选中旁边按钮选项,跳出另一个窗口做重命名或者修改的任务。
初学者:老师只教了label,textbox,button功能。
引用Microsoft.VisualBasic
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 Q759010
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
if (listBox1.SelectedItem != null)
listBox1.Items.Remove(listBox1.SelectedItem);
}
private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Add(Microsoft.VisualBasic.Interaction.InputBox("输入球队名", "新增"));
}
private void button1_Click(object sender, EventArgs e)
{
if (listBox1.SelectedItem != null)
listBox1.Items[listBox1.SelectedIndex] = Microsoft.VisualBasic.Interaction.InputBox("输入新的球队名", "修改", listBox1.SelectedItem.ToString());
}
}
}
以下是C#的代码 不明白的可以追问!
请采纳!
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 shuangji
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (listBox1.SelectedItem != null)
listBox1.Items.Remove(listBox1.SelectedItem);
}
private void btnAdd_Click(object sender, EventArgs e)
{
FormAdd f = new FormAdd();
f.Text = "增加";
f.ShowDialog();
listBox1.Items.Add(f.AddText);
}
private void btnEdit_Click(object sender, EventArgs e)
{
if (listBox1.SelectedItem != null)
{
FormAdd f = new FormAdd();
f.AddText = listBox1.Items[listBox1.SelectedIndex].Text;
f.Text = "修改";
f.ShowDialog();
listBox1.Items[listBox1.SelectedIndex] = f.AddText;
}
}
}
}