本文介绍了在C#中使用listbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的用户,我是C#的新手。我有一个病理学项目,我被要求以编程方式将诊断测试添加到某个地方(如listbox,datagridview或Listview)&根据选择的测试,我需要在A4纸上打印(A4纸上已添加页眉和页脚)。我在表单中添加了文本框,下拉菜单(我选择了listbox1)。问题是,当我添加医生名称&列表框中单行中的患者姓名,患者姓名在极端角落移位(如果医生姓名足够长)&不会留在我要求它坐的位置。因此我搜索它以查找是否可以使用X或Y坐标在列表框中插入文本但无效。我现在很沮丧。我还尝试使用其他控件,如datagridview或Listview,但他们需要获取不符合我的项目要求的特定列名称。请帮我。示例代码如下所示。

Dear users, I am new to C#. I have a project on pathology where i have been asked to add diagnostics tests programatically into somewhere (like listbox, datagridview or Listview) & based on the test choosed I need to print it on A4 paper (the A4 paper has header & footer added already on page). I have added text boxes, drop-down menus to my form ( I choosed listbox1). The problem is that when I add "Doctor name" & "Patient name" in a single line in listbox, the patient name shifts at extreme corner (if doctor name is long enough) & does not remain at the position where I ask it to sit. Hence I googled it to find if we can insert text in listbox using X or Y coordinates but no to avail. I am frustated now. I also tried to use other controls like datagridview or Listview but they need to get specific columns names which does not meet my project requirements. Please help me. The sample code is as below.

private void btn_patient_add_Click(object sender, EventArgs e)
{
listBox1.Items.Add(lbl_patient_name.Text + " " + comboBox1.Text + " " + txtbox_patient.Text + "                                                                                " + lbl_age.Text+" "+cbox_age.Text+"/"+cbox_sex.Text);
listBox1.Items.Add("\n");
listBox1.Items.Add(lbl_ref.Text+" "+cbox_ref.Text+ " "+txtbox_date.Text);
listBox1.Items.Add("\n");
listBox1.Items.Add("__________________________________________________________________________________________________");
//listBox1.Items.Insert(10, "First");
}

推荐答案


这篇关于在C#中使用listbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 15:36