home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Tree View and List View / SplitTwoProportional / SplitTwoProportional.cs next >
Encoding:
Text File  |  2001-01-15  |  2.0 KB  |  64 lines

  1. //---------------------------------------------------
  2. // SplitTwoProportional.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class SplitTwoProportional: Form
  9. {
  10.      Panel panel2;
  11.      float fProportion = 0.5f;
  12.  
  13.      public static void Main()
  14.      {
  15.           Application.Run(new SplitTwoProportional());
  16.      }
  17.      public SplitTwoProportional()
  18.      {
  19.           Text = "Split Two Proportional";
  20.  
  21.           Panel panel1     = new Panel();
  22.           panel1.Parent    = this;
  23.           panel1.Dock      = DockStyle.Fill;
  24.           panel1.BackColor = Color.Red;
  25.           panel1.Resize   += new EventHandler(PanelOnResize);
  26.           panel1.Paint    += new PaintEventHandler(PanelOnPaint);
  27.  
  28.           Splitter split   = new Splitter();
  29.           split.Parent     = this;
  30.           split.Dock       = DockStyle.Left;
  31.           split.SplitterMoving += new SplitterEventHandler(SplitterOnMoving);
  32.  
  33.           panel2           = new Panel();
  34.           panel2.Parent    = this;
  35.           panel2.Dock      = DockStyle.Left;
  36.           panel2.BackColor = Color.Lime;
  37.           panel2.Resize   += new EventHandler(PanelOnResize);
  38.           panel2.Paint    += new PaintEventHandler(PanelOnPaint);
  39.  
  40.           OnResize(EventArgs.Empty);
  41.      }
  42.      protected override void OnResize(EventArgs ea)
  43.      {
  44.           base.OnResize(ea);
  45.           panel2.Width = (int) (fProportion * ClientSize.Width);
  46.      }
  47.      void SplitterOnMoving(object obj, SplitterEventArgs sea)
  48.      {
  49.           fProportion = (float) sea.SplitX / ClientSize.Width;
  50.      }
  51.      void PanelOnResize(object obj, EventArgs ea)
  52.      {
  53.           ((Panel) obj).Invalidate();
  54.      }
  55.      void PanelOnPaint(object obj, PaintEventArgs pea)
  56.      {
  57.           Panel    panel = (Panel) obj;
  58.           Graphics grfx  = pea.Graphics;
  59.  
  60.           grfx.DrawEllipse(Pens.Black, 0, 0, 
  61.                            panel.Width - 1, panel.Height - 1);
  62.      }
  63. }
  64.