Csharp/C Sharp by API/System.Windows.Forms/Panel
Содержание
extends Panel
<source lang="csharp"> using System; using System.Collections.Generic; using System.ruponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; public class ScrollingText : System.Windows.Forms.Panel {
Font textFont = new Font("Times New Roman", 24); public ScrollingText() { InitializeComponent(); } private void ScrollingText_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; g.TranslateTransform(this.AutoScrollPosition.X, this.AutoScrollPosition.Y); g.DrawString("Hello, World", textFont, Brushes.Black, 40, 40); g.DrawString("Hello, World", textFont, Brushes.Red, 40, 240); g.DrawString("Hello, World", textFont, Brushes.Blue, 350, 40); g.DrawString("Hello, World", textFont, Brushes.Green, 350, 240); } private void InitializeComponent() { this.SuspendLayout(); this.AutoScroll = true; this.AutoScrollMinSize = new System.Drawing.Size(600, 400); this.BackColor = System.Drawing.SystemColors.Window; this.Paint += new System.Windows.Forms.PaintEventHandler(this.ScrollingText_Paint); this.ResumeLayout(false); }
} public class Form1 : Form {
public Form1() { InitializeComponent(); } private void InitializeComponent() { this.scrollingText1 = new ScrollingText(); this.SuspendLayout(); this.scrollingText1.AutoScroll = true; this.scrollingText1.AutoScrollMinSize = new System.Drawing.Size(600, 400); this.scrollingText1.BackColor = System.Drawing.SystemColors.Window; this.scrollingText1.Location = new System.Drawing.Point(13, 13); this.scrollingText1.Size = new System.Drawing.Size(267, 243); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(292, 268); this.Controls.Add(this.scrollingText1); this.ResumeLayout(false); } private ScrollingText scrollingText1; [STAThread] static void Main() { Application.EnableVisualStyles(); Application.Run(new Form1()); }
}
</source>
new Panel()
<source lang="csharp"> using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Windows.Forms; class ClipViewAll : Form {
Panel panelDisplay, panelButtons; RadioButton radioChecked; string[] astrFormatsSave = new string[0]; public static void Main() { Application.Run(new ClipViewAll()); } public ClipViewAll() { panelDisplay = new Panel(); panelDisplay.Parent = this; panelDisplay.Dock = DockStyle.Fill; panelDisplay.Paint += new PaintEventHandler(PanelOnPaint); panelDisplay.BorderStyle = BorderStyle.Fixed3D; Splitter split = new Splitter(); split.Parent = this; split.Dock = DockStyle.Left; panelButtons = new Panel(); panelButtons.Parent = this; panelButtons.Dock = DockStyle.Left; panelButtons.AutoScroll = true; panelButtons.Width = Width / 2; Timer timer = new Timer(); timer.Interval = 1000; timer.Tick += new EventHandler(TimerOnTick); timer.Enabled = true; } void TimerOnTick(object obj, EventArgs ea) { IDataObject data = Clipboard.GetDataObject(); string[] astrFormats = data.GetFormats(); bool bUpdate = false; if (astrFormats.Length != astrFormatsSave.Length) bUpdate = true; else { for (int i = 0; i < astrFormats.Length; i++) if (astrFormats[i] != astrFormatsSave[i]) { bUpdate = true; break; } } panelDisplay.Invalidate(); if (!bUpdate) return; astrFormatsSave = astrFormats; panelButtons.Controls.Clear(); Graphics grfx = CreateGraphics(); EventHandler eh = new EventHandler(RadioButtonOnClick); int cxText = AutoScaleBaseSize.Width; int cyText = AutoScaleBaseSize.Height; for (int i = 0; i < astrFormats.Length; i++) { RadioButton radio = new RadioButton(); radio.Parent = panelButtons; radio.Text = astrFormats[i]; if (!data.GetDataPresent(astrFormats[i], false)) radio.Text += "*"; try { object objClip = data.GetData(astrFormats[i]); radio.Text += " (" + objClip.GetType() + ")"; } catch { radio.Text += " (Exception on GetData or GetType!)"; } radio.Tag = astrFormats[i]; radio.Location = new Point(cxText, i * 3 * cyText / 2); radio.Size = new Size((radio.Text.Length + 20) * cxText, 3 * cyText / 2); radio.Click += eh; } grfx.Dispose(); radioChecked = null; } void RadioButtonOnClick(object obj, EventArgs ea) { radioChecked = (RadioButton)obj; panelDisplay.Invalidate(); } void PanelOnPaint(object obj, PaintEventArgs pea) { Panel panel = (Panel)obj; Graphics grfx = pea.Graphics; Brush brush = new SolidBrush(panel.ForeColor); if (radioChecked == null) return; IDataObject data = Clipboard.GetDataObject(); object objClip = data.GetData((string)radioChecked.Tag); if (objClip == null) return; else if (objClip.GetType() == typeof(string)) { grfx.DrawString((string)objClip, Font, brush, panel.ClientRectangle); } else if (objClip.GetType() == typeof(string[])) // FileDrop { string str = string.Join("\r\n", (string[])objClip); grfx.DrawString(str, Font, brush, panel.ClientRectangle); } else if (objClip.GetType() == typeof(Bitmap) || objClip.GetType() == typeof(Metafile) || objClip.GetType() == typeof(Image)) { grfx.DrawImage((Image)objClip, 0, 0); } else if (objClip.GetType() == typeof(MemoryStream)) { Stream stream = (Stream)objClip; byte[] abyBuffer = new byte[16]; long lAddress = 0; int iCount; Font font = new Font(FontFamily.GenericMonospace, Font.SizeInPoints); float y = 0; while ((iCount = stream.Read(abyBuffer, 0, 16)) > 0) { lAddress += 16; } } }
}
</source>
Panel.AutoScroll
<source lang="csharp"> using System; using System.Collections.Generic; using System.ruponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; public class Form1 : Form {
private System.Windows.Forms.Panel Panel1; private System.Windows.Forms.Button Button6; private System.Windows.Forms.Button Button5; private System.Windows.Forms.Button Button4; private System.Windows.Forms.Button Button3; private System.Windows.Forms.Button Button2; private System.Windows.Forms.Button Button1; public Form1() { InitializeComponent(); }
private void InitializeComponent() { this.Panel1 = new System.Windows.Forms.Panel(); this.Button6 = new System.Windows.Forms.Button(); this.Button5 = new System.Windows.Forms.Button(); this.Button4 = new System.Windows.Forms.Button(); this.Button3 = new System.Windows.Forms.Button(); this.Button2 = new System.Windows.Forms.Button(); this.Button1 = new System.Windows.Forms.Button(); this.Panel1.SuspendLayout(); this.SuspendLayout(); // // Panel1 // this.Panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.Panel1.AutoScroll = true; this.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.Panel1.Controls.Add(this.Button6); this.Panel1.Controls.Add(this.Button5); this.Panel1.Controls.Add(this.Button4); this.Panel1.Controls.Add(this.Button3); this.Panel1.Controls.Add(this.Button2); this.Panel1.Controls.Add(this.Button1); this.Panel1.Location = new System.Drawing.Point(12, 12); this.Panel1.Name = "Panel1"; this.Panel1.Size = new System.Drawing.Size(218, 198); this.Panel1.TabIndex = 3; // // Button6 // this.Button6.FlatStyle = System.Windows.Forms.FlatStyle.System; this.Button6.Location = new System.Drawing.Point(16, 180); this.Button6.Name = "Button6"; this.Button6.Size = new System.Drawing.Size(168, 24); this.Button6.TabIndex = 5; this.Button6.Text = "Button6"; // // Button5 // this.Button5.FlatStyle = System.Windows.Forms.FlatStyle.System; this.Button5.Location = new System.Drawing.Point(16, 148); this.Button5.Name = "Button5"; this.Button5.Size = new System.Drawing.Size(168, 24); this.Button5.TabIndex = 4; this.Button5.Text = "Button5"; // // Button4 // this.Button4.FlatStyle = System.Windows.Forms.FlatStyle.System; this.Button4.Location = new System.Drawing.Point(16, 116); this.Button4.Name = "Button4"; this.Button4.Size = new System.Drawing.Size(168, 24); this.Button4.TabIndex = 3; this.Button4.Text = "Button4"; // // Button3 // this.Button3.FlatStyle = System.Windows.Forms.FlatStyle.System; this.Button3.Location = new System.Drawing.Point(16, 84); this.Button3.Name = "Button3"; this.Button3.Size = new System.Drawing.Size(168, 24); this.Button3.TabIndex = 2; this.Button3.Text = "Button3"; // // Button2 // this.Button2.FlatStyle = System.Windows.Forms.FlatStyle.System; this.Button2.Location = new System.Drawing.Point(16, 52); this.Button2.Name = "Button2"; this.Button2.Size = new System.Drawing.Size(168, 24); this.Button2.TabIndex = 1; this.Button2.Text = "Button2"; // // Button1 // this.Button1.FlatStyle = System.Windows.Forms.FlatStyle.System; this.Button1.Location = new System.Drawing.Point(16, 20); this.Button1.Name = "Button1"; this.Button1.Size = new System.Drawing.Size(168, 24); this.Button1.TabIndex = 0; this.Button1.Text = "Button1"; // // ScrollablePanel // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(248, 224); this.Controls.Add(this.Panel1); this.Name = "ScrollablePanel"; this.Text = "ScrollablePanel"; this.Panel1.ResumeLayout(false); this.ResumeLayout(false); } [STAThread] static void Main() { Application.EnableVisualStyles(); Application.Run(new Form1()); }
}
</source>
Panel.AutoScrollPosition
<source lang="csharp"> using System; using System.Collections.Generic; using System.ruponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; public class Form1 : Form {
public Form1() { this.panel1 = new System.Windows.Forms.Panel(); this.SuspendLayout(); this.panel1.AutoScroll = true; this.panel1.BackgroundImage = new Bitmap("yourfile.bmp"); this.panel1.Location = new System.Drawing.Point(13, 13); this.panel1.Size = new System.Drawing.Size(267, 243); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(292, 268); this.Controls.Add(this.panel1); this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); this.panel1.AutoScrollMinSize = this.panel1.BackgroundImage.Size; } private void Form1_Load(object sender, EventArgs e) { int midX = this.panel1.AutoScrollMinSize.Width / 2; int midY = this.panel1.AutoScrollMinSize.Height / 2; int halfSizeX = this.panel1.Size.Width / 2; int halfSizeY = this.panel1.Size.Height / 2; int startPosX = midX - halfSizeX; if (startPosX < 0) startPosX = 0; int startPosY = midY - halfSizeY; if (startPosY < 0) startPosY = 0; this.panel1.AutoScrollPosition = new Point(startPosX, startPosY); } private System.Windows.Forms.Panel panel1; [STAThread] static void Main() { Application.EnableVisualStyles(); Application.Run(new Form1()); }
}
</source>
Panel.Dock
<source lang="csharp"> using System; using System.Drawing; using System.Windows.Forms;
class ToggleButtons: Form {
protected Panel panel = new Panel(); protected ToolBar tbar; protected string strText = "Toggle"; protected Color clrText = SystemColors.WindowText; FontStyle fontstyle = FontStyle.Regular; public static void Main() { Application.Run(new ToggleButtons()); } public ToggleButtons() { panel.Parent = this; panel.Dock = DockStyle.Fill; panel.BackColor = SystemColors.Window; panel.ForeColor = SystemColors.WindowText; panel.Resize += new EventHandler(PanelOnResize); panel.Paint += new PaintEventHandler(PanelOnPaint); Bitmap bm = new Bitmap(GetType(), "ToggleButtons.bmp"); ImageList imglst = new ImageList(); imglst.ImageSize = new Size(bm.Width / 4, bm.Height); imglst.Images.AddStrip(bm); imglst.TransparentColor = Color.White; tbar = new ToolBar(); tbar.ImageList = imglst; tbar.Parent = this; tbar.ShowToolTips = true; tbar.ButtonClick += new ToolBarButtonClickEventHandler(ToolBarOnClick); FontStyle[] afs = { FontStyle.Bold, FontStyle.Italic, FontStyle.Underline, FontStyle.Strikeout }; for (int i = 0; i < 4; i++) { ToolBarButton tbarbtn = new ToolBarButton(); tbarbtn.ImageIndex = i; tbarbtn.Style = ToolBarButtonStyle.ToggleButton; tbarbtn.ToolTipText = afs[i].ToString(); tbarbtn.Tag = afs[i]; tbar.Buttons.Add(tbarbtn); } } void ToolBarOnClick(object obj, ToolBarButtonClickEventArgs tbbcea) { ToolBarButton tbarbtn = tbbcea.Button; if (tbarbtn.Tag == null || tbarbtn.Tag.GetType() != typeof(FontStyle)) return; if (tbarbtn.Pushed) fontstyle |= (FontStyle) tbarbtn.Tag; else fontstyle &= ~(FontStyle) tbarbtn.Tag; panel.Invalidate(); } void PanelOnResize(object obj, EventArgs ea) { Panel panel = (Panel) obj; panel.Invalidate(); } void PanelOnPaint(object obj, PaintEventArgs pea) { Panel panel = (Panel) obj; Graphics grfx = pea.Graphics; Font font = new Font("Times New Roman", 72, fontstyle); SizeF sizef = grfx.MeasureString(strText, font); grfx.DrawString(strText, font, new SolidBrush(clrText), (panel.Width - sizef.Width) / 2, (panel.Height - sizef.Height) / 2); }
}
</source>
Panel.DockPadding.
<source lang="csharp"> using System; using System.Collections.Generic; using System.ruponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; public class Form1 : Form {
private System.Windows.Forms.GroupBox GroupBox1; private System.Windows.Forms.Button cmdUpdate; private System.Windows.Forms.NumericUpDown udDockPaddingForm; private System.Windows.Forms.NumericUpDown udDockPaddingPanel; private System.Windows.Forms.ruboBox lstDockPanel; private System.Windows.Forms.Label Label3; private System.Windows.Forms.Label Label4; private System.Windows.Forms.ruboBox lstDockTextBox; private System.Windows.Forms.Label Label2; private System.Windows.Forms.Label Label1; private System.Windows.Forms.Panel pnlDock; private System.Windows.Forms.TextBox txtDock; public Form1() { InitializeComponent(); lstDockPanel.Items.AddRange(Enum.GetNames(Dock.GetType())); lstDockTextBox.Items.AddRange(Enum.GetNames(Dock.GetType())); lstDockPanel.Text = Enum.GetName(Dock.GetType(), pnlDock.Dock); lstDockTextBox.Text = Enum.GetName(Dock.GetType(), lstDockTextBox.Dock); } private void cmdUpdate_Click(object sender, EventArgs e) { this.DockPadding.All = (int)udDockPaddingForm.Value; pnlDock.DockPadding.All = (int)udDockPaddingPanel.Value; TypeConverter converter; converter = TypeDescriptor.GetConverter(Dock.GetType()); pnlDock.Dock = (DockStyle)converter.ConvertFromString(lstDockPanel.Text); txtDock.Dock = (DockStyle)converter.ConvertFromString(lstDockTextBox.Text); } private void InitializeComponent() { this.GroupBox1 = new System.Windows.Forms.GroupBox(); this.cmdUpdate = new System.Windows.Forms.Button(); this.udDockPaddingForm = new System.Windows.Forms.NumericUpDown(); this.udDockPaddingPanel = new System.Windows.Forms.NumericUpDown(); this.lstDockPanel = new System.Windows.Forms.ruboBox(); this.Label3 = new System.Windows.Forms.Label(); this.Label4 = new System.Windows.Forms.Label(); this.lstDockTextBox = new System.Windows.Forms.ruboBox(); this.Label2 = new System.Windows.Forms.Label(); this.Label1 = new System.Windows.Forms.Label(); this.pnlDock = new System.Windows.Forms.Panel(); this.txtDock = new System.Windows.Forms.TextBox(); this.GroupBox1.SuspendLayout(); ((System.ruponentModel.ISupportInitialize)(this.udDockPaddingForm)).BeginInit(); ((System.ruponentModel.ISupportInitialize)(this.udDockPaddingPanel)).BeginInit(); this.pnlDock.SuspendLayout(); this.SuspendLayout(); // // GroupBox1 // this.GroupBox1.Controls.Add(this.cmdUpdate); this.GroupBox1.Controls.Add(this.udDockPaddingForm); this.GroupBox1.Controls.Add(this.udDockPaddingPanel); this.GroupBox1.Controls.Add(this.lstDockPanel); this.GroupBox1.Controls.Add(this.Label3); this.GroupBox1.Controls.Add(this.Label4); this.GroupBox1.Controls.Add(this.lstDockTextBox); this.GroupBox1.Controls.Add(this.Label2); this.GroupBox1.Controls.Add(this.Label1); this.GroupBox1.Location = new System.Drawing.Point(202, 20); this.GroupBox1.Name = "GroupBox1"; this.GroupBox1.Size = new System.Drawing.Size(284, 224); this.GroupBox1.TabIndex = 14; this.GroupBox1.TabStop = false; this.GroupBox1.Text = "Configure"; // // cmdUpdate // this.cmdUpdate.Location = new System.Drawing.Point(160, 180); this.cmdUpdate.Name = "cmdUpdate"; this.cmdUpdate.Size = new System.Drawing.Size(84, 24); this.cmdUpdate.TabIndex = 10; this.cmdUpdate.Text = "Update"; this.cmdUpdate.Click += new System.EventHandler(this.cmdUpdate_Click); // // udDockPaddingForm // this.udDockPaddingForm.Increment = new decimal(new int[] { 5, 0, 0, 0}); this.udDockPaddingForm.Location = new System.Drawing.Point(160, 32); this.udDockPaddingForm.Name = "udDockPaddingForm"; this.udDockPaddingForm.Size = new System.Drawing.Size(52, 21); this.udDockPaddingForm.TabIndex = 4; // // udDockPaddingPanel // this.udDockPaddingPanel.Increment = new decimal(new int[] { 5, 0, 0, 0}); this.udDockPaddingPanel.Location = new System.Drawing.Point(160, 56); this.udDockPaddingPanel.Name = "udDockPaddingPanel"; this.udDockPaddingPanel.Size = new System.Drawing.Size(52, 21); this.udDockPaddingPanel.TabIndex = 5; this.udDockPaddingPanel.Value = new decimal(new int[] { 20, 0, 0, 0}); // // lstDockPanel // this.lstDockPanel.DropDownStyle = System.Windows.Forms.ruboBoxStyle.DropDownList; this.lstDockPanel.FormattingEnabled = true; this.lstDockPanel.Location = new System.Drawing.Point(156, 100); this.lstDockPanel.Name = "lstDockPanel"; this.lstDockPanel.Size = new System.Drawing.Size(92, 21); this.lstDockPanel.TabIndex = 8; // // Label3 // this.Label3.Location = new System.Drawing.Point(16, 104); this.Label3.Name = "Label3"; this.Label3.Size = new System.Drawing.Size(136, 20); this.Label3.TabIndex = 6; this.Label3.Text = "Dock Panel To:"; // // Label4 // this.Label4.Location = new System.Drawing.Point(16, 128); this.Label4.Name = "Label4"; this.Label4.Size = new System.Drawing.Size(136, 20); this.Label4.TabIndex = 7; this.Label4.Text = "Dock TextBox To:"; // // lstDockTextBox // this.lstDockTextBox.DropDownStyle = System.Windows.Forms.ruboBoxStyle.DropDownList; this.lstDockTextBox.FormattingEnabled = true; this.lstDockTextBox.Location = new System.Drawing.Point(156, 124); this.lstDockTextBox.Name = "lstDockTextBox"; this.lstDockTextBox.Size = new System.Drawing.Size(92, 21); this.lstDockTextBox.TabIndex = 9; // // Label2 // this.Label2.Location = new System.Drawing.Point(16, 60); this.Label2.Name = "Label2"; this.Label2.Size = new System.Drawing.Size(136, 20); this.Label2.TabIndex = 3; this.Label2.Text = "Panel\"s DockPadding:"; // // Label1 // this.Label1.Location = new System.Drawing.Point(16, 36); this.Label1.Name = "Label1"; this.Label1.Size = new System.Drawing.Size(136, 20); this.Label1.TabIndex = 2; this.Label1.Text = "Form\"s DockPadding:"; // // pnlDock // this.pnlDock.Controls.Add(this.txtDock); this.pnlDock.Dock = System.Windows.Forms.DockStyle.Left; this.pnlDock.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.pnlDock.Location = new System.Drawing.Point(0, 0); this.pnlDock.Name = "pnlDock"; this.pnlDock.Padding = new System.Windows.Forms.Padding(20); this.pnlDock.Size = new System.Drawing.Size(224, 314); this.pnlDock.TabIndex = 13; // // txtDock // this.txtDock.Dock = System.Windows.Forms.DockStyle.Left; this.txtDock.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.txtDock.Location = new System.Drawing.Point(20, 20); this.txtDock.Multiline = true; this.txtDock.Name = "txtDock"; this.txtDock.Size = new System.Drawing.Size(108, 274); this.txtDock.TabIndex = 0; this.txtDock.Text = "This is a TextBox."; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(497, 314); this.Controls.Add(this.GroupBox1); this.Controls.Add(this.pnlDock); this.Text = "Docking At Work"; this.GroupBox1.ResumeLayout(false); ((System.ruponentModel.ISupportInitialize)(this.udDockPaddingForm)).EndInit(); ((System.ruponentModel.ISupportInitialize)(this.udDockPaddingPanel)).EndInit(); this.pnlDock.ResumeLayout(false); this.pnlDock.PerformLayout(); this.ResumeLayout(false); }
[STAThread] static void Main() { Application.EnableVisualStyles(); Application.Run(new Form1()); }
}
</source>
Panel.Paint
<source lang="csharp"> using System; using System.Drawing; using System.Windows.Forms;
class SplitTwoProportional: Form {
Panel panel2; float fProportion = 0.5f; public static void Main() { Application.Run(new SplitTwoProportional()); } public SplitTwoProportional() { Text = ""; Panel panel1 = new Panel(); panel1.Parent = this; panel1.Dock = DockStyle.Fill; panel1.BackColor = Color.Red; panel1.Resize += new EventHandler(PanelOnResize); panel1.Paint += new PaintEventHandler(PanelOnPaint); Splitter split = new Splitter(); split.Parent = this; split.Dock = DockStyle.Left; split.SplitterMoving += new SplitterEventHandler(SplitterOnMoving); panel2 = new Panel(); panel2.Parent = this; panel2.Dock = DockStyle.Left; panel2.BackColor = Color.Lime; panel2.Resize += new EventHandler(PanelOnResize); panel2.Paint += new PaintEventHandler(PanelOnPaint); OnResize(EventArgs.Empty); } protected override void OnResize(EventArgs ea) { base.OnResize(ea); panel2.Width = (int) (fProportion * ClientSize.Width); } void SplitterOnMoving(object obj, SplitterEventArgs sea) { fProportion = (float) sea.SplitX / ClientSize.Width; } void PanelOnResize(object obj, EventArgs ea) { ((Panel) obj).Invalidate(); } void PanelOnPaint(object obj, PaintEventArgs pea) { Panel panel = (Panel) obj; Graphics grfx = pea.Graphics; grfx.DrawEllipse(Pens.Black, 0, 0, panel.Width - 1, panel.Height - 1); }
}
</source>
Panel.Resize
<source lang="csharp"> using System; using System.Drawing; using System.Windows.Forms;
class SplitThreeFrames: Form {
public static void Main() { Application.Run(new SplitThreeFrames()); } public SplitThreeFrames() { Panel panel = new Panel(); panel.Parent = this; panel.Dock = DockStyle.Fill; Splitter split1 = new Splitter(); split1.Parent = this; split1.Dock = DockStyle.Left; Panel panel1 = new Panel(); panel1.Parent = this; panel1.Dock = DockStyle.Left; panel1.BackColor = Color.Lime; panel1.Resize += new EventHandler(PanelOnResize); panel1.Paint += new PaintEventHandler(PanelOnPaint); Panel panel2 = new Panel(); panel2.Parent = panel; panel2.Dock = DockStyle.Fill; panel2.BackColor = Color.Blue; panel2.Resize += new EventHandler(PanelOnResize); panel2.Paint += new PaintEventHandler(PanelOnPaint); Splitter split2 = new Splitter(); split2.Parent = panel; split2.Dock = DockStyle.Top; Panel panel3 = new Panel(); panel3.Parent = panel; panel3.Dock = DockStyle.Top; panel3.BackColor = Color.Tan; panel3.Resize += new EventHandler(PanelOnResize); panel3.Paint += new PaintEventHandler(PanelOnPaint); panel1.Width = ClientSize.Width / 3; panel3.Height = ClientSize.Height / 3; } void PanelOnResize(object obj, EventArgs ea) { ((Panel) obj).Invalidate(); } void PanelOnPaint(object obj, PaintEventArgs pea) { Panel panel = (Panel) obj; Graphics grfx = pea.Graphics; grfx.DrawEllipse(Pens.Black, 0, 0, panel.Width - 1, panel.Height - 1); }
}
</source>