Using MS Chart component in C# and trying to determine the item hit (HitResult). It seems that the result is not always accurate. If I have two charts. Right hand side is always a column chart. Left hand side is sometimes a column chart and sometimes a doughnut. The Item returned from HitResult when left hand side is a Doughnut is not correct. Image of what I mean :
namespace WindowsFormsApplication5
{
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.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
System.Windows.Forms.DataVisualization.Charting.DataPoint dataPoint1 = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0D, 10D);
System.Windows.Forms.DataVisualization.Charting.DataPoint dataPoint2 = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0D, 20D);
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
System.Windows.Forms.DataVisualization.Charting.DataPoint dataPoint3 = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0D, 10D);
System.Windows.Forms.DataVisualization.Charting.DataPoint dataPoint4 = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0D, 20D);
this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
this.chart2 = new System.Windows.Forms.DataVisualization.Charting.Chart();
((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.chart2)).BeginInit();
this.SuspendLayout();
//
// chart1
//
chartArea1.Name = "ChartArea1";
this.chart1.ChartAreas.Add(chartArea1);
legend1.Name = "Legend1";
this.chart1.Legends.Add(legend1);
this.chart1.Location = new System.Drawing.Point(13, 13);
this.chart1.Name = "chart1";
series1.ChartArea = "ChartArea1";
series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Doughnut;
series1.Label = "bbb";
series1.Legend = "Legend1";
series1.Name = "Series1";
dataPoint1.AxisLabel = "AAA";
dataPoint2.AxisLabel = "BBB";
dataPoint2.Label = "aaa";
series1.Points.Add(dataPoint1);
series1.Points.Add(dataPoint2);
this.chart1.Series.Add(series1);
this.chart1.Size = new System.Drawing.Size(300, 300);
this.chart1.TabIndex = 0;
this.chart1.Text = "chart1";
this.chart1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart1_MouseDown);
//
// chart2
//
chartArea2.Name = "ChartArea1";
this.chart2.ChartAreas.Add(chartArea2);
legend2.Name = "Legend1";
this.chart2.Legends.Add(legend2);
this.chart2.Location = new System.Drawing.Point(341, 13);
this.chart2.Name = "chart2";
series2.ChartArea = "ChartArea1";
series2.Legend = "Legend1";
series2.Name = "Series1";
dataPoint3.AxisLabel = "111";
dataPoint4.AxisLabel = "2222";
series2.Points.Add(dataPoint3);
series2.Points.Add(dataPoint4);
this.chart2.Series.Add(series2);
this.chart2.Size = new System.Drawing.Size(300, 300);
this.chart2.TabIndex = 1;
this.chart2.Text = "chart2";
this.chart2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart1_MouseDown);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(801, 490);
this.Controls.Add(this.chart2);
this.Controls.Add(this.chart1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.chart2)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataVisualization.Charting.Chart chart1;
private System.Windows.Forms.DataVisualization.Charting.Chart chart2;
}
}
Looking at the Designer code the problem is easily found: You hook up the very same event to two different Chart controls.
This is actually a common way to avoid redundant code; the trick is to cast the sender to the right control type and then use the result.
So you probably do a hit test with the wrong Chart; you still don't show the MouseClick or MouseDown code but most likely it contains something like this:
HitTestResult hitr = chart1.HitTest(e.X, e.Y);
What you would need, if you really want to use only one event is this:
HitTestResult hitr = ((Chart)sender).HitTest(e.X, e.Y);
As I have explained in my comments above, there is really not need to have two Chart controls in the first place; add an extra ChartArea and assign the series you want to show in it the name:
ChartArea ca2 = chart1.ChartAreas.Add("ca2");
series1.ChartArea = "ca2";
You can switch between ChartTypes dynamically, maybe with a CheckBox:
series1.ChartType = cbx_Pie.Checked ? SeriesChartType.Pie : SeriesChartType.Column;
Using two (or more) ChartAreas in one Chart has a few advantages. Not only will they shar a BorderStyle and Background; they will also both draw onto the same Bitmap with DrawToBitmap and they will scale together when resizing the `Chart. But this is your design..
Related
I have a groupbox which I created a custom paint event for so that I
can control the border color.
It works great when the groupbox is on a form but when the groupbox is
on a tabpage, the control does not paint properly. Everything is blurry
and the child controls inside the groupbox are also blurry and get a border
drawn.
Any gentle help would be greatly appreciated!
Thanks,
Dan
using System.Drawing;
using System.Windows.Forms;
namespace CustomGroupBoxPaint
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
///////////////////////////////////////////////////////////////////////
private void groupBox_Paint(object sender, PaintEventArgs e)
{
// Default border line color
Color lineColor = Color.LightGray;
// Get the control
GroupBox gb = (GroupBox)sender;
// Figure out which color to use
if (gb.Enabled == true)
{
// User black line
lineColor = Color.Black;
}
else
{
// Use dark gray color
lineColor = Color.DarkGray;
}
//get the text size in groupbox
System.Drawing.Size tSize = TextRenderer.MeasureText(e.Graphics, gb.Text, gb.Font);
// Draw groupbox border
Rectangle borderRect = e.ClipRectangle;
borderRect.Y = (borderRect.Y + (tSize.Height / 2));
borderRect.Height = (borderRect.Height - (tSize.Height / 2));
ControlPaint.DrawBorder(e.Graphics, borderRect, lineColor, ButtonBorderStyle.Solid);
// Draw groupbox text
Rectangle textRect = e.ClipRectangle;
textRect.X = (textRect.X + 6);
textRect.Width = tSize.Width + 5;
textRect.Height = tSize.Height;
e.Graphics.FillRectangle(new SolidBrush(gb.BackColor), textRect);
TextRenderer.DrawText(e.Graphics, gb.Text, gb.Font, textRect, gb.ForeColor);
}
}
}
namespace CustomGroupBoxPaint
{
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.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.checkBox3 = new System.Windows.Forms.CheckBox();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.checkBox4 = new System.Windows.Forms.CheckBox();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox1.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox4.SuspendLayout();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Location = new System.Drawing.Point(40, 24);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(376, 352);
this.tabControl1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.groupBox2);
this.tabPage1.Controls.Add(this.groupBox1);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(368, 326);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "tabPage1";
this.tabPage1.UseVisualStyleBackColor = true;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.checkBox2);
this.groupBox2.Enabled = false;
this.groupBox2.Location = new System.Drawing.Point(52, 168);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(272, 100);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "DisabledGBTabPage";
this.groupBox2.Paint += new System.Windows.Forms.PaintEventHandler(this.groupBox_Paint);
//
// checkBox2
//
this.checkBox2.AutoSize = true;
this.checkBox2.Location = new System.Drawing.Point(64, 42);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(80, 17);
this.checkBox2.TabIndex = 1;
this.checkBox2.Text = "checkBox2";
this.checkBox2.UseVisualStyleBackColor = true;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.checkBox1);
this.groupBox1.Location = new System.Drawing.Point(48, 32);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(272, 100);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "EnabledGBTabPage";
this.groupBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.groupBox_Paint);
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(64, 48);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(80, 17);
this.checkBox1.TabIndex = 0;
this.checkBox1.Text = "checkBox1";
this.checkBox1.UseVisualStyleBackColor = true;
//
// tabPage2
//
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
this.tabPage2.Size = new System.Drawing.Size(368, 326);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "tabPage2";
this.tabPage2.UseVisualStyleBackColor = true;
//
// groupBox3
//
this.groupBox3.Controls.Add(this.checkBox3);
this.groupBox3.Location = new System.Drawing.Point(512, 78);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(200, 100);
this.groupBox3.TabIndex = 1;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "EnabledGBform";
this.groupBox3.Paint += new System.Windows.Forms.PaintEventHandler(this.groupBox_Paint);
//
// checkBox3
//
this.checkBox3.AutoSize = true;
this.checkBox3.Location = new System.Drawing.Point(60, 42);
this.checkBox3.Name = "checkBox3";
this.checkBox3.Size = new System.Drawing.Size(80, 17);
this.checkBox3.TabIndex = 1;
this.checkBox3.Text = "checkBox3";
this.checkBox3.UseVisualStyleBackColor = true;
//
// groupBox4
//
this.groupBox4.Controls.Add(this.checkBox4);
this.groupBox4.Enabled = false;
this.groupBox4.Location = new System.Drawing.Point(512, 238);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(200, 100);
this.groupBox4.TabIndex = 2;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "DisabledGBform";
this.groupBox4.Paint += new System.Windows.Forms.PaintEventHandler(this.groupBox_Paint);
//
// checkBox4
//
this.checkBox4.AutoSize = true;
this.checkBox4.Location = new System.Drawing.Point(60, 42);
this.checkBox4.Name = "checkBox4";
this.checkBox4.Size = new System.Drawing.Size(80, 17);
this.checkBox4.TabIndex = 1;
this.checkBox4.Text = "checkBox4";
this.checkBox4.UseVisualStyleBackColor = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.tabControl1);
this.Name = "Form1";
this.Text = "Form1";
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.groupBox4.ResumeLayout(false);
this.groupBox4.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.CheckBox checkBox3;
private System.Windows.Forms.CheckBox checkBox4;
}
}
Screen shot showing problem
I am trying to have my custom control somehow auto-fit into the flow layout panel at horizontal edges.
What I am trying to accomplish is a vertical list of shown custom control. But what I get is below:
Code for my custom control is:
namespace CustomControl
{
partial class ChatMessage
{
/// <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 Component 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(ChatMessage));
this.ContentsTable = new System.Windows.Forms.TableLayoutPanel();
this.DateTimeLabel = new System.Windows.Forms.Label();
this.NumberLabel = new System.Windows.Forms.Label();
this.NameLabel = new System.Windows.Forms.Label();
this.MessageLabel = new System.Windows.Forms.Label();
this.DirectionLabel = new System.Windows.Forms.Label();
this.ContentsTable.SuspendLayout();
this.SuspendLayout();
//
// ContentsTable
//
this.ContentsTable.AutoSize = true;
this.ContentsTable.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ContentsTable.BackColor = System.Drawing.Color.White;
this.ContentsTable.ColumnCount = 2;
this.ContentsTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.ContentsTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.ContentsTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.ContentsTable.Controls.Add(this.DateTimeLabel, 1, 2);
this.ContentsTable.Controls.Add(this.NumberLabel, 1, 0);
this.ContentsTable.Controls.Add(this.NameLabel, 0, 0);
this.ContentsTable.Controls.Add(this.MessageLabel, 0, 1);
this.ContentsTable.Controls.Add(this.DirectionLabel, 0, 2);
this.ContentsTable.Dock = System.Windows.Forms.DockStyle.Fill;
this.ContentsTable.Location = new System.Drawing.Point(48, 0);
this.ContentsTable.Name = "ContentsTable";
this.ContentsTable.RowCount = 3;
this.ContentsTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.ContentsTable.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.ContentsTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.ContentsTable.Size = new System.Drawing.Size(592, 54);
this.ContentsTable.TabIndex = 0;
//
// DateTimeLabel
//
this.DateTimeLabel.Dock = System.Windows.Forms.DockStyle.Fill;
this.DateTimeLabel.Font = new System.Drawing.Font("Calibri", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.DateTimeLabel.ForeColor = System.Drawing.SystemColors.ControlDark;
this.DateTimeLabel.Location = new System.Drawing.Point(299, 104);
this.DateTimeLabel.Name = "DateTimeLabel";
this.DateTimeLabel.Size = new System.Drawing.Size(290, 20);
this.DateTimeLabel.TabIndex = 0;
this.DateTimeLabel.Text = "Date / Time";
this.DateTimeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// NumberLabel
//
this.NumberLabel.Dock = System.Windows.Forms.DockStyle.Fill;
this.NumberLabel.Font = new System.Drawing.Font("Calibri", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.NumberLabel.Location = new System.Drawing.Point(299, 0);
this.NumberLabel.Name = "NumberLabel";
this.NumberLabel.Size = new System.Drawing.Size(290, 20);
this.NumberLabel.TabIndex = 1;
this.NumberLabel.Text = "Number or ID";
this.NumberLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// NameLabel
//
this.NameLabel.Dock = System.Windows.Forms.DockStyle.Fill;
this.NameLabel.Font = new System.Drawing.Font("Calibri", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.NameLabel.Location = new System.Drawing.Point(3, 0);
this.NameLabel.Name = "NameLabel";
this.NameLabel.Size = new System.Drawing.Size(290, 20);
this.NameLabel.TabIndex = 2;
this.NameLabel.Text = "Name";
this.NameLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// MessageLabel
//
this.MessageLabel.AutoSize = true;
this.ContentsTable.SetColumnSpan(this.MessageLabel, 2);
this.MessageLabel.Dock = System.Windows.Forms.DockStyle.Fill;
this.MessageLabel.Font = new System.Drawing.Font("Calibri", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.MessageLabel.Location = new System.Drawing.Point(3, 20);
this.MessageLabel.Name = "MessageLabel";
this.MessageLabel.Size = new System.Drawing.Size(586, 84);
this.MessageLabel.TabIndex = 3;
this.MessageLabel.Text = resources.GetString("MessageLabel.Text");
//
// DirectionLabel
//
this.DirectionLabel.Dock = System.Windows.Forms.DockStyle.Fill;
this.DirectionLabel.ForeColor = System.Drawing.Color.LightGray;
this.DirectionLabel.Location = new System.Drawing.Point(3, 104);
this.DirectionLabel.Name = "DirectionLabel";
this.DirectionLabel.Size = new System.Drawing.Size(290, 20);
this.DirectionLabel.TabIndex = 4;
this.DirectionLabel.Text = "Direction";
this.DirectionLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// ChatMessage
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.Controls.Add(this.ContentsTable);
this.MinimumSize = new System.Drawing.Size(320, 0);
this.Name = "ChatMessage";
this.Padding = new System.Windows.Forms.Padding(48, 0, 0, 0);
this.Size = new System.Drawing.Size(640, 54);
this.ContentsTable.ResumeLayout(false);
this.ContentsTable.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TableLayoutPanel ContentsTable;
private System.Windows.Forms.Label DateTimeLabel;
private System.Windows.Forms.Label NumberLabel;
private System.Windows.Forms.Label NameLabel;
private System.Windows.Forms.Label MessageLabel;
private System.Windows.Forms.Label DirectionLabel;
}
}
You can see my custom control overflows form size.
Note: Flow layout panel used in the picture has a dock fill, flow direction = top down & wrap contents = false.
Can anyone please suggest?
Using the custom label class from this page for the message label inside panel as suggested by #Reza Aghaei did the job. See the result below, this is exactly what I wanted.
I am implementing a winform application in c# so that it contains four picture boxes and some control buttons in one corner.
My main problem is that I cannot achieve the behaviour shown in the picture. The idea is to automatically resize the picture boxes when the form is resized. The area of the control panel should stay the same and only the area containing the boxes should be resized accordingly.
I have been playing with anchor and dock properties but I dont get the desire output.
Anyone could give me a hint?
Thanks and kind regards,
Bilbinight
So, let's say you have the following picture boxes:
pictureBox1 | pictureBox2 | panel
------------|------------
pictureBox3 | pictureBox4
Then the following should do the trick:
set the forms Resize event to this eventhandler:
private void Form1_Resize(object sender, EventArgs e)
{
int spaceBetweenPictures = 19;
int widthToFill = (this.Width - 40 - panel.Width) - spaceBetweenPictures;
int heightToFill = this.Height - 80;
pictureBox1.Width = widthToFill / 2;
pictureBox1.Height = heightToFill / 2;
// Setting the sizes of all the three pictureboxes to the sizes of the first one.
pictureBox2.Width = pictureBox1.Width;
pictureBox2.Height = pictureBox1.Height;
pictureBox3.Width = pictureBox1.Width;
pictureBox3.Height = pictureBox1.Height;
pictureBox4.Width = pictureBox1.Width;
pictureBox4.Height = pictureBox1.Height;
// Setting the positions:
pictureBox2.Location = new Point(pictureBox1.Width + spaceBetweenPictures, pictureBox1.Location.Y);
pictureBox3.Location = new Point(pictureBox1.Location.X, pictureBox1.Height + spaceBetweenPictures);
pictureBox4.Location = new Point(pictureBox2.Location.X, pictureBox3.Location.Y);
}
Of course you should modify the magic numbers in this code (19, 40, 80) accordingly, to suit your program (that depends a lot on whether you use border on your form or not).
UPDATE:
If you want your pictureboxes square shaped then just ignore the heightToFill variable and use widthToFill instead when setting the Height of pictureBox1. Or set:
pictureBox1.Height = pictureBox.Width;
And I also forgot to mention that the panel of course should be aligned Top, Right. So set the panel's Anchor property to:
AnchorStyles.Top | AnchorStyles.Right;
Are four image boxes supposed to support resizing at runtime (allowing end user to resize)? if not then following will give you desired result.
1 TableLayoutPanel with 2 rows and two columns. Set the initial size to fill the desired area, set the anchor to all four directions.
Add 4 picture boxes to 4 cells and set Dock to Fill for all Picture Boxes.
Add a panel to the right side of form, and make it fit to cover your controls area. Set the anchor Top, Bottom, Right.
Here is sample code:
//frmResizing.cs
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class frmResizing : Form
{
public frmResizing()
{
InitializeComponent();
}
}
}
//frmResizing.Designer.cs code
namespace WindowsFormsApplication1
{
partial class frmResizing
{
/// <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.panel1 = new System.Windows.Forms.Panel();
this.pictureBox4 = new System.Windows.Forms.PictureBox();
this.pictureBox3 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.tableLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox4)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.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.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Controls.Add(this.pictureBox4, 1, 1);
this.tableLayoutPanel1.Controls.Add(this.pictureBox3, 0, 1);
this.tableLayoutPanel1.Controls.Add(this.pictureBox2, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.pictureBox1, 0, 0);
this.tableLayoutPanel1.Location = new System.Drawing.Point(2, 1);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(544, 561);
this.tableLayoutPanel1.TabIndex = 0;
//
// panel1
//
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.BackColor = System.Drawing.Color.Red;
this.panel1.Location = new System.Drawing.Point(553, 1);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(107, 561);
this.panel1.TabIndex = 1;
//
// pictureBox4
//
this.pictureBox4.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox4.Image = global::WindowsFormsApplication1.Properties.Resources.download;
this.pictureBox4.Location = new System.Drawing.Point(275, 283);
this.pictureBox4.Name = "pictureBox4";
this.pictureBox4.Size = new System.Drawing.Size(266, 275);
this.pictureBox4.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox4.TabIndex = 3;
this.pictureBox4.TabStop = false;
//
// pictureBox3
//
this.pictureBox3.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox3.Image = global::WindowsFormsApplication1.Properties.Resources.pizza_page;
this.pictureBox3.Location = new System.Drawing.Point(3, 283);
this.pictureBox3.Name = "pictureBox3";
this.pictureBox3.Size = new System.Drawing.Size(266, 275);
this.pictureBox3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox3.TabIndex = 2;
this.pictureBox3.TabStop = false;
//
// pictureBox2
//
this.pictureBox2.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox2.Image = global::WindowsFormsApplication1.Properties.Resources.images;
this.pictureBox2.Location = new System.Drawing.Point(275, 3);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(266, 274);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox2.TabIndex = 1;
this.pictureBox2.TabStop = false;
//
// pictureBox1
//
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Image = global::WindowsFormsApplication1.Properties.Resources.download__1_;
this.pictureBox1.Location = new System.Drawing.Point(3, 3);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(266, 274);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(660, 562);
this.Controls.Add(this.panel1);
this.Controls.Add(this.tableLayoutPanel1);
this.Name = "Form2";
this.Text = "Form2";
this.tableLayoutPanel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox4)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.PictureBox pictureBox4;
private System.Windows.Forms.PictureBox pictureBox3;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Panel panel1;
}
}
I am new to WinForms, and I am very used to styling in CSS, so maybe I am not looking at WinForm's Bottom Margin property correctly, but, no matter what element I set an arbitrarily large bottom-margin number to, it seems to have no effect, at all.
What I want is to extend the design of the form to below the initial viewable window (vertical-scroll bar shows up just fine), and set a bottom-margin to these elements so that the very bottom of the element isn't flush with the very bottom of the window (a little space would be nice).
I have tried this on several elements just to see if it was only the one element (or the fact that it was out of the initial visible part of the window) that was giving me problems, but I can't seem to get any effect out of the margin property at all.
Looking here: http://msdn.microsoft.com/en-us/library/ms229627.aspx It seems that this is, indeed, what the margin property should do. Also, I can't find any padding within the GUI controls for any element.
As it stands, I am mostly only coding C# for the event handlers, until I get a better grasp of where Visual Studio puts everything within the two partial classes (and the other .cs files).
If it helps, here is the code for the designer file:
namespace WindowsFormsApplication1
{
partial class IntroForm
{
/// <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.WelcomeHeader = new System.Windows.Forms.Label();
this.ActionSelect = new System.Windows.Forms.ComboBox();
this.ProceedBtn = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// WelcomeHeader
//
this.WelcomeHeader.AutoSize = true;
this.WelcomeHeader.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.WelcomeHeader.Location = new System.Drawing.Point(84, 30);
this.WelcomeHeader.Name = "WelcomeHeader";
this.WelcomeHeader.Size = new System.Drawing.Size(367, 25);
this.WelcomeHeader.TabIndex = 0;
this.WelcomeHeader.Text = "Please Select Which Content You";
//
// ActionSelect
//
this.ActionSelect.ForeColor = System.Drawing.SystemColors.WindowFrame;
this.ActionSelect.FormattingEnabled = true;
this.ActionSelect.Items.AddRange(new object[] {
"Events",
"Headline News",
"Images For Slideshow",
"Agendas",
"Job Opportunities",
"Schedule Of Meetings",
"Legal Notices",
"Main Street (Main Link)",
"Tourism (Main Link)",
"Rental Properties",
"Concert In The Park",
"Main Street News Letters"});
this.ActionSelect.Location = new System.Drawing.Point(126, 116);
this.ActionSelect.Name = "ActionSelect";
this.ActionSelect.Size = new System.Drawing.Size(283, 28);
this.ActionSelect.TabIndex = 1;
this.ActionSelect.Text = "Please Select";
//
// ProceedBtn
//
this.ProceedBtn.BackColor = System.Drawing.SystemColors.ButtonFace;
this.ProceedBtn.Cursor = System.Windows.Forms.Cursors.Hand;
this.ProceedBtn.ForeColor = System.Drawing.Color.DimGray;
this.ProceedBtn.Location = new System.Drawing.Point(221, 192);
this.ProceedBtn.Name = "ProceedBtn";
this.ProceedBtn.Size = new System.Drawing.Size(93, 34);
this.ProceedBtn.TabIndex = 2;
this.ProceedBtn.Text = "Proceed";
this.ProceedBtn.UseVisualStyleBackColor = false;
this.ProceedBtn.Click += new System.EventHandler(this.ProceedBtn_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.Location = new System.Drawing.Point(142, 55);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(251, 25);
this.label1.TabIndex = 3;
this.label1.Text = "Would Like To Change";
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(147, 268);
this.richTextBox1.Margin = new System.Windows.Forms.Padding(3, 3, 3, 30);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(246, 269);
this.richTextBox1.TabIndex = 4;
this.richTextBox1.Text = "";
//
// IntroForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoScroll = true;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(102)))), ((int)(((byte)(0)))));
this.ClientSize = new System.Drawing.Size(535, 306);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.ProceedBtn);
this.Controls.Add(this.ActionSelect);
this.Controls.Add(this.WelcomeHeader);
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(204)))), ((int)(((byte)(153)))), ((int)(((byte)(0)))));
this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.Name = "IntroForm";
this.Text = "Okmulgee Online Web File Generator";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label WelcomeHeader;
private System.Windows.Forms.ComboBox ActionSelect;
private System.Windows.Forms.Button ProceedBtn;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.RichTextBox richTextBox1;
}
}
------------------------------------------UPDATE-------------------------------------------
The element I have set the bottom margin property to within the code above is simply, richTextBox1.
Also, I did find a Padding element to the main form element, but sadly, this doesn't push other elements away from its edges either :(
What do these properties do (margin, padding)?
The Margin property is used by the automatic layout feature built into Winforms. But it does require that you allow the container to grow so it can provide the requested margin. So you must set the form's AutoSize property to True.
Combining AutoSize and AutoScroll is possible, you can set the MaximumSize property to prevent it from growing too much. The scrollbar automatically appears when the layout calculation produces a layout that exceeds the MaximumSize. The default maximum size is the Screen.WorkingArea on which the form is displayed, usually good enough.
I'm not 100% sure how I should word this question but I'll try my best.
I have a PointCtrlForm that has a DataGridView inside a TableLayoutPanel. The DataGridView is docked to the table as Fill. PointCtrlForm is docked to another window set as MDIParent with the dockstyle property set as Fill.
Resizing the main window properly resizes the PointCtrlForm, which then is supposed to resize the DataGridView as well. Well, at least "half" of the resizing works properly. Enlarging the main window also enlarges the datagridview, which is what I expected but if I shrink the main window to a certain point, the DataGridView stops shrinking and hides the columns without showing a scrollbar.
I've checked that all columns do not have Frozen property enabled, checked that both the datagridview and the child window is properly docked, and checked the scrollbars property is set to both.
Edit: AutoSizeColumnsMode is also fill.
I'll post the content of the Designer.cs here. I'd appreciate any guidance.
namespace DDCUI
{
partial class PointCtrlForm
{
/// <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.CmbSubDevice = new System.Windows.Forms.ComboBox();
this.BtnBack = new System.Windows.Forms.Button();
this.CmbMainDevice = new System.Windows.Forms.ComboBox();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.BtnRefresh = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.PointName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Value = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Description = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.DefaultValue = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ActiveString = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.InactiveString = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.AlarmCondition = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.tableLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 6;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 151F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 88F));
this.tableLayoutPanel1.Controls.Add(this.CmbSubDevice, 0, 1);
this.tableLayoutPanel1.Controls.Add(this.BtnBack, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.CmbMainDevice, 0, 1);
this.tableLayoutPanel1.Controls.Add(this.dataGridView1, 0, 2);
this.tableLayoutPanel1.Controls.Add(this.BtnRefresh, 4, 1);
this.tableLayoutPanel1.Controls.Add(this.label1, 5, 1);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 3;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 67.02128F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 32.97872F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 368F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(639, 467);
this.tableLayoutPanel1.TabIndex = 0;
//
// CmbSubDevice
//
this.tableLayoutPanel1.SetColumnSpan(this.CmbSubDevice, 2);
this.CmbSubDevice.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CmbSubDevice.Font = new System.Drawing.Font("굴림", 12F);
this.CmbSubDevice.FormattingEnabled = true;
this.CmbSubDevice.Location = new System.Drawing.Point(203, 69);
this.CmbSubDevice.Name = "CmbSubDevice";
this.CmbSubDevice.Size = new System.Drawing.Size(194, 24);
this.CmbSubDevice.TabIndex = 3;
//
// BtnBack
//
this.BtnBack.Location = new System.Drawing.Point(3, 3);
this.BtnBack.Name = "BtnBack";
this.BtnBack.Size = new System.Drawing.Size(94, 54);
this.BtnBack.TabIndex = 0;
this.BtnBack.Text = "Back";
this.BtnBack.UseVisualStyleBackColor = true;
this.BtnBack.Click += new System.EventHandler(this.BtnBack_Click);
//
// CmbMainDevice
//
this.tableLayoutPanel1.SetColumnSpan(this.CmbMainDevice, 2);
this.CmbMainDevice.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CmbMainDevice.Font = new System.Drawing.Font("굴림", 12F);
this.CmbMainDevice.FormattingEnabled = true;
this.CmbMainDevice.Items.AddRange(new object[] {
"I/O",
"VIRTUAL",
"SAC",
"MODBUS",
"NATIONAL",
"TOSHIBA",
"SCHEDULE",
"SYSTEM ALARM",
"LOGIC",
"GROUP"});
this.CmbMainDevice.Location = new System.Drawing.Point(3, 69);
this.CmbMainDevice.Name = "CmbMainDevice";
this.CmbMainDevice.Size = new System.Drawing.Size(194, 24);
this.CmbMainDevice.TabIndex = 2;
this.CmbMainDevice.SelectedIndexChanged += new System.EventHandler(this.CmbMainDevice_SelectedIndexChanged);
//
// dataGridView1
//
this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ID,
this.PointName,
this.Value,
this.Description,
this.DefaultValue,
this.ActiveString,
this.InactiveString,
this.AlarmCondition});
this.tableLayoutPanel1.SetColumnSpan(this.dataGridView1, 6);
this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGridView1.Location = new System.Drawing.Point(3, 101);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.RowTemplate.Height = 23;
this.dataGridView1.Size = new System.Drawing.Size(633, 363);
this.dataGridView1.TabIndex = 5;
//
// BtnRefresh
//
this.BtnRefresh.Location = new System.Drawing.Point(403, 69);
this.BtnRefresh.Name = "BtnRefresh";
this.BtnRefresh.Size = new System.Drawing.Size(94, 26);
this.BtnRefresh.TabIndex = 6;
this.BtnRefresh.Text = "Refresh";
this.BtnRefresh.UseVisualStyleBackColor = true;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
this.label1.Font = new System.Drawing.Font("굴림", 12F);
this.label1.Location = new System.Drawing.Point(554, 66);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(82, 32);
this.label1.TabIndex = 7;
this.label1.Text = "XXX 개";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// ID
//
this.ID.FillWeight = 70F;
this.ID.HeaderText = "ID";
this.ID.Name = "ID";
//
// PointName
//
this.PointName.FillWeight = 70F;
this.PointName.HeaderText = "이름";
this.PointName.Name = "PointName";
//
// Value
//
this.Value.FillWeight = 70F;
this.Value.HeaderText = "값";
this.Value.Name = "Value";
//
// Description
//
this.Description.FillWeight = 70F;
this.Description.HeaderText = "설명";
this.Description.Name = "Description";
//
// DefaultValue
//
this.DefaultValue.FillWeight = 70F;
this.DefaultValue.HeaderText = "초기값";
this.DefaultValue.Name = "DefaultValue";
//
// ActiveString
//
this.ActiveString.HeaderText = "Active문자열";
this.ActiveString.Name = "ActiveString";
//
// InactiveString
//
this.InactiveString.HeaderText = "InActive문자열";
this.InactiveString.Name = "InactiveString";
//
// AlarmCondition
//
this.AlarmCondition.HeaderText = "알람조건";
this.AlarmCondition.Name = "AlarmCondition";
//
// PointCtrlForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(639, 467);
this.Controls.Add(this.tableLayoutPanel1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "PointCtrlForm";
this.Text = "LG-DDC";
this.tableLayoutPanel1.ResumeLayout(false);
this.tableLayoutPanel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.Button BtnBack;
private System.Windows.Forms.ComboBox CmbMainDevice;
private System.Windows.Forms.ComboBox CmbSubDevice;
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.Button BtnRefresh;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.DataGridViewTextBoxColumn ID;
private System.Windows.Forms.DataGridViewTextBoxColumn PointName;
private System.Windows.Forms.DataGridViewTextBoxColumn Value;
private System.Windows.Forms.DataGridViewTextBoxColumn Description;
private System.Windows.Forms.DataGridViewTextBoxColumn DefaultValue;
private System.Windows.Forms.DataGridViewTextBoxColumn ActiveString;
private System.Windows.Forms.DataGridViewTextBoxColumn InactiveString;
private System.Windows.Forms.DataGridViewTextBoxColumn AlarmCondition;
}
}
I've found the solution and it's rather simple.
The row and column sizes for the DGV has to be set "percentage (relative)" not "absolute" in order for the docking to work properly.
You can edit the sizes by right clicking on one of the cells of the DGV and clicking on Edit Row/Column Properties.