- 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 WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
-
- }
-
- private void button1_Click(object sender, EventArgs e)
- {
- try
- {
- string item = listBox1.SelectedItem.ToString();
- int i = listBox1.SelectedIndex;
- if (i == 0)
- return;
- listBox1.Items.Remove(listBox1.SelectedItem.ToString());
- listBox1.Items.Insert(i - 1, item);
- listBox1.SelectedIndex = i - 1;
- }
- catch (Exception)
- {
- MessageBox.Show("未选择项!");
- }
-
- }
-
- private void button2_Click(object sender, EventArgs e)
- {
- try
- {
- string item = listBox1.SelectedItem.ToString();
- int i = listBox1.SelectedIndex;
- if (i == listBox1.Items.Count - 1)
- return;
- listBox1.Items.Remove(listBox1.SelectedItem.ToString());
- listBox1.Items.Insert(i + 1, item);
- listBox1.SelectedIndex = i + 1;
- }
- catch (Exception)
- {
-
- MessageBox.Show("未选择项!");
- }
-
- }
- }
- }
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string item = listBox1.SelectedItem.ToString();
int i = listBox1.SelectedIndex;
if (i == 0)
return;
listBox1.Items.Remove(listBox1.SelectedItem.ToString());
listBox1.Items.Insert(i - 1, item);
listBox1.SelectedIndex = i - 1;
}
catch (Exception)
{
MessageBox.Show("未选择项!");
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
string item = listBox1.SelectedItem.ToString();
int i = listBox1.SelectedIndex;
if (i == listBox1.Items.Count - 1)
return;
listBox1.Items.Remove(listBox1.SelectedItem.ToString());
listBox1.Items.Insert(i + 1, item);
listBox1.SelectedIndex = i + 1;
}
catch (Exception)
{
MessageBox.Show("未选择项!");
}
}
}
}
|