Quantcast
Viewing all articles
Browse latest Browse all 12583

Adding buttons to SplitContainer

Hi All,

I am trying to add collapse/expand buttons to the splitercontainer.

I create a custom control and put the below code in. The splittercontainer custom control is set to horizontal orientation and is set to doc in parent container.

This code draws a thin rectangle 20 pixels below top of the splittercontainer. It does not get redrawn when the splitter is moved and also, the splitter width, panel1.width,X,Y are all static and are not changing.

How do i get the rectangle to be redrawn when the splitter is moved ? and how to get the values of  splitter width, panel1.width,X,Y etc.. to change based on the splitter movement ?

Thanks in advance.

Also, below line does not really fill up the splitter rectangle.

 g.FillRectangle(new SolidBrush(Color.Aqua), splitContainer1.SplitterRectangle);

Code:

public partial class CustomControl1 : System.Windows.Forms.SplitContainer
    {
        public CustomControl1()
        {
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            Graphics g = pe.Graphics;
            Rectangle r = splitContainer1.SplitterRectangle; // fixed in version 1.1
Rectangle rr = new Rectangle(splitContainer1.SplitterRectangle.Width / 2, splitContainer1.SplitterDistance, splitContainer1.SplitterRectangle.Width, splitContainer1.SplitterRectangle.Height);
             g.FillRectangle(new SolidBrush(Color.Aqua), splitContainer1.SplitterRectangle);
            g.FillRectangle(new SolidBrush(Color.CadetBlue), rr);

        }

private void splitContainer1_SplitterMoving(object sender, SplitterCancelEventArgs e)

{
this.Invalidate();

}


-Giri.


Viewing all articles
Browse latest Browse all 12583

Trending Articles