本文目錄一覽:
- 1、C++ LISTBOX具體用法
- 2、C 語言如何改變LISTBOX的顏色
- 3、c #listbox 的內容怎麼複製
- 4、請問C#控件中listBox怎麼賦值呀?是listBox.Text=”” 嗎?
- 5、用C#語言ListBox和MessageBox關聯的問題
C++ LISTBOX具體用法
CString t;
int i;
for(i=65;i70;i++)
{
t.Format(“%c”,i);
m_lst.AddString(t);//m_lst是控件變量
}
C 語言如何改變LISTBOX的顏色
在列表框所在的對話框里處理WM_CTLCOLORLISTBOX消息,並返回一個有顏色的刷子(HBRUSH)。
//這是MFC下的
HBRUSH CTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
// HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
static HBRUSH hbr=NULL;
if(hbr==NULL)
{
//創建紅色刷子
hbr=CreateSolidBrush(RGB(255,0,0));
}
//如果是列表框
if(pWnd-GetDlgCtrlID()==IDC_LIST1)
{
pDC-SetBkMode(TRANSPARENT);
return hbr;
}
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
//不用MFC的話思路是也一樣的。
//如果還不行直接找我!!
c #listbox 的內容怎麼複製
private void test()
{
for (int i = 0; i listBox1.Items.Count; i++)
{
listBox2.Items.Add(listBox1 .Items [i]);
}
}
請問C#控件中listBox怎麼賦值呀?是listBox.Text=”” 嗎?
listBox有一個這樣的屬性:Items,你可利用它進行賦值:
listBox1.Items.Add(“a”);
listBox1.Items.Add(“b”);
listBox1.Items.Add(“c”);
用C#語言ListBox和MessageBox關聯的問題
我給你做了個一摸一樣的:在窗體中拖進個listbox1:代碼如下:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show(“您選的是:第【”+(listBox1.SelectedIndex + 1).ToString() + “】項;\r\n字母為:” + listBox1.SelectedItem.ToString());
}
private void Form1_Load(object sender, EventArgs e)
{
string[] myString = new string[]{“A”,”B”,”C”,”D”,”E”,”F”,”G”,”H”, “I”,”J”,”K”,”L”,”M”,”N”,”O”,”P”,”Q”,”R”,”S”,”T”,”U”,
“V”,”W”,”X”,”Y”,”Z”};
for (int i = 0; i myString.Length; i++)
{
listBox1.Items.Add(myString[i]);
}
}
可以加我百度HI,共同了解ASP.NET
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/287095.html