When PictureBox have parent ListView and ListView RightToLeft set to true/yes I received some artifacts on drawing.
Why this happens and how remove this artifacts?
Images
http://i.stack.imgur.com/kx0zQ.png
http://i.stack.imgur.com/E5il3.png
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
void DrawOnPictureBox(PictureBox pc)
{
int delta;
int.TryParse((string)comboBox1.SelectedItem, out delta);
pc.Width = 100;
pc.Height = 40;
if (pc.Image == null)
pc.Image = new Bitmap(pc.Width, pc.Height);
else
if (pc.Image.Width != pc.Width || pc.Image.Height != pc.Height)
pc.Image = new Bitmap(pc.Width, pc.Height);
Graphics gr = Graphics.FromImage(pc.Image);
gr.Clear(Color.White);
int paintWidth = pc.Width - 1;
int paintHeight = pc.Height - 1;
PointF[] points = new PointF[4];
points[0] = new PointF(delta, paintHeight - 1);
points[1] = new PointF(paintWidth - delta, paintHeight - 1);
points[2] = new PointF(paintWidth - delta, 0);
points[3] = new PointF(delta, 0);
//gr.DrawPolygon(new Pen(Color.Black), points);
/**/
gr.DrawLine(new Pen(Color.Black), points[0], points[1]);
gr.DrawLine(new Pen(Color.Black), points[1], points[2]);
gr.DrawLine(new Pen(Color.Black), points[2], points[3]);
gr.DrawLine(new Pen(Color.Black), points[3], points[0]);
/**/
gr.DrawString("1", this.Font, new SolidBrush(Color.Black), 10, 10);
}
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Parent = listView1;
DrawOnPictureBox(pictureBox1);
pictureBox2.Parent = listView2;
DrawOnPictureBox(pictureBox2);
pictureBox3.Parent = listView3;
DrawOnPictureBox(pictureBox3);
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
listView1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
listView1.RightToLeftLayout = true;
listView2.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
listView2.RightToLeftLayout = true;
listView3.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
listView3.RightToLeftLayout = true;
}
else
{
listView1.RightToLeft = System.Windows.Forms.RightToLeft.No;
listView1.RightToLeftLayout = false;
listView2.RightToLeft = System.Windows.Forms.RightToLeft.No;
listView2.RightToLeftLayout = false;
listView3.RightToLeft = System.Windows.Forms.RightToLeft.No;
listView3.RightToLeftLayout = false;
}
}
}
namespace WindowsFormsApplication2
{
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.button1 = new System.Windows.Forms.Button();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.listView1 = new System.Windows.Forms.ListView();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.listView2 = new System.Windows.Forms.ListView();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.listView3 = new System.Windows.Forms.ListView();
this.pictureBox3 = new System.Windows.Forms.PictureBox();
this.comboBox1 = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(357, 23);
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);
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(481, 35);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(80, 17);
this.checkBox1.TabIndex = 2;
this.checkBox1.Text = "checkBox1";
this.checkBox1.UseVisualStyleBackColor = true;
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
//
// listView1
//
this.listView1.Location = new System.Drawing.Point(2, 263);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(317, 364);
this.listView1.TabIndex = 3;
this.listView1.UseCompatibleStateImageBehavior = false;
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(24, 280);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(130, 99);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// listView2
//
this.listView2.Location = new System.Drawing.Point(394, 55);
this.listView2.Name = "listView2";
this.listView2.Size = new System.Drawing.Size(538, 426);
this.listView2.TabIndex = 4;
this.listView2.UseCompatibleStateImageBehavior = false;
//
// pictureBox2
//
this.pictureBox2.Location = new System.Drawing.Point(407, 69);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(130, 397);
this.pictureBox2.TabIndex = 5;
this.pictureBox2.TabStop = false;
//
// listView3
//
this.listView3.Location = new System.Drawing.Point(2, 3);
this.listView3.Name = "listView3";
this.listView3.Size = new System.Drawing.Size(183, 155);
this.listView3.TabIndex = 6;
this.listView3.UseCompatibleStateImageBehavior = false;
//
// pictureBox3
//
this.pictureBox3.Location = new System.Drawing.Point(2, 3);
this.pictureBox3.Name = "pictureBox3";
this.pictureBox3.Size = new System.Drawing.Size(183, 155);
this.pictureBox3.TabIndex = 7;
this.pictureBox3.TabStop = false;
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Items.AddRange(new object[] {
"0",
"1",
"5",
"10"});
this.comboBox1.Location = new System.Drawing.Point(216, 55);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(120, 21);
this.comboBox1.TabIndex = 8;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(951, 627);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.pictureBox3);
this.Controls.Add(this.listView2);
this.Controls.Add(this.listView1);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.listView3);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.ListView listView2;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.ListView listView3;
private System.Windows.Forms.PictureBox pictureBox3;
private System.Windows.Forms.ComboBox comboBox1;
}
}
I noticed that artefacts appeared only when draw near the borders of picturebox.
I don't agree that is border-artefacts.
Temporary (approximately for 100 years :) solved with this hack
pictureBox.Location = new Point(-1, -1);
int delta = 2;
int paintWidth = pictureBox.Width - delta;
int paintHeight = pictureBox.Height - delta;
...
points[0] = new PointF(hLenL + delta, paintHeight);
points[1] = new PointF(paintWidth - hLenR, paintHeight);
points[2] = new PointF(paintWidth, delta);
points[3] = new PointF(delta, delta);
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
How would I input a trackbar.Value into a value for a Pen? I am trying to take the value of trackBarSize and put in for an integer value, is this possible?
On line
Pen myPen = new Pen(Color.Black, trackBarSize.Value);
I got this error:
CS0236 C# A field initializer cannot reference the non-static field, method, or property 'WhiteBoard.trackBarSize'
What would i have to do in order to get the value of the trackbar to be the value of the brush size?
If you want all of the values for each object, I can provide it.
namespace WhiteBoard
{
public partial class WhiteBoard : Form
{
public WhiteBoard()
{
InitializeComponent();
}
Graphics myGraphics;
bool mousePress;
int xLast;
int yLast;
// Pens
Pen BlaP = new Pen(Color.Black, 2);
Pen ReP = new Pen(Color.Red, 2);
Pen GreP = new Pen(Color.Green, 2);
Pen BluP = new Pen(Color.Blue, 2);
Pen myPen = new Pen(Color.Black, trackBarSize.Value);
private void WhiteBoard_Load(object sender, EventArgs e)
{
myGraphics = pnlBoard.CreateGraphics();
}
private void pnlBoard_Paint(object sender, PaintEventArgs e)
{
}
private void pnlBoard_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mousePress = true;
xLast = e.X;
yLast = e.Y;
}
}
private void pnlBoard_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
myGraphics.DrawLine(myPen, xLast, yLast, e.X, e.Y);
mousePress = false;
}
}
private void pnlBoard_MouseMove(object sender, MouseEventArgs e)
{
if (mousePress)
{
myGraphics.DrawLine(myPen, xLast, yLast, e.X, e.Y);
xLast = e.X;
yLast = e.Y;
}
}
// Lines
private void btnLine1_Click(object sender, EventArgs e)
{
myGraphics.DrawLine(BlaP, 10, 10, 590, 10);
myGraphics.DrawLine(BlaP, 10, 10, 10, 590);
myGraphics.DrawLine(BlaP, 10, 590, 590, 590);
myGraphics.DrawLine(BlaP, 590, 10, 590, 590);
}
private void btnLine2_Click(object sender, EventArgs e)
{
myGraphics.DrawLine(ReP, 10, 10, 590, 10);
myGraphics.DrawLine(ReP, 10, 10, 10, 590);
myGraphics.DrawLine(ReP, 10, 590, 590, 590);
myGraphics.DrawLine(ReP, 590, 10, 590, 590);
}
private void btnLine3_Click(object sender, EventArgs e)
{
myGraphics.DrawLine(GreP, 10, 10, 590, 10);
myGraphics.DrawLine(GreP, 10, 10, 10, 590);
myGraphics.DrawLine(GreP, 10, 590, 590, 590);
myGraphics.DrawLine(GreP, 590, 10, 590, 590);
}
private void btnLine4_Click(object sender, EventArgs e)
{
myGraphics.DrawLine(BluP, 10, 10, 590, 10);
myGraphics.DrawLine(BluP, 10, 10, 10, 590);
myGraphics.DrawLine(BluP, 10, 590, 590, 590);
myGraphics.DrawLine(BluP, 590, 10, 590, 590);
}
private void WhiteBoard_FormClosing(object sender, FormClosingEventArgs e)
{
myGraphics.Dispose();
BlaP.Dispose();
ReP.Dispose();
GreP.Dispose();
BluP.Dispose();
}
// Brushes
private void rdoBlack_CheckedChanged(object sender, EventArgs e)
{
myPen.Color = Color.Black;
}
private void rdoRed_CheckedChanged(object sender, EventArgs e)
{
myPen.Color = Color.Red;
}
private void rdoGreen_CheckedChanged(object sender, EventArgs e)
{
myPen.Color = Color.Green;
}
private void rdoBlue_CheckedChanged(object sender, EventArgs e)
{
myPen.Color = Color.Blue;
}
private void rdoPurple_CheckedChanged(object sender, EventArgs e)
{
myPen.Color = Color.Purple;
}
private void rdoYellow_CheckedChanged(object sender, EventArgs e)
{
myPen.Color = Color.Yellow;
}
private void rdoOrange_CheckedChanged(object sender, EventArgs e)
{
myPen.Color = Color.Orange;
}
private void rdoPink_CheckedChanged(object sender, EventArgs e)
{
myPen.Color = Color.Pink;
}
private void trackBarSize_ValueChanged(object sender, EventArgs e)
{
txtBrushSize.Text = trackBarSize.Value + "";
}
private void btnClear_Click(object sender, EventArgs e)
{
myGraphics.Clear(pnlBoard.BackColor);
}
private void trackBarSize_Scroll(object sender, EventArgs e)
{
}
}
}
Here are the values for all of the objects:
namespace WhiteBoard
{
partial class WhiteBoard
{
/// <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.pnlBoard = new System.Windows.Forms.Panel();
this.txtBrushSize = new System.Windows.Forms.TextBox();
this.btnLine1 = new System.Windows.Forms.Button();
this.btnLine2 = new System.Windows.Forms.Button();
this.btnLine4 = new System.Windows.Forms.Button();
this.btnLine3 = new System.Windows.Forms.Button();
this.btnClear = new System.Windows.Forms.Button();
this.pnlLines = new System.Windows.Forms.Panel();
this.label1 = new System.Windows.Forms.Label();
this.trackBarSize = new System.Windows.Forms.TrackBar();
this.lblBrushSize = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
this.rdoPink = new System.Windows.Forms.RadioButton();
this.rdoOrange = new System.Windows.Forms.RadioButton();
this.rdoYellow = new System.Windows.Forms.RadioButton();
this.rdoPurple = new System.Windows.Forms.RadioButton();
this.rdoBlue = new System.Windows.Forms.RadioButton();
this.rdoGreen = new System.Windows.Forms.RadioButton();
this.rdoRed = new System.Windows.Forms.RadioButton();
this.rdoBlack = new System.Windows.Forms.RadioButton();
this.trackBarColor = new System.Windows.Forms.TrackBar();
this.label2 = new System.Windows.Forms.Label();
this.pnlLines.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBarSize)).BeginInit();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBarColor)).BeginInit();
this.SuspendLayout();
//
// pnlBoard
//
this.pnlBoard.BackColor = System.Drawing.Color.White;
this.pnlBoard.Location = new System.Drawing.Point(12, 12);
this.pnlBoard.Name = "pnlBoard";
this.pnlBoard.Size = new System.Drawing.Size(600, 600);
this.pnlBoard.TabIndex = 0;
this.pnlBoard.Paint += new System.Windows.Forms.PaintEventHandler(this.pnlBoard_Paint);
this.pnlBoard.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pnlBoard_MouseDown);
this.pnlBoard.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pnlBoard_MouseMove);
this.pnlBoard.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pnlBoard_MouseUp);
//
// txtBrushSize
//
this.txtBrushSize.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.txtBrushSize.Location = new System.Drawing.Point(686, 184);
this.txtBrushSize.Name = "txtBrushSize";
this.txtBrushSize.Size = new System.Drawing.Size(25, 22);
this.txtBrushSize.TabIndex = 11;
this.txtBrushSize.Text = "5";
//
// btnLine1
//
this.btnLine1.BackColor = System.Drawing.Color.Transparent;
this.btnLine1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnLine1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnLine1.Location = new System.Drawing.Point(4, 19);
this.btnLine1.Name = "btnLine1";
this.btnLine1.Size = new System.Drawing.Size(75, 23);
this.btnLine1.TabIndex = 1;
this.btnLine1.Text = "Black Lines";
this.btnLine1.UseVisualStyleBackColor = false;
this.btnLine1.Click += new System.EventHandler(this.btnLine1_Click);
//
// btnLine2
//
this.btnLine2.BackColor = System.Drawing.Color.Transparent;
this.btnLine2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnLine2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnLine2.Location = new System.Drawing.Point(82, 19);
this.btnLine2.Name = "btnLine2";
this.btnLine2.Size = new System.Drawing.Size(75, 23);
this.btnLine2.TabIndex = 2;
this.btnLine2.Text = "Red Lines";
this.btnLine2.UseVisualStyleBackColor = false;
this.btnLine2.Click += new System.EventHandler(this.btnLine2_Click);
//
// btnLine4
//
this.btnLine4.BackColor = System.Drawing.Color.Transparent;
this.btnLine4.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnLine4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnLine4.Location = new System.Drawing.Point(82, 48);
this.btnLine4.Name = "btnLine4";
this.btnLine4.Size = new System.Drawing.Size(75, 23);
this.btnLine4.TabIndex = 4;
this.btnLine4.Text = "Blue Lines";
this.btnLine4.UseVisualStyleBackColor = false;
this.btnLine4.Click += new System.EventHandler(this.btnLine4_Click);
//
// btnLine3
//
this.btnLine3.BackColor = System.Drawing.Color.Transparent;
this.btnLine3.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnLine3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnLine3.Location = new System.Drawing.Point(4, 48);
this.btnLine3.Name = "btnLine3";
this.btnLine3.Size = new System.Drawing.Size(75, 23);
this.btnLine3.TabIndex = 3;
this.btnLine3.Text = "Green Lines";
this.btnLine3.UseVisualStyleBackColor = false;
this.btnLine3.Click += new System.EventHandler(this.btnLine3_Click);
//
// btnClear
//
this.btnClear.BackColor = System.Drawing.Color.Tomato;
this.btnClear.FlatAppearance.BorderColor = System.Drawing.Color.Firebrick;
this.btnClear.FlatAppearance.BorderSize = 2;
this.btnClear.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnClear.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnClear.ForeColor = System.Drawing.Color.Black;
this.btnClear.Location = new System.Drawing.Point(618, 578);
this.btnClear.Name = "btnClear";
this.btnClear.Size = new System.Drawing.Size(156, 34);
this.btnClear.TabIndex = 5;
this.btnClear.Text = "Clear Board";
this.btnClear.UseMnemonic = false;
this.btnClear.UseVisualStyleBackColor = false;
this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
//
// pnlLines
//
this.pnlLines.BackColor = System.Drawing.SystemColors.ButtonShadow;
this.pnlLines.Controls.Add(this.btnLine3);
this.pnlLines.Controls.Add(this.btnLine1);
this.pnlLines.Controls.Add(this.btnLine4);
this.pnlLines.Controls.Add(this.label1);
this.pnlLines.Controls.Add(this.btnLine2);
this.pnlLines.Location = new System.Drawing.Point(618, 12);
this.pnlLines.Name = "pnlLines";
this.pnlLines.Size = new System.Drawing.Size(161, 75);
this.pnlLines.TabIndex = 8;
//
// label1
//
this.label1.AutoSize = true;
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.Location = new System.Drawing.Point(3, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(45, 16);
this.label1.TabIndex = 0;
this.label1.Text = "Lines";
//
// trackBarSize
//
this.trackBarSize.BackColor = System.Drawing.SystemColors.ButtonShadow;
this.trackBarSize.Cursor = System.Windows.Forms.Cursors.Default;
this.trackBarSize.Location = new System.Drawing.Point(618, 135);
this.trackBarSize.Name = "trackBarSize";
this.trackBarSize.Size = new System.Drawing.Size(161, 45);
this.trackBarSize.TabIndex = 9;
this.trackBarSize.TabStop = false;
this.trackBarSize.TickStyle = System.Windows.Forms.TickStyle.Both;
this.trackBarSize.Value = 5;
this.trackBarSize.ValueChanged += new System.EventHandler(this.trackBarSize_ValueChanged);
this.trackBarSize.MouseUp += new System.Windows.Forms.MouseEventHandler(this.trackBarSize_MouseUp);
//
// lblBrushSize
//
this.lblBrushSize.AutoSize = true;
this.lblBrushSize.BackColor = System.Drawing.Color.Transparent;
this.lblBrushSize.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblBrushSize.Location = new System.Drawing.Point(658, 120);
this.lblBrushSize.Name = "lblBrushSize";
this.lblBrushSize.Size = new System.Drawing.Size(81, 16);
this.lblBrushSize.TabIndex = 10;
this.lblBrushSize.Text = "Brush Size";
//
// label3
//
this.label3.AutoSize = true;
this.label3.BackColor = System.Drawing.Color.Transparent;
this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label3.Location = new System.Drawing.Point(3, 0);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(96, 16);
this.label3.TabIndex = 0;
this.label3.Text = "Brush Colors";
//
// panel1
//
this.panel1.BackColor = System.Drawing.SystemColors.ButtonShadow;
this.panel1.Controls.Add(this.rdoPink);
this.panel1.Controls.Add(this.rdoOrange);
this.panel1.Controls.Add(this.rdoYellow);
this.panel1.Controls.Add(this.rdoPurple);
this.panel1.Controls.Add(this.rdoBlue);
this.panel1.Controls.Add(this.rdoGreen);
this.panel1.Controls.Add(this.rdoRed);
this.panel1.Controls.Add(this.rdoBlack);
this.panel1.Controls.Add(this.label3);
this.panel1.Location = new System.Drawing.Point(618, 212);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(161, 116);
this.panel1.TabIndex = 10;
//
// rdoPink
//
this.rdoPink.AutoSize = true;
this.rdoPink.BackColor = System.Drawing.Color.Transparent;
this.rdoPink.Location = new System.Drawing.Point(91, 90);
this.rdoPink.Name = "rdoPink";
this.rdoPink.Size = new System.Drawing.Size(46, 17);
this.rdoPink.TabIndex = 8;
this.rdoPink.Text = "Pink";
this.rdoPink.UseVisualStyleBackColor = false;
this.rdoPink.CheckedChanged += new System.EventHandler(this.rdoPink_CheckedChanged);
//
// rdoOrange
//
this.rdoOrange.AutoSize = true;
this.rdoOrange.BackColor = System.Drawing.Color.Transparent;
this.rdoOrange.Location = new System.Drawing.Point(6, 90);
this.rdoOrange.Name = "rdoOrange";
this.rdoOrange.Size = new System.Drawing.Size(60, 17);
this.rdoOrange.TabIndex = 7;
this.rdoOrange.Text = "Orange";
this.rdoOrange.UseVisualStyleBackColor = false;
this.rdoOrange.CheckedChanged += new System.EventHandler(this.rdoOrange_CheckedChanged);
//
// rdoYellow
//
this.rdoYellow.AutoSize = true;
this.rdoYellow.BackColor = System.Drawing.Color.Transparent;
this.rdoYellow.Location = new System.Drawing.Point(91, 66);
this.rdoYellow.Name = "rdoYellow";
this.rdoYellow.Size = new System.Drawing.Size(56, 17);
this.rdoYellow.TabIndex = 6;
this.rdoYellow.Text = "Yellow";
this.rdoYellow.UseVisualStyleBackColor = false;
this.rdoYellow.CheckedChanged += new System.EventHandler(this.rdoYellow_CheckedChanged);
//
// rdoPurple
//
this.rdoPurple.AutoSize = true;
this.rdoPurple.BackColor = System.Drawing.Color.Transparent;
this.rdoPurple.Location = new System.Drawing.Point(6, 66);
this.rdoPurple.Name = "rdoPurple";
this.rdoPurple.Size = new System.Drawing.Size(55, 17);
this.rdoPurple.TabIndex = 5;
this.rdoPurple.Text = "Purple";
this.rdoPurple.UseVisualStyleBackColor = false;
this.rdoPurple.CheckedChanged += new System.EventHandler(this.rdoPurple_CheckedChanged);
//
// rdoBlue
//
this.rdoBlue.AutoSize = true;
this.rdoBlue.BackColor = System.Drawing.Color.Transparent;
this.rdoBlue.Location = new System.Drawing.Point(91, 43);
this.rdoBlue.Name = "rdoBlue";
this.rdoBlue.Size = new System.Drawing.Size(46, 17);
this.rdoBlue.TabIndex = 4;
this.rdoBlue.Text = "Blue";
this.rdoBlue.UseVisualStyleBackColor = false;
this.rdoBlue.CheckedChanged += new System.EventHandler(this.rdoBlue_CheckedChanged);
//
// rdoGreen
//
this.rdoGreen.AutoSize = true;
this.rdoGreen.BackColor = System.Drawing.Color.Transparent;
this.rdoGreen.Location = new System.Drawing.Point(6, 42);
this.rdoGreen.Name = "rdoGreen";
this.rdoGreen.Size = new System.Drawing.Size(54, 17);
this.rdoGreen.TabIndex = 3;
this.rdoGreen.Text = "Green";
this.rdoGreen.UseVisualStyleBackColor = false;
this.rdoGreen.CheckedChanged += new System.EventHandler(this.rdoGreen_CheckedChanged);
//
// rdoRed
//
this.rdoRed.AutoSize = true;
this.rdoRed.BackColor = System.Drawing.Color.Transparent;
this.rdoRed.Location = new System.Drawing.Point(91, 19);
this.rdoRed.Name = "rdoRed";
this.rdoRed.Size = new System.Drawing.Size(45, 17);
this.rdoRed.TabIndex = 2;
this.rdoRed.Text = "Red";
this.rdoRed.UseVisualStyleBackColor = false;
this.rdoRed.CheckedChanged += new System.EventHandler(this.rdoRed_CheckedChanged);
//
// rdoBlack
//
this.rdoBlack.AutoSize = true;
this.rdoBlack.BackColor = System.Drawing.Color.Transparent;
this.rdoBlack.Checked = true;
this.rdoBlack.Location = new System.Drawing.Point(6, 19);
this.rdoBlack.Name = "rdoBlack";
this.rdoBlack.Size = new System.Drawing.Size(52, 17);
this.rdoBlack.TabIndex = 1;
this.rdoBlack.TabStop = true;
this.rdoBlack.Text = "Black";
this.rdoBlack.UseVisualStyleBackColor = false;
this.rdoBlack.CheckedChanged += new System.EventHandler(this.rdoBlack_CheckedChanged);
//
// trackBarColor
//
this.trackBarColor.BackColor = System.Drawing.SystemColors.ButtonShadow;
this.trackBarColor.Cursor = System.Windows.Forms.Cursors.Default;
this.trackBarColor.Location = new System.Drawing.Point(618, 527);
this.trackBarColor.Maximum = 255;
this.trackBarColor.Name = "trackBarColor";
this.trackBarColor.Size = new System.Drawing.Size(161, 45);
this.trackBarColor.TabIndex = 12;
this.trackBarColor.TabStop = false;
this.trackBarColor.TickStyle = System.Windows.Forms.TickStyle.Both;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label2.Location = new System.Drawing.Point(658, 508);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(91, 16);
this.label2.TabIndex = 13;
this.label2.Text = "Board Color";
//
// WhiteBoard
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ActiveBorder;
this.ClientSize = new System.Drawing.Size(787, 624);
this.Controls.Add(this.label2);
this.Controls.Add(this.trackBarColor);
this.Controls.Add(this.panel1);
this.Controls.Add(this.txtBrushSize);
this.Controls.Add(this.lblBrushSize);
this.Controls.Add(this.trackBarSize);
this.Controls.Add(this.pnlLines);
this.Controls.Add(this.btnClear);
this.Controls.Add(this.pnlBoard);
this.Name = "WhiteBoard";
this.Text = "White Board";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.WhiteBoard_FormClosing);
this.Load += new System.EventHandler(this.WhiteBoard_Load);
this.pnlLines.ResumeLayout(false);
this.pnlLines.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBarSize)).EndInit();
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBarColor)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Panel pnlBoard;
private System.Windows.Forms.Button btnLine1;
private System.Windows.Forms.Button btnLine2;
private System.Windows.Forms.Button btnLine4;
private System.Windows.Forms.Button btnLine3;
private System.Windows.Forms.Button btnClear;
private System.Windows.Forms.Panel pnlLines;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TrackBar trackBarSize;
private System.Windows.Forms.Label lblBrushSize;
private System.Windows.Forms.TextBox txtBrushSize;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.RadioButton rdoPink;
private System.Windows.Forms.RadioButton rdoOrange;
private System.Windows.Forms.RadioButton rdoYellow;
private System.Windows.Forms.RadioButton rdoPurple;
private System.Windows.Forms.RadioButton rdoBlue;
private System.Windows.Forms.RadioButton rdoGreen;
private System.Windows.Forms.RadioButton rdoRed;
private System.Windows.Forms.RadioButton rdoBlack;
private System.Windows.Forms.TrackBar trackBarColor;
private System.Windows.Forms.Label label2;
}
}
In this declaration line:
Pen myPen = new Pen(Color.Black, trackBarSize.Value);
You can't use trackBarSize.Value because the control hasn't even been created and initialized yet.
So simply pick a default size and use that:
Pen myPen = new Pen(Color.Black, 1);
Then, in the ValueChanged() event of your TrackBar, you'd update the Width property of your Pen:
private void trackBarSize_ValueChanged(object sender, System.EventArgs e)
{
myPen.Width = (Single)trackBarSize.Value;
}
I'm having some serious issues when attempting to add an existing form from one Project to another. I have done a bit of research regarding how to add existing forms correctly to a project and I have located the file through Add Existing. I have also rebuilt the original project to the correct .Net framework (as it was using 4.00 and my current project is using 4.5.2) the issue i am having is when trying to initiate the new form in a button click in my main menu form it does not show up for instance when attempting to reference the form (new Project.Test.Test) it does not recognise the form as part of the project.
All other solutions i have found don't seem to work for me.
edit : This is the code from from test.cs
using System;
using System.Windows.Forms;
namespace StackedHeader
{
public partial class Test : Form
{
public Test()
{
InitializeComponent();
StackedHeaderDecorator objREnderer = new StackedHeaderDecorator(dataGridView1);
//dataGridView1.Columns[0].Visible = false;
//dataGridView1.Columns[2].Visible = false;
}
private void btnAdd_Click(object sender, EventArgs e)
{
for (int i = 0; i < 3; ++i)
{
int columnCount = dataGridView1.Columns.Count;
dataGridView1.Columns.Add("Column" + dataGridView1.Columns.Count,
"Parent[" + columnCount + "].Child 1.Child 2.Input Name");
dataGridView1.Columns.Add("Column" + dataGridView1.Columns.Count ,
"Parent[" + columnCount + "].Child 1.Child 2.Input Name 2");
dataGridView1.Columns.Add("Column" + dataGridView1.Columns.Count,
"Parent[" + columnCount + "].Child 1.Child 3.Input Name 3");
dataGridView1.Columns.Add("Column" + dataGridView1.Columns.Count ,
"Parent[" + columnCount + "].Child 1.Input Name 4");
dataGridView1.Columns.Add("Column" + dataGridView1.Columns.Count ,
"Parent[" + columnCount + "].Input Name 5");
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}
and this is my form design code:
namespace StackedHeader
{
partial class Test
{
/// <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.dataGridView1 = new System.Windows.Forms.DataGridView();
this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.e = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column7 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column8 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column9 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column10 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column11 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column12 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column13 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column14 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column15 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column16 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column17 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column18 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column19 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column20 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column21 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column22 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column23 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column24 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column25 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column26 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column27 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column28 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.listBox1 = new System.Windows.Forms.ListBox();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// dataGridView1
//
this.dataGridView1.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.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Column1,
this.e,
this.Column3,
this.Column4,
this.Column5,
this.Column2,
this.Column6,
this.Column7,
this.Column8,
this.Column9,
this.Column10,
this.Column11,
this.Column12,
this.Column13,
this.Column14,
this.Column15,
this.Column16,
this.Column17,
this.Column18,
this.Column19,
this.Column20,
this.Column21,
this.Column22,
this.Column23,
this.Column24,
this.Column25,
this.Column26,
this.Column27,
this.Column28});
this.dataGridView1.Location = new System.Drawing.Point(12, 12);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(1492, 697);
this.dataGridView1.TabIndex = 0;
this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick);
//
// Column1
//
this.Column1.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
this.Column1.HeaderText = "MasterRoster.Monday.On";
this.Column1.Name = "Column1";
this.Column1.Width = 50;
//
// e
//
this.e.HeaderText = "MasterRoster.Monday.Off";
this.e.Name = "e";
this.e.Width = 50;
//
// Column3
//
this.Column3.HeaderText = "MasterRoster.Monday.Duty";
this.Column3.Name = "Column3";
this.Column3.Width = 50;
//
// Column4
//
this.Column4.HeaderText = "MasterRoster.Monday.Hours";
this.Column4.Name = "Column4";
this.Column4.Width = 50;
//
// Column5
//
this.Column5.HeaderText = "MasterRoster.Tuesday.On";
this.Column5.Name = "Column5";
this.Column5.Width = 50;
//
// Column2
//
this.Column2.HeaderText = "MasterRoster.Tuesday.Off";
this.Column2.Name = "Column2";
this.Column2.Width = 50;
//
// Column6
//
this.Column6.HeaderText = "MasterRoster.Tuesday.Duty";
this.Column6.Name = "Column6";
this.Column6.Width = 50;
//
// Column7
//
this.Column7.HeaderText = "MasterRoster.Tuesday.Hours";
this.Column7.Name = "Column7";
this.Column7.Width = 50;
//
// Column8
//
this.Column8.HeaderText = "MasterRoster.Wednesday.On";
this.Column8.Name = "Column8";
this.Column8.Width = 50;
//
// Column9
//
this.Column9.HeaderText = "MasterRoster.Wednesday.Off";
this.Column9.Name = "Column9";
this.Column9.Width = 50;
//
// Column10
//
this.Column10.HeaderText = "MasterRoster.Wednesday.Duty";
this.Column10.Name = "Column10";
this.Column10.Width = 50;
//
// Column11
//
this.Column11.HeaderText = "MasterRoster.Wednesday.Hours";
this.Column11.Name = "Column11";
this.Column11.Width = 50;
//
// Column12
//
this.Column12.HeaderText = "MasterRoster.Thursday.On";
this.Column12.Name = "Column12";
this.Column12.Width = 50;
//
// Column13
//
this.Column13.HeaderText = "MasterRoster.Thursday.Off";
this.Column13.Name = "Column13";
this.Column13.Width = 50;
//
// Column14
//
this.Column14.HeaderText = "MasterRoster.Thursday.Duty";
this.Column14.Name = "Column14";
this.Column14.Width = 50;
//
// Column15
//
this.Column15.HeaderText = "MasterRoster.Thursday.Hours";
this.Column15.Name = "Column15";
this.Column15.Width = 50;
//
// Column16
//
this.Column16.HeaderText = "MasterRoster.Friday.On";
this.Column16.Name = "Column16";
this.Column16.Width = 50;
//
// Column17
//
this.Column17.HeaderText = "MasterRoster.Friday.Off";
this.Column17.Name = "Column17";
this.Column17.Width = 50;
//
// Column18
//
this.Column18.HeaderText = "MasterRoster.Friday.Duty";
this.Column18.Name = "Column18";
this.Column18.Width = 50;
//
// Column19
//
this.Column19.HeaderText = "MasterRoster.Friday.Hours";
this.Column19.Name = "Column19";
this.Column19.Width = 50;
//
// Column20
//
this.Column20.HeaderText = "MasterRoster.Saturday.On";
this.Column20.Name = "Column20";
this.Column20.Width = 50;
//
// Column21
//
this.Column21.HeaderText = "MasterRoster.Saturday.Off";
this.Column21.Name = "Column21";
this.Column21.Width = 50;
//
// Column22
//
this.Column22.HeaderText = "MasterRoster.Saturday.Duty";
this.Column22.Name = "Column22";
this.Column22.Width = 50;
//
// Column23
//
this.Column23.HeaderText = "MasterRoster.Saturday.Hours";
this.Column23.Name = "Column23";
this.Column23.Width = 50;
//
// Column24
//
this.Column24.HeaderText = "MasterRoster.Sunday.On";
this.Column24.Name = "Column24";
this.Column24.Width = 50;
//
// Column25
//
this.Column25.HeaderText = "MasterRoster.Sunday.Off";
this.Column25.Name = "Column25";
this.Column25.Width = 50;
//
// Column26
//
this.Column26.HeaderText = "MasterRoster.Sunday.Duty";
this.Column26.Name = "Column26";
this.Column26.Width = 50;
//
// Column27
//
this.Column27.HeaderText = "MasterRoster.Sunday.Hours";
this.Column27.Name = "Column27";
this.Column27.Width = 50;
//
// Column28
//
this.Column28.HeaderText = "MasterRoster.Total Hours";
this.Column28.Name = "Column28";
this.Column28.Width = 50;
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
this.listBox1.Location = new System.Drawing.Point(1510, 46);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(158, 680);
this.listBox1.TabIndex = 1;
//
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Items.AddRange(new object[] {
"All",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"});
this.comboBox1.Location = new System.Drawing.Point(1510, 19);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(158, 21);
this.comboBox1.TabIndex = 2;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(1510, 3);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(84, 13);
this.label1.TabIndex = 3;
this.label1.Text = "Duty Day Picker";
//
// Test
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1670, 738);
this.Controls.Add(this.label1);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.dataGridView1);
this.Name = "Test";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.DataGridViewTextBoxColumn Column1;
private System.Windows.Forms.DataGridViewTextBoxColumn e;
private System.Windows.Forms.DataGridViewTextBoxColumn Column3;
private System.Windows.Forms.DataGridViewTextBoxColumn Column4;
private System.Windows.Forms.DataGridViewTextBoxColumn Column5;
private System.Windows.Forms.DataGridViewTextBoxColumn Column2;
private System.Windows.Forms.DataGridViewTextBoxColumn Column6;
private System.Windows.Forms.DataGridViewTextBoxColumn Column7;
private System.Windows.Forms.DataGridViewTextBoxColumn Column8;
private System.Windows.Forms.DataGridViewTextBoxColumn Column9;
private System.Windows.Forms.DataGridViewTextBoxColumn Column10;
private System.Windows.Forms.DataGridViewTextBoxColumn Column11;
private System.Windows.Forms.DataGridViewTextBoxColumn Column12;
private System.Windows.Forms.DataGridViewTextBoxColumn Column13;
private System.Windows.Forms.DataGridViewTextBoxColumn Column14;
private System.Windows.Forms.DataGridViewTextBoxColumn Column15;
private System.Windows.Forms.DataGridViewTextBoxColumn Column16;
private System.Windows.Forms.DataGridViewTextBoxColumn Column17;
private System.Windows.Forms.DataGridViewTextBoxColumn Column18;
private System.Windows.Forms.DataGridViewTextBoxColumn Column19;
private System.Windows.Forms.DataGridViewTextBoxColumn Column20;
private System.Windows.Forms.DataGridViewTextBoxColumn Column21;
private System.Windows.Forms.DataGridViewTextBoxColumn Column22;
private System.Windows.Forms.DataGridViewTextBoxColumn Column23;
private System.Windows.Forms.DataGridViewTextBoxColumn Column24;
private System.Windows.Forms.DataGridViewTextBoxColumn Column25;
private System.Windows.Forms.DataGridViewTextBoxColumn Column26;
private System.Windows.Forms.DataGridViewTextBoxColumn Column27;
private System.Windows.Forms.DataGridViewTextBoxColumn Column28;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label1;
}
}
I'm trying to implement a C# drag and drop row-reorder with a listbox. I've come across some snippets of code on the internet but none seem to be working with my needs.
I want you to show me an example code of how to move rows in ListBox.
Thanks!
The moving of rows is done in methods "listBox1_MouseUp and listBox1_MouseDown.
Use view code to change this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Calculator
{
public partial class ComponentMover : Form
{
private Control trackedControl;
private int gridWidth = 100, gridHeight = 20;
private int row;
public ComponentMover()
{
this.InitializeComponent();
this.InitializeDynamic();
}
void draggable_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (this.trackedControl == null)
this.trackedControl = (Control)sender;
}
void draggable_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (this.trackedControl != null)
{
int x = e.X + this.trackedControl.Location.X;
int y = e.Y + this.trackedControl.Location.Y;
Point moved = new Point(x - x % this.gridWidth, y - y % this.gridHeight);
Console.WriteLine(e.X + ", " + e.Y + ", " + ", " + moved.X + ", " + moved.Y);
if (moved != this.trackedControl.Location)
this.trackedControl.Location = moved;
}
}
void draggable_MouseUp(object sender, MouseEventArgs e)
{
this.trackedControl = null;
}
private void AddDragListeners(Control draggable)
{
draggable.MouseDown += new MouseEventHandler(draggable_MouseDown);
draggable.MouseMove += new MouseEventHandler(draggable_MouseMove);
draggable.MouseUp += new MouseEventHandler(draggable_MouseUp);
}
}
}
Designer code:
namespace Calculator
{
// Designer code.
partial class ComponentMover
{
/// <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);
}
private void InitializeDynamic()
{
this.AddDragListeners(button1);
this.AddDragListeners(button4);
this.AddDragListeners(domainUpDown1);
this.AddDragListeners(textBox1);
this.AddDragListeners(checkBox1);
this.AddDragListeners(radioButton1);
}
#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.button1 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.domainUpDown1 = new System.Windows.Forms.DomainUpDown();
this.textBox1 = new System.Windows.Forms.TextBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.listBox1 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(13, 13);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
//
// button4
//
this.button4.Location = new System.Drawing.Point(177, 43);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(75, 23);
this.button4.TabIndex = 3;
this.button4.Text = "button4";
this.button4.UseVisualStyleBackColor = true;
//
// domainUpDown1
//
this.domainUpDown1.Location = new System.Drawing.Point(95, 42);
this.domainUpDown1.Name = "domainUpDown1";
this.domainUpDown1.Size = new System.Drawing.Size(74, 20);
this.domainUpDown1.TabIndex = 4;
this.domainUpDown1.Text = "domainUpDown1";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(177, 72);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 5;
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(281, 13);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(80, 17);
this.checkBox1.TabIndex = 6;
this.checkBox1.Text = "checkBox1";
this.checkBox1.UseVisualStyleBackColor = true;
//
// radioButton1
//
this.radioButton1.AutoSize = true;
this.radioButton1.Location = new System.Drawing.Point(366, 42);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(85, 17);
this.radioButton1.TabIndex = 7;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "radioButton1";
this.radioButton1.UseVisualStyleBackColor = true;
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
this.listBox1.Items.AddRange(new object[] {
"word1",
"word2",
"word3"});
this.listBox1.Location = new System.Drawing.Point(13, 42);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(76, 82);
this.listBox1.TabIndex = 8;
this.listBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(listBox1_MouseDown);
this.listBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(listBox1_MouseUp);
//
// ComponentMover
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(485, 159);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.radioButton1);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.domainUpDown1);
this.Controls.Add(this.button4);
this.Controls.Add(this.button1);
this.Name = "ComponentMover";
this.Text = "ComponentMover";
this.ResumeLayout(false);
this.PerformLayout();
}
void listBox1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
System.Windows.Forms.ListBox list = (System.Windows.Forms.ListBox)sender;
int swap = list.SelectedIndex;
if(swap != this.row)
{
string temp = (string)list.Items[this.row];
list.Items[this.row] = list.Items[swap];
list.Items[swap] = temp;
}
}
void listBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.row = ((System.Windows.Forms.ListBox)sender).SelectedIndex;
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.DomainUpDown domainUpDown1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.ListBox listBox1;
}
}
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.