Control에서 상속을 받아 컨트롤을 만들때에 내부에 텍스트 출력 및 정렬을 하려면 OnPaint 이벤트에 직접 코딩을 해줘야 한다.
Text 를 출력하는 방법은
protected override void OnPaint(PaintEventArgs pea)
        {
            StringFormat format = new StringFormat(StringFormatFlags.NoClip);
            format.Alignment = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;
            pea.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), new RectangleF(0, 0, this.Width, this.Height), format);
         }
이렇게 하면 출력이 된다.
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
이 두부분이 정렬 설정 부분이다. 설정은 레리아웃의 방향에 따라 설정이 되면 Near, Center, Far 세가지가 있다
레이아웃이 왼쪽에서 오른쪽인 경우에는 Near가 Left 또는 Top이 된다.
new RectangleF(0, 0, this.Width, this.Height) 이 부분은 컨트롤의 가운데 찍으려면 이렇게 값을 주면 되고 내부에 별도 영역에 출력을 하려면 그 여역을 지정해 주면 된다..
더 쉬운 방법이 있을것 같기도 한데...모르겠다..

'PC Programming > C# .net' 카테고리의 다른 글

c# DOCK Property 설정  (0) 2012.03.19
c# 에서 Debug메세지 뿌리기  (0) 2011.08.08
SqlCommand에서 Parameter 사용  (0) 2010.03.24
Posted by bluescor
폼에 판넬(Panel1)을 놓은다음 다른 판넬(Panel2)을 올려 놓은 후 뒤 Panel2 Dock 설정을 Fill이 아니라 다른 값으로 설정을
한 후 Panel1의 Dock 설정을 Fill로 설정을 하게 되면 Panel1이 폼 전체에 가득 차게 된다..
다른 언어에서는 자동으로 뒤에 놓은 판넬도 고려해서 적용이 됐었던것 같은데...
이 경우에 Panel1위에서 마우스 오른쪽 클릭을 한 후에 맨 앞으로 가져오기를 하게 되면 Panel2의 공간을 제외한 공간에 가득 차게 된다.
왜 안되는지 한참 고민했는데....별게 아니었네...;;;
귀찮게 되어 있다....
Posted by bluescor
단말기 Debug메세지에 메세지 나오게 하는 C# 함수 단말기 외에도 사용은 가능할듯 하다....
사용은 안해봐서 정확하지는 않지만...

System.Diagnostics.Debug.WriteLine("메세지");
System.Diagnostics.Trace.WriteLine("메세지");
Posted by bluescor

            String sSql;
            SqlCommand sqlComm;
            SqlDataReader sqlReader;

            try
            {
                sSql = "SELECT PASSWORD FROM TB_USER WHERE USERID = @USERID ";
                sqlComm = new SqlCommand(sSql, DBConnection.conn);
                sqlComm.Parameters.Add(new SqlParameter("USERID", txtUserID.Text));
                sqlReader = sqlComm.ExecuteReader();
                if (sqlReader != null && sqlReader.HasRows)
                {
                    sqlReader.Read();
                    if (sqlReader.GetString(0) == txtPassword.Text)
                        this.Close();
                    else
                    {
                        txtPassword.Text = "";
                        MessageBox.Show("비밀번호가 틀립니다.");
                    }
                }
                else
                {
                    txtUserID.Text = "";
                    MessageBox.Show("존재하지 않는 아이디 입니다.");
                }
                sqlReader.Close();
            }
            catch (SqlException ex)
            {
                Program.angLog.WriteLog(String.Format("SQLException {0}", ex.Message));
            }
            catch (Exception ex)
            {
                Program.angLog.WriteLog(String.Format("Exception {0}", ex.Message));
            }

Posted by bluescor
이전버튼 1 이전버튼

블로그 이미지
bluescor

공지사항

Yesterday
Today
Total

달력

 « |  » 2024.5
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

최근에 올라온 글

최근에 달린 댓글

글 보관함