728x90
Main
-사용한 컨트롤 : Button 1개, Listview 1개
전체 소스 코드
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 CSharp_ListView
{
public partial class Form1 : Form
{
//컨트롤 해제 변수...
List<Control> ltControl = new List<Control>();
public Form1()
{
InitializeComponent();
}
void ControlDispose()
{
for (int iCount = 0; iCount < ltControl.Count; iCount++)
{
ltControl[iCount].Dispose();
}
if (ltControl.Count > 0)
{
ltControl.Clear();
}
}
private void button2_Click(object sender, EventArgs e)
{
lvMain.Groups.Clear();
lvMain.Items.Clear();
ControlDispose();
ListViewItem lvi = new ListViewItem();
lvi.Text = "000";
lvi.SubItems.Add("111");
lvi.SubItems.Add("222");
lvi.SubItems.Add("333");
lvMain.Items.Add(lvi);
//객체를 어디에 담았다가 Dispose() 해주기...
//Control In 할 객체 만들기...
ProgressBar pb = new ProgressBar();
pb.Minimum = 0;
pb.Maximum = 100;
pb.Value = 50;
pb.Parent = listView_Telephone;
//서브 아이템 얻어오기
ListViewItem.ListViewSubItem ps = null;
ps = listView_Telephone.Items[0].SubItems[0];
//그리기
Rectangle rt = new Rectangle();
rt = ps.Bounds;
pb.SetBounds(rt.X, rt.Y, 100, rt.Height);
ltControl.Add(pb);
Button bt = new Button();
bt.Text = "In Button1";
bt.Click += new EventHandler(bt_Click);
bt.Parent = listView_Telephone;
//서브 아이템 얻어오기
ListViewItem.ListViewSubItem ps2 = null;
ps2 = listView_Telephone.Items[0].SubItems[1];
//그리기
Rectangle rt2 = new Rectangle();
rt2 = ps2.Bounds;
bt.SetBounds(rt2.X, rt2.Y, rt2.Width, rt2.Height+6);
ltControl.Add(bt);
//-----------------------------------
Button bt2 = new Button();
bt2.Text = "In Button2";
bt2.Click += new EventHandler(bt_Click);
bt2.Parent = listView_Telephone;
//서브 아이템 얻어오기
ListViewItem.ListViewSubItem ps3 = null;
ps3 = listView_Telephone.Items[0].SubItems[2];
//그리기
Rectangle rt3 = new Rectangle();
rt3 = ps3.Bounds;
bt2.SetBounds(rt3.X, rt3.Y, rt3.Width, rt3.Height+6);
ltControl.Add(bt2);
TextBox tb = new TextBox();
tb.Text = "In TextBox";
tb.Parent = listView_lvMainTelephone;
//서브 아이템 얻어오기
ListViewItem.ListViewSubItem ps4 = null;
ps4 = listView_Telephone.Items[0].SubItems[3];
//그리기
Rectangle rt4 = new Rectangle();
rt4 = ps4.Bounds;
tb.SetBounds(rt4.X, rt4.Y, rt4.Width, rt4.Height);
ltControl.Add(tb);
}
void bt_Click(object s, EventArgs e)
{
Button bt = s as Button; MessageBox.Show(bt.Text);
}
}
}
*예제 결과
https://kdsoft-zeros.tistory.com/211
출처: https://kdsoft-zeros.tistory.com/210 [삽질하는 개발자...]
'개발언어 > C#' 카테고리의 다른 글
[C#] ListView 버튼 및 컨트롤 추가 (0) | 2021.08.10 |
---|---|
[C#] LISTVIEW 기능 분석 (0) | 2021.08.10 |
[C#] ListView 실습 (0) | 2021.08.10 |
[C#] listview에 button추가시 샘플3 (0) | 2021.08.10 |
[C#] listview에 button추가시 샘플1 (0) | 2021.08.10 |