2008/C#2008. 10. 13. 15:10

[C#] Round Rectangle 처리하기

사용자 삽입 이미지

RoundPanel 클래스를 제작했습니다.
Panel을 상속해서 처리 했습니다.

Round 하는 코드는 아래의 코드를 참조 하시면 됩니다.       

        static public GraphicsPath GetRoundedRectPath(Rectangle rect, int radius)
        {
            int diameter = 2 * radius;
            Rectangle arcRect =
                new Rectangle(rect.Location, new Size(diameter, diameter));

            GraphicsPath path = new GraphicsPath();

            path.AddArc(arcRect, 180, 90);

            arcRect.X = rect.Right - diameter;
            path.AddArc(arcRect, 270, 90);

            arcRect.Y = rect.Bottom - diameter;
            path.AddArc(arcRect, 0, 90);

            arcRect.X = rect.Left;
            path.AddArc(arcRect, 90, 90);

            path.CloseFigure();

            return path;
        }

Panel 함수에서 드로잉 하는 코드 입니다.
       

        private void roundPanel_title_Paint(object sender, PaintEventArgs e)
        {
            RoundPanel panel = (RoundPanel)sender;

            Graphics g = e.Graphics;
            g.SmoothingMode = SmoothingMode.HighQuality;

            int width = panel.ClientRectangle.Width;
            int height = panel.ClientRectangle.Height;

            Rectangle rect = new Rectangle(0, 0, width-1, height-1);
            using (GraphicsPath path = RoundPanel.GetRoundedRectPath(rect, 8))
            {
                using (Brush brush = new LinearGradientBrush(
                                            new Rectangle(0, 0, panel.ClientRectangle.Width, panel.ClientRectangle.Height),
                                            Color.FromArgb(panel.Opcity, 102, 102, 102),
                                            Color.FromArgb(panel.Opcity, 0, 0, 0),
                                            90.0f))
                {
                    //graphics.FillRectangle(brush, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height);
                    g.FillPath(brush, path);
                }

                //g.FillPath(Brushes.Yellow, path);
                Pen pen = new Pen(Color.FromArgb(panel.Opcity, 255, 255, 255));
                g.DrawPath(pen, path);
            }
        }

이걸 처리 하다 보면 화면을 전환 하거나 리프레쉬할때 플리커 현상이 생기기도 합니다.
이걸 해결하기 위해서 RoundPanel에 더블버퍼링 처리 코드를 추가 했습니다.

        public RoundPanel()
        {
            ...
            this.SetStyle(  ControlStyles.UserPaint |
                            ControlStyles.AllPaintingInWmPaint |
                            ControlStyles.DoubleBuffer, true);
        }

출처 : http://iamgsi.com/374
Posted by penguindori
2008/C#2008. 10. 9. 16:18



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OracleClient;

namespace Login
{
    public partial class Form2 : Form
    {
        OracleConnection oConn;
        OracleCommand oComm;
        OracleParameter[] oPar;

        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            oConn = new OracleConnection("Data Source=mi;User ID=midas;Password=midas123");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            StringBuilder sbSql = new StringBuilder();
            oConn.Open();

            try
            {
                sbSql.Append(" select userid,userpwd,username  ");
                sbSql.Append("  from midas_user ");
                sbSql.Append("  WHERE userid  = :userid ");
                sbSql.Append("  AND userpwd  = :userpwd ");

                oPar = new OracleParameter[2];
                oPar[0] = new OracleParameter(":userid", textBox1.Text);
                oPar[1] = new OracleParameter(":userpwd", textBox2.Text);

                oComm = new OracleCommand(sbSql.ToString(), oConn);

                oComm.Parameters.Add(oPar[0]);
                oComm.Parameters.Add(oPar[1]);

                OracleDataReader dr = oComm.ExecuteReader(CommandBehavior.CloseConnection);
                oComm.Parameters.Clear();

                dr.Read();

                MessageBox.Show(dr["USERNAME"].ToString());
                MessageBox.Show(dr["userid"].ToString());
              

            }
            catch (Exception ex) { string ok = ex.Message.ToString(); }


        }
    }
}

Posted by penguindori