我已经尝试了几个小时但是无法让它工作,我必须使用c#中的面板和按钮实现二进制搜索树到目前为止我所做的是从文本区域输入并创建一个带有文本的按钮它的价值,现在我必须以层次结构的方式显示按钮来制作树。我很困惑我可以使用什么工具来完成我的任务,我刚开始使用C#昨天我对它没有多少了解。关于这个主题的更多指导将对我有很大帮助谢谢,这里是迄今为止的代码!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string value;
int z=30;
int y=100;
List<Panel> ls = new List<Panel>();
Button main = new Button();
public Form1()
{
InitializeComponent();
}
private void retrieveInput_Click(object sender, EventArgs e)
{
value = this.inputText.Text;
long number1= 0;
bool canConvert = long.TryParse(value, out number1);
if (canConvert == true)
{
Button button1 = new Button();
Panel pan = new Panel();
ls.Add(pan);
pan.Location = new Point(10, z * 100);
pan.Size = new Size(200, 90); // just an example
this.Controls.Add(pan);
button1.Click +=(Onb2Click);
button1.Text = value;
button1.Width = 100;//this.Width - 10;
button1.Height = 30;
pan.Controls.Add(button1);
pan.Location = new Point(10, z * 100);
z = z + 30;
pan.Size = new Size(200, 90); // just an example
this.Controls.Add(pan);
panel1.Controls.Add(pan);
}
else
{
// Console.WriteLine("numString is not a valid long");
}
}
private void inputText_TextChanged(object sender, EventArgs e)
{
value = this.inputText.Text;
// retrieveInput_Click(object sender, EventArgs e);
}
void Onb2Click(object sender, EventArgs e)
{
}
private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e)
{
z++;
y++;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
}
}
答案 0 :(得分:2)
我建议您改用TreeView
控件。
更容易处理父子显示流程