I think vertical tearing is the proper term to describe what I'm seeing but here is an screenshot that shows the issue:
I thought the DoubleBuffered property could help with this but it neither setting it on my Form or inheriting TableLayoutPanel and setting it in the constructor seem to have any effect.
I apologize for the following long block of code, but I felt I should include a complete example that demonstrates the issue. You should just be able to copy it and run it to replicate my issue:
public class ScrollTearingDemo : Form
{
private const int ROW_COUNT = 20;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new ScrollTearingDemo());
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
public ScrollTearingDemo()
{
InitializeComponent();
this.initializeTable();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
// Moved this here to encapsulate demo in single source file
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
//this.tableLayoutPanel1 = new BufferedTableLayoutPanel();
this.SuspendLayout();
//
// tableLayoutPanel1
//
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.tableLayoutPanel1.AutoScroll = true;
this.tableLayoutPanel1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single;
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel1.Dock = DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.TabIndex = 0;
//
// ScrollTearingDemo
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.tableLayoutPanel1);
this.DoubleBuffered = true;
this.Name = "ScrollTearingDemo";
this.Text = "ScrollTearingDemo";
this.ResumeLayout(false);
}
private void initializeTable()
{
// There is one more empty row to take up any extra space
// in the event the number of rows does not fill the table.
this.tableLayoutPanel1.RowCount = ROW_COUNT + 1;
for(int j = 0; j < ROW_COUNT;j++)
{
Label markerLabel = new Label();
markerLabel.Dock = System.Windows.Forms.DockStyle.Fill;
markerLabel.TextAlign = ContentAlignment.MiddleRight;
markerLabel.Name = "Label " + j;
markerLabel.Text = markerLabel.Name;
TextBox inputItem = new TextBox();
inputItem.Dock = DockStyle.Fill;
inputItem.Name = "Input " + j;
inputItem.Text = inputItem.Name;
inputItem.TextAlign = HorizontalAlignment.Right;
inputItem.CausesValidation = true;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.AutoSize, 25F));
this.tableLayoutPanel1.Controls.Add(markerLabel, 0, j);
this.tableLayoutPanel1.Controls.Add(inputItem, 1, j);
}
// Row style for the empty filler row.
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 0F));
this.ResumeLayout();
}
}
The project this is for is limited to C# 2.0.
Related
So, I'm trying to create an accordion with dynamically loaded buttons. In the future, the title of the buttons will change depending on the details I've retrieved from somewhere. For now, what I'm trying to do is to load buttons to look like these:
I've tried doing the following below:
// Forms1.cs
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
int buttonCount = 3;
var buttons = new FontAwesome.Sharp.IconButton[buttonCount];
for (int i = 0; i < buttonCount; i++)
{
var btn = new FontAwesome.Sharp.IconButton
{
Text = "Button " + i,
TextAlign = ContentAlignment.MiddleLeft,
IconChar = FontAwesome.Sharp.IconChar.Book,
IconColor = ColorTranslator.FromHtml("#6A6A73"),
IconSize = 20,
IconFont = FontAwesome.Sharp.IconFont.Auto,
TextImageRelation = TextImageRelation.ImageBeforeText,
FlatStyle = FlatStyle.Flat
};
btn.FlatAppearance.BorderSize = 0;
btn.ForeColor = ColorTranslator.FromHtml("#6A6A73");
btn.BackColor = ColorTranslator.FromHtml("#FDFEFF");
btn.Dock = DockStyle.Top;
buttons[i] = btn;
}
flowLayoutPanel1.Controls.AddRange(buttons);
}
}
}
// Forms1.Designer.cs
namespace WindowsFormsApp1
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.SuspendLayout();
//
// flowLayoutPanel1
//
this.flowLayoutPanel1.BackColor = System.Drawing.SystemColors.ControlLight;
this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Left;
this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size(200, 450);
this.flowLayoutPanel1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.flowLayoutPanel1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
}
}
Here's what it looks like after building and running the application:
What am I doing wrong?
Form1_Load method is not subscribed to Load event of your form. Body of InitializeComponent is missing following line of code.
this.Load += new System.EventHandler(this.Form1_Load);
Insert this line before this.ResumeLayout(false);. You can fix it in designer as well.
I would like to disable the button part of a ToolStripSplitButton in a c# winforms app. As far as I see it is not possible and I would like to avoid a complex solution (rewriting entire toolstripsplitbutton) so I'm trying to disable visually at least, ie. draw a grayed icon when button part disabled.
First I browsed referencesource and found that ToolStripRenderer and ToolStripProfessionalRenderer uses some 'internal' properties and methods in OnRenderItemImage(ToolStripItemImageRenderEventArgs e) so I cannot mimic (copy-and-modify-a-bit) the behaviour of OnRenderItemImage.
Next I tried the following code.
Basically it works, the toolStripSplitButton1 is grayed out when the Tag is boolean false.
But this solution kills all my System.Windows.Forms.Timer somehow! Try this code, when toolStripSplitButton1.Tag == false then the toolstrip-independent timer1 does not tick anymore. And the toolStripSplitButton1 tooltip does not show up (guess because it uses Timer as well).
(button1 and button1_Click is just for toggle toolStripSplitButton1.Tag)
My first question is why OnRenderItemImage kills all System.Windows.Forms.Timer?
Second question is how to achieve the original aim to gray out button icon at least visually independently of the button itself?
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
toolStrip1.Renderer = new MyToolStripProfessionalRenderer();
toolStripSplitButton1.Tag = false; // this is for disabling button part
toolStripSplitButton1.ToolTipText = "toolStripSplitButton1 ToolTip";
System.Windows.Forms.Timer timer1 = new Timer();
timer1.Interval = 1000;
timer1.Tick += T_Tick;
timer1.Start();
}
int ticks = 0;
private void T_Tick(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine(ticks++);
}
private void button1_Click(object sender, EventArgs e)
{
toolStripSplitButton1.Tag = !((bool)toolStripSplitButton1.Tag);
}
}
class MyToolStripProfessionalRenderer : ToolStripProfessionalRenderer
{
protected override void OnRenderItemImage(ToolStripItemImageRenderEventArgs e)
{
try
{
if (e.Item.Enabled &&
e.Item.Tag?.GetType() == typeof(bool) &&
!(bool)e.Item.Tag)
{
e.Item.Enabled = false;
base.OnRenderItemImage(e);
e.Item.Enabled = true;
}
else
base.OnRenderItemImage(e);
}
catch (Exception ex)
{
// this never reached, there's no exceptions
System.Diagnostics.Debug.WriteLine(ex);
}
}
}
}
Designer.cs:
namespace WindowsFormsApplication
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.toolStripSplitButton1 = new System.Windows.Forms.ToolStripSplitButton();
this.button1 = new System.Windows.Forms.Button();
this.toolStrip1.SuspendLayout();
this.SuspendLayout();
//
// toolStrip1
//
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripSplitButton1});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(352, 25);
this.toolStrip1.TabIndex = 0;
this.toolStrip1.Text = "toolStrip1";
//
// toolStripSplitButton1
//
this.toolStripSplitButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.toolStripSplitButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripSplitButton1.Image")));
this.toolStripSplitButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripSplitButton1.Name = "toolStripSplitButton1";
this.toolStripSplitButton1.Size = new System.Drawing.Size(32, 22);
this.toolStripSplitButton1.Text = "toolStripSplitButton1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(13, 64);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(352, 265);
this.Controls.Add(this.button1);
this.Controls.Add(this.toolStrip1);
this.Name = "Form1";
this.Text = "Form1";
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.ToolStripSplitButton toolStripSplitButton1;
private System.Windows.Forms.Button button1;
}
}
I don't think that using a timer for tracking the change is a good idea. What I suggest is create a changeOccurred event and do the operations inside the event.
I am creating an application using C# and WinForms. I have three panels. Two of them are fairly large and are currently positioned side by side. I am trying to implement a feature for users who have smaller screens or wish to have the form as a smaller size. I am relocating the right panel underneath the middle one and re-centering them in the form.
The issue that I have though is when the user scrolls down and re-sizes the form again the two middle panels (the big ones) move lower in the form leaving a chunk of blank space at the top.
My code is fairly simple
namespace ResizeCheck
{
public partial class Form1 : Form
{
Point originalLeft, originalRight;
bool flag = false;
public Form1()
{
InitializeComponent();
originalLeft = leftInnerPanel.Location;
originalRight = rightInnerPanel.Location;
}
private void vertical()//move the right panel under the left one
{
leftInnerPanel.Location = new Point(this.Width / 2 - leftInnerPanel.Width / 2, 5);
if (leftInnerPanel.Location.X <= buttonPanel.Location.X + buttonPanel.Width)
{
leftInnerPanel.Location = new Point(buttonPanel.Location.X + buttonPanel.Width, leftInnerPanel.Location.Y);
}
rightInnerPanel.Location = new Point(leftInnerPanel.Location.X, leftInnerPanel.Height + 10);
MessageBox.Show("inside vertical " + leftInnerPanel.Location.Y);
}
private void horizontal()//relocate to their original horizontal position
{
leftInnerPanel.Location = new Point(buttonPanel.Location.X + buttonPanel.Width + 10, 5);
if (leftInnerPanel.Location.X <= buttonPanel.Location.X + buttonPanel.Width)
{
leftInnerPanel.Location = new Point(buttonPanel.Location.X + buttonPanel.Width, leftInnerPanel.Location.Y);
}
rightInnerPanel.Location = new Point(leftInnerPanel.Location.X + leftInnerPanel.Width + 20, 5);
MessageBox.Show("inside horizontal " + leftInnerPanel.Location.Y);
}
private void Form1_SizeChanged(object sender, EventArgs e)//handler for when the form is resized by the user
{
if ((leftInnerPanel.Width + rightInnerPanel.Width + buttonPanel.Width) >= this.Width)
{
vertical();
//flag = true;
}
else if ((leftInnerPanel.Width + rightInnerPanel.Width + buttonPanel.Width) + 50 < this.Width)
{
horizontal();
//flag = false;
}
}
}
}
My designer code is also fairly simple.
namespace ResizeCheck
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.rightInnerPanel = new System.Windows.Forms.Panel();
this.leftInnerPanel = new System.Windows.Forms.Panel();
this.buttonPanel = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// rightInnerPanel
//
this.rightInnerPanel.BackColor = System.Drawing.Color.Yellow;
this.rightInnerPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.rightInnerPanel.Location = new System.Drawing.Point(887, 13);
this.rightInnerPanel.Name = "rightInnerPanel";
this.rightInnerPanel.Size = new System.Drawing.Size(662, 936);
this.rightInnerPanel.TabIndex = 1;
//
// leftInnerPanel
//
this.leftInnerPanel.BackColor = System.Drawing.Color.Yellow;
this.leftInnerPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.leftInnerPanel.Location = new System.Drawing.Point(219, 13);
this.leftInnerPanel.Name = "leftInnerPanel";
this.leftInnerPanel.Size = new System.Drawing.Size(662, 936);
this.leftInnerPanel.TabIndex = 0;
//
// buttonPanel
//
this.buttonPanel.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.buttonPanel.Location = new System.Drawing.Point(13, 13);
this.buttonPanel.Name = "buttonPanel";
this.buttonPanel.Size = new System.Drawing.Size(200, 258);
this.buttonPanel.TabIndex = 1;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(1008, 601);
this.Controls.Add(this.rightInnerPanel);
this.Controls.Add(this.buttonPanel);
this.Controls.Add(this.leftInnerPanel);
this.Name = "Form1";
this.Text = "Form1";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel rightInnerPanel;
private System.Windows.Forms.Panel leftInnerPanel;
private System.Windows.Forms.Panel buttonPanel;
}
}
You are not accounting for how much the form has scrolled, you are simply plopping the panel at the top of the visible client area.
Change your Vertical() method thusly:
private void vertical()
{
leftInnerPanel.Location = new Point(this.Width / 2 - leftInnerPanel.Width / 2, 5 - VerticalScroll.Value);
if (leftInnerPanel.Location.X <= buttonPanel.Location.X + buttonPanel.Width)
leftInnerPanel.Location = new Point(buttonPanel.Location.X + buttonPanel.Width, leftInnerPanel.Location.Y);
rightInnerPanel.Location = new Point(leftInnerPanel.Location.X, leftInnerPanel.Bottom + 10);
}
Two points to note:
1) use of the VerticalScroll member.
2) use of Bottom instead of Height (and Right instead of Width in the Horizontal() method).
In vertical()
since you are not adjusting the Y of leftInnerPanel, we can straightaway use the buttonPanel.Top
leftInnerPanel.Location = new Point(this.Width / 2 - leftInnerPanel.Width / 2, buttonPanel.Top);
Secondly,
//rightInnerPanel.Location = new Point(leftInnerPanel.Location.X, leftInnerPanel.Height + 10);
rightInnerPanel.Location = new Point(leftInnerPanel.Location.X, leftInnerPanel.Bottom + 10);
i am using visual studio 2010 for making a Drawing Application but the problem is when i try to compile the program it says
1)The type name 'DrawingBoard' does not exist in the type 'DrawingBoard.DrawingBoard' line 33
2)The type name 'Toolbox' does not exist in the type 'DrawingBoard.DrawingBoard' line 34
3)An object reference is required for the non-static field, method, or property 'DrawingBoard.DrawingBoard.EditOption.get' line 74
the code of this program is below i have pointed the errors with the word problem. i would be very Thankful if you help me.
using System.Drawing;
namespace DrawingBoard
{
partial class WinForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.splitContainerMain = new System.Windows.Forms.SplitContainer();
this.drawingBoard = new DrawingBoard.DrawingBoard();//problem
this.toolBox = new DrawingBoard.Toolbox.ToolBox();//problem
this.splitContainerMain.Panel1.SuspendLayout();
this.splitContainerMain.Panel2.SuspendLayout();
this.splitContainerMain.SuspendLayout();
this.SuspendLayout();
//
// splitContainerMain
//
this.splitContainerMain.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainerMain.Location = new System.Drawing.Point(0, 0);
this.splitContainerMain.Margin = new System.Windows.Forms.Padding(2);
this.splitContainerMain.Name = "splitContainerMain";
//
// splitContainerMain.Panel1
//
this.splitContainerMain.Panel1.Controls.Add(this.drawingBoard);
//
// splitContainerMain.Panel2
//
this.splitContainerMain.Panel2.Controls.Add(this.toolBox);
this.splitContainerMain.Size = new System.Drawing.Size(853, 553);
this.splitContainerMain.SplitterDistance = 532;
this.splitContainerMain.SplitterWidth = 3;
this.splitContainerMain.TabIndex = 37;
//
// drawingBoard
//
this.drawingBoard.AllowDrop = true;
this.drawingBoard.AutoScroll = true;
this.drawingBoard.BackColor = System.Drawing.Color.White;
this.drawingBoard.BackgroundImageAlpha = ((byte)(255));
this.drawingBoard.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.drawingBoard.BackgroundImageX = 0;
this.drawingBoard.BackgroundImageY = 0;
this.drawingBoard.BoundedCanvasHeight = 1140;
this.drawingBoard.BoundedCanvasWidth = 810;
this.drawingBoard.CanvasOriginX = 0;
this.drawingBoard.CanvasOriginY = 0;
this.drawingBoard.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.Default;
this.drawingBoard.Dock = System.Windows.Forms.DockStyle.Fill;
this.drawingBoard.EditOption = DrawingBoard.EditOption.Select; //problem
this.drawingBoard.GridColor = System.Drawing.Color.Gainsboro;
this.drawingBoard.GridSize = 0;
this.drawingBoard.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default;
this.drawingBoard.IsBoundedCanvas = true;
this.drawingBoard.Location = new System.Drawing.Point(0, 0);
this.drawingBoard.Name = "drawingBoard";
this.drawingBoard.PaperOutsideColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(255)))));
this.drawingBoard.ShowPaperOutside = true;
this.drawingBoard.Size = new System.Drawing.Size(532, 553);
this.drawingBoard.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
this.drawingBoard.StickyEditOption = true;
this.drawingBoard.TabIndex = 3;
this.drawingBoard.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
this.drawingBoard.Zoom = 1F;
//
// toolBox
//
this.toolBox.AutoSize = true;
this.toolBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.toolBox.Drawingboard = null;
this.toolBox.Location = new System.Drawing.Point(0, 0);
this.toolBox.Margin = new System.Windows.Forms.Padding(4);
this.toolBox.Name = "toolBox";
this.toolBox.Size = new System.Drawing.Size(318, 553);
this.toolBox.TabIndex = 1;
//
// WinForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
this.ClientSize = new System.Drawing.Size(853, 553);
this.Controls.Add(this.splitContainerMain);
this.Name = "WinForm";
this.Text = "DrawingBoard";
this.splitContainerMain.Panel1.ResumeLayout(false);
this.splitContainerMain.Panel2.ResumeLayout(false);
this.splitContainerMain.Panel2.PerformLayout();
this.splitContainerMain.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.SplitContainer splitContainerMain;
private DrawingBoard drawingBoard;
private global::DrawingBoard.Toolbox.ToolBox toolBox;
}
}
It sounds like you have a namespace issue and it looks like DrawingBoard.DrawingBoard is probably going to cause confusion. Try to rename your namespace to omit duplicate names. Use a format such as Solution.Project.Module. In your case it could be MySolution.DrawingBoard.
I have a TableLayoutPanel to which I add rows dynamically.
Each row has an absolute size.
I set the AutoScroll to "true", but when I add rows that go out of the display of the TableLayoutPanel, I don't see the scroll.
This is the designer code:
namespace WindowsFormsApplication1
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.AutoScroll = true;
this.tableLayoutPanel1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single;
this.tableLayoutPanel1.ColumnCount = 1;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Location = new System.Drawing.Point(24, 48);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 1;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(239, 163);
this.tableLayoutPanel1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(24, 10);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(239, 28);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Controls.Add(this.tableLayoutPanel1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.Button button1;
}
}
and this is how I add rows:
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
tableLayoutPanel1.RowCount++;
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 30));
Button b = new Button();
tableLayoutPanel1.Controls.Add(b, 0, tableLayoutPanel1.RowCount - 1);
}
}
}
Does anybody know what's going on?
thanks :)
Set the AutoScroll property to True.
Make sure that the default rows that get added by the designer do not cause any trouble. Make your constructor look like this:
public Form1() {
InitializeComponent();
tableLayoutPanel1.RowCount = 0;
tableLayoutPanel1.RowStyles.Clear();
tableLayoutPanel1.AutoScroll = true;
}
Looks like you're missing tableLayoutPanel.AutoSize = true.
Try the below line which may work for you:
this.tableLayoutPanel1.AutoScroll = true;
this.tableLayoutPanel1.Dock = DockStyle.Top;