grid에 데이터 넣기

 

private void SetChkStatusGrid()
{
string[] ChkStatusName = new string[]{"Seq.1) BarCode Scanner Check...",
"Seq.2) MES SERVER Connection Check...",
"Seq.3) MES_NET file Execute Check...",
"Seq.4) LOT ID FILE Search...",
"Seq.5) LOT ID FILE Downloading..."};

string strName = "";
int HeaderCnt = 2, ColumnCnt = 6;
gridChkStatus.BorderStyle = BorderStyle.FixedSingle;
gridChkStatus.BackColor = Color.Black;
gridChkStatus.Redim(ColumnCnt, HeaderCnt);
for (int row = 0; row < ColumnCnt; row++)
{
for (int col = 0; col < HeaderCnt; col++)
{
if (row == 0)
{
if(col == 0) strName = "CHECK PROCESS.....";
else strName = "PASS/FAIL";
gridChkStatus[row, col] = new SourceGrid2.Cells.Real.ColumnHeader(strName);
m_ChkStsHeaderColor.TextAlignment = ContentAlignment.MiddleCenter;
gridChkStatus[row, col].VisualModel = m_ChkStsHeaderColor;
}
else
{
if (col != 0){
gridChkStatus[row, col] = new SourceGrid2.Cells.Real.Cell();
}
else {
gridChkStatus[row, col] = new SourceGrid2.Cells.Real.Cell(ChkStatusName[row - 1]);
}
gridChkStatus[row, col].VisualModel = m_ChkStsBackColor;
}
}// for int col
} // for int row

// gridChkStatus[1, 1] = new SourceGrid2.Clls.Real.Cell("only test");
gridChkStatus.AutoSizeAll();
}

색 및 정렬하기

private SourceGrid2.VisualModels.Common m_ChkStsPColor;
private SourceGrid2.VisualModels.Common m_ChkStsFColor;
private SourceGrid2.VisualModels.Common m_ChkStsBackColor;
private SourceGrid2.VisualModels.Common m_ChkStsHeaderColor;

public LotIDScanForm(RegistryStruct MainRegStruct)
{
..................

m_ChkStsPColor = new SourceGrid2.VisualModels.Common();
m_ChkStsFColor = new SourceGrid2.VisualModels.Common();
m_ChkStsBackColor = new SourceGrid2.VisualModels.Common();
m_ChkStsHeaderColor = new SourceGrid2.VisualModels.Common();

// Chk Status를 위한 Color 생성.
m_ChkStsPColor.BackColor = Color.Green;
m_ChkStsFColor.BackColor = Color.OrangeRed;
m_ChkStsBackColor.BackColor = Color.AliceBlue;
m_ChkStsHeaderColor.BackColor = Color.Khaki;

// 문자열 정렬.
m_ChkStsPColor.TextAlignment = ContentAlignment.MiddleCenter;
m_ChkStsFColor.TextAlignment = ContentAlignment.MiddleCenter;
m_ChkStsBackColor.TextAlignment = ContentAlignment.MiddleCenter;
m_ChkStsHeaderColor.TextAlignment = ContentAlignment.MiddleCenter;

 

학습목표: Tab Index가 변경될때, 그 index 번호를 알아내자.

 

enum TabStatus : int { SLogin = 0, ScanGpib = 1, UI = 2, LotEnd = 3 }

 

private void TabCtrlfunctionSetup_SelectedIndexChanged(object sender, EventArgs e)
{
TabControl tab = (TabControl)sender;
if (tab.SelectedIndex == (int)TabStatus.ScanGpib)
txtboxScanData.Focus();
}

 

 

txtboxScanDataList. AppendText(sBuf);

학습목표: 이번 장에서는 KeyPress를 활용하여,

특정 Key가 눌러졌을때 그에 상응하는 대응 코드를 작성해 보자.

 

//하기와 같이 KeyPress Event를 활용하면 된다.

끝..

 

private void txtboxScanData_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (int)Keys.Enter)
{
string sBuf = txtboxScanData.Text;
MessageBox.Show(sBuf);
}
}

'프로그래밍 > .Net' 카테고리의 다른 글

Tab Control index change  (0) 2014.01.17
textbox 글자넣기  (0) 2014.01.17
Color class에서 문자열로 색 지정하기  (0) 2014.01.17
MainForm, ChildForm 데이터 공유  (0) 2014.01.17
Color Type(Color.)  (0) 2014.01.17

학습목표: Color Class를 사용함에 있어,

TextBox Control의 BackColor에 색을 지정하고 싶은 경우, 문자열로 지정된 값을 색을 넣어보자

 

이 얼마나 쉬운가~!!

1. TextBox.BackColor = Color.FromName("Red");

학습 목표: Main Form을 생성한 후, MainForm에서 SubForm을 생성하여,

RegistryStruct class내에 선언된 변수에 데이터 저장 후

SubForm을 닫고 Main Form에서 RegistryStruct Class의 변수값을 사용하여보자.

 

1. Main Form 전역으로 RegistryStruct 선언하고,

실제 SubForm을 사용하는 곳에서 SubForm을 생성시킨다.

 

RegistryStruct RegStruct = new RegistryStruct();

 

private void btnFuncSetup_Click(object sender, EventArgs e)
{

// MainForm과의 데이터 공유를 위하여 매개변수에 RegStruct를 넘겨준다.
SubForm = new SubForm (RegStruct);
funcDlg.Show();
}

 

2. SubForm 생성자에서 해당 구조체를 받아서 데이터를 Read/Write 수행한다.

// 전연변수로 선언. new로 선언하면 새로운 인스턴트가 생성되어버림.

RegistryStruct RegStruct;

 

// Sub Form 생성부분에서 Main Form의 데이터를 받는다.

public FunctionSetupDlg(RegistryStruct MainRegStruct)
{
InitializeComponent();

// Main form에서 생성을 먼저 하고, Sub Form으로 연결시킨다.
this.RegStruct = MainRegStruct;

}

 

Color의 속성으로 설정할 수 있는 Color name..




 

//파일조작 - 생성 삭제 복사 이동
string path = @"sample.txt";
FileInfo file = new FileInfo(path);

if (file.Exists) // 파일이 있는지
{
// 복사 (경로,덮어쓰기 옵션 기본값 false)
// 만약 덮어쓰기 false일때 파일이 존재하면 에러남.
file.CopyTo(@"sample2.txt",true);
file.CopyTo(@"sample3.txt", true);

// 이동
FileInfo fileMove = new FileInfo(@"sample2.txt");
fileMove.MoveTo(@"sample2.txt");
if (fileMove.Exists) // 파일이 있는지
{
fileMove.MoveTo((@"c:\sample2_move.txt")); // 이미있으면 에러
}

// 삭제 - 먼저 삭제할 파일을 FileInfo로 연다.
FileInfo fileDel = new FileInfo(@"c:\sample2_move.txt");
if (fileDel.Exists) // 삭제할 파일이 있는지
{
fileDel.Delete(); // 없어도 에러안남
}

// 이름 바꾸기
FileInfo fileRename = new FileInfo(@"sample3.txt");
if (fileRename.Exists)
{
fileRename.MoveTo(@"sample3_rename.txt"); // 이미있으면 에러
}
}

 

파일 조작 복사.

if (bSimMode == true)

{

FileInfo file = new FileInfo(sourcefile);

if (file.Exists != true)

{

MessageBox.Show(" ";

return true;

}

 

file.CopyTo(localfile, true);

 

return true;

}

 


 

학습목표: 자신의 Local PC의 IP를 얻어오는 연습을 해보자.

 

// 자신의 PC의 IP를 얻어와 default로 설정한다.
IPAddress ipadrs = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0];
string strCurIP = ipadrs.ToString();

 

의외로 간단하다.

끝~!

목표: 힘들게 제작해둔 User Control 기능중에서 Btn이나 기타 main form에 어떠한 정보를

주고자 하는 경우의 event 등록과 사용방법에 대해 알아보자.

 

1. UserContrl에 btn을 만들어 놓고,

btn을 클릭했을경우, Main form에 어떠한 데이터를 넘겨주는 로직을 구현하고자 할때..

 

하기의 block Diagram 으로 표현해보자.

 

 

 

2. 실제 적용된 소스 코드를 들여다 보자

/// User Contrl . dll

namespace asServerLoginX
{
// define the delegate for use the event in this User Contrl.
// To use this event, you have to registry event in Main Form.

public delegate void BtnPingOnClickHandler(string msg);

public partial class ServerLoginX : UserControl
{
#region "전역으로 사용되는 변수 리스트"
// event instance define.
public event BtnPingOnClickHandler BtnPingOnClick;

.............

}

 

// event를 사용하고자 하는 부분.

// It's create the event to give the Main Form.
if (BtnPingOnClick != null) // event가 등록되어있다면...
BtnPingOnClick(retmsg);

}

 

 

//Main Form에서 event 연결시키고 UserContrl에서 추가한 이벤트 정보 가져오기

namespace ServerTester
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

// User Control에서 Button Event 가져오기.
private void Form1_Load(object sender, EventArgs e)
{
// axSLoginX.EnableResultBox(false);
axSLoginX.BtnPingOnClick +=

new asServerLoginX.BtnPingOnClickHandler(GetMsg);
}

 

private void GetMsg(string msg)
{
MessageBox.Show(msg);
}

}
}

 

+ Recent posts