this.Invoke(new Action(delegate()

{

   UI컨트롤

}));

 

 

System.InvalidOperationException: '크로스 스레드 작업이 잘못되었습니다. 'txtHistory' 컨트롤이 자신이 만들어진 스레드가 아닌 스레드에서 액세스되었습니다.'

 

 

this.Invoke(new Action(delegate()

{

  txtHistory.AppendText(text);

}));

 

listbox.items 를 for 문으로 루프 돌리면서 확인하시면 됩니다.

 

예를 들어서 listbox1 이라는 컨트롤이 있다고 가정하면,

아래와같이 취득할수 있습니다.

 

   private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 0; i <= listBox1.Items.Count; i++)
            {
                listBox1.Items[i].ToString();
            }
        }

 

그리고 리스트박스 항목 갯수 구하기 

int i;
i = listBox.Items.Count
private string GetIP() {     
string strHostName = "";     
strHostName = System.Net.Dns.GetHostName();    
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);    
IPAddress[] addr = ipEntry.AddressList;     
return addr[addr.Length - 1].ToString(); 
}

C# 에서 IP 주소 가져오는 방법

 

'기타 ETC > C#' 카테고리의 다른 글

UI 쓰레드 에러 문제 해결하기  (0) 2020.04.09
C# 리스트박스 항목 가져오기  (0) 2020.04.09
c# 둥근 버튼 만들기  (0) 2020.03.24
C# 그라디언트 판넬 컨트롤 만들기  (0) 2020.03.24
C# DragControl 만들기  (0) 2020.03.24

c# 둥근 버튼 만들기 C# Circular Button 

 

1. 클래스를 생성하고 다음과 같이 코딩한다. 

using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Monitor0._2.UI_Forms
{
    class CircularButton : Button
    {
        protected override void OnPaint(PaintEventArgs pevent)
        {
            GraphicsPath grPath = new GraphicsPath();
            grPath.AddEllipse(0, 0, ClientSize.Width, ClientSize.Height);
            this.Region = new System.Drawing.Region(grPath);
            base.OnPaint(pevent);
        }
     
    }
}

 

2. 다시빌드하고 도구상자에 CircularButton이 있다. 드래그해서 쓰면된다.

+ Recent posts