BindingList<ComboData> _comboItems = new BindingList<ComboData>(); // ComboBox의 DataSource 적용된것


private void Combo_DrawItem(object sender, DrawItemEventArgs e)

        {

            Brush brush = null;

            ComboBox combo = (ComboBox)sender;


            if (combo == null || _comboItems == null)

            {

                return;

            }


            if (대상인 색깔..)

            {

                //백그라운드 색

                e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds);

                //글자 색

                brush = ((e.State & DrawItemState.Selected) > 0) ? SystemBrushes.HotTrack : SystemBrushes.ControlText;

                e.Graphics.DrawString(_comboItems[e.Index].Text, combo.Font, brush, e.Bounds);

            }

            else

            {

                e.DrawBackground();

                //백그라운드 색

                e.Graphics.FillRectangle(Brushes.DarkGray, e.Bounds);

                //글자 색

                brush = ((e.State & DrawItemState.Selected) > 0) ? SystemBrushes.HighlightText : SystemBrushes.ControlText;

                e.Graphics.DrawString(_comboItems[e.Index].Text, combo.Font, brush, e.Bounds);

                e.DrawFocusRectangle();

            }

        }

Posted by Lich King
,

    public interface IFormDataInterface

    {

        void SetData(String Data);

    }

    

    public partial class Form1 : Form, IFormDataInterface

    {

        public Form1()

        {

            InitializeComponent();

        }


        private void button1_Click(object sender, EventArgs e)

        {

            Form2 frm = new Form2(this as IFormDataInterface);

            frm.Show();

        }

        public void SetData(String Data)

        {

            textBox1.Text = Data;

        }

    }


    public partial class Form2 : Form

    {

        private IFormDataInterface frm = null;

        public Form2(IFormDataInterface frm)

        {

            InitializeComponent();

            this.frm = frm;

        }


        private void button1_Click(object sender, EventArgs e)

        {

            frm.SetData(textBox1.Text);

        }

    }

Posted by Lich King
,

            AutoScroll = false;

            HorizontalScroll.Enabled = false;

            AutoScroll = true;


하면된다.

이렇게 안하면 수평 스크롤이 안없어진다.

버그가 있다.

Posted by Lich King
,

생성자

            TableLayoutPanel1.MouseWheel += new MouseEventHandler(DoNothing_MouseWheel);



함수

        private void DoNothing_MouseWheel(object sender, EventArgs e)
        {
            HandledMouseEventArgs handledMouseEventArgs = (HandledMouseEventArgs)e;
            handledMouseEventArgs.Handled = true;
        }

TableLayoutPanel  이벤트

        private void coTableLayoutPanel1_MouseHover(object sender, EventArgs e)
        {
            TableLayoutPanel1.Focus();
        }


Posted by Lich King
,

    public static class NativeMethods

    {

        public static int WM_SETREDRAW = 0x000B; //uint WM_SETREDRAW

        public static int WS_EX_COMPOSITED = 0x02000000;

        

        [DllImport("user32.dll", CharSet = CharSet.Auto)]

        public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); //UInt32 Msg

    }




class DoubleBufferTableLayoutPanel : TableLayoutPanel

    {



        public DoubleBufferTableLayoutPanel()

        {

            SetStyle(ControlStyles.DoubleBuffer, true);

        }


        protected override void OnCreateControl()

        {

            base.OnCreateControl();

            this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.CacheText, true);

        }


        protected override CreateParams CreateParams

        {

            get

            {

                CreateParams cp = base.CreateParams;

                cp.ExStyle |= NativeMethods.WS_EX_COMPOSITED;

                return cp;

            }

        }


        public void BeginUpdate()

        {

            NativeMethods.SendMessage(this.Handle, NativeMethods.WM_SETREDRAW, IntPtr.Zero, IntPtr.Zero);

        }


        public void EndUpdate()

        {

            NativeMethods.SendMessage(this.Handle, NativeMethods.WM_SETREDRAW, new IntPtr(1), IntPtr.Zero);

            Parent.Invalidate(true);

        }

    }



DoubleBufferTableLayoutPanel  이것을 쓴다.

Posted by Lich King
,

        private void AddNewTab(Form frm)

        {

            TabPage tab = new TabPage(frm.Text);

            frm.TopLevel = false;

            frm.Parent = tab;

            frm.Visible = true;

            dataMakerTabControl.TabPages.Add(tab);

            frm.Location = new Point((tab.Width - frm.Width) / 2, (tab.Height - frm.Height) / 2);

            frm.Height = frm.Height;

        }

선언하고

다음과같이 호출한다.


AddNewTab(new Form2());



Posted by Lich King
,

Form에 다음을 선언한다.




   protected virtual bool DoubleBuffered { get; set; }



   public static class Extensions

    {

        public static void DoubleBuffered(this Control control, bool enabled)

        {

            var prop = control.GetType().GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);

            prop.SetValue(control, enabled, null);

        }

    }


2개를 선언하고 리스트뷰에 


            statusListview.DoubleBuffered(true);


를 쓴다.

Form1_Load에 쓰면 됨. 일반적으로


Posted by Lich King
,