C# Listbox Drag and Drop Rows - c#

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;
}
}

Related

Custom groupbox control not painting correctly when added to tabpage

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

c# how does timeSpan work?

I have a timer, how starts, when the text in a label appears and stop when you click on a button. Now i want to stop the reaktiontime and save it in a list, which i want to sort, so i can give out the fastest and lowest reaktiontime in a label. but in my code every time it shows 00:00:00 in the messagebox :(
public partial class Form1 : Form
{
Random r = new Random();
Random Farbe = new Random();
bool Start_MouseClick;
IList<string> Reaktionszeitliste = new List<string>() {};
IList<Color> myColors = new[] { Color.Red, Color.Blue, Color.Green, Color.White, Color.Yellow };
string[] colors = { "Rot", "Blau", "Grün", "Gelb", "Weiß" };
int Timeleft = 5;
int summe = 0, z;
string Reaktionszeit;
int Zeit;
int Spielzuege = 0;
DateTime Time1;
DateTime Time2;
TimeSpan ts;
private void btnRot_Click(object sender, EventArgs e)
{
Spielzuege = Spielzuege + 1;
timMessung.Stop();
if (Start_MouseClick == true)
{
int summe = 0, z;
lblAnzeige.Text = " ";
while (summe <= 0)
{
z = r.Next(1, 6);
summe = summe + z;
}
lblAnzeige.Text += colors[summe - 1] + "\n";
Zeit = 0;
timMessung.Enabled = true;
if (ckbExtrem.Checked == false)
{
lblAnzeige.ForeColor = myColors[Farbe.Next(myColors.Count)];
}
else
{
lblAnzeige.ForeColor = Color.FromArgb(Farbe.Next(256), Farbe.Next(256), Farbe.Next(256));
}
if (Spielzuege == 15)
{
if (txbPlayer2.Text != "")
{
MessageBox.Show("Spieler 2: Machen Sie sich bereit!");
}
else
{
MessageBox.Show(Convert.ToString(ts));
}
}
}
}
private void txbStart_MouseClick(object sender, MouseEventArgs e)
{
if (txbPlayer1.Text == "" && txbPlayer2.Text == "")
{
MessageBox.Show("Bitte geben Sie Spielername(n) ein!");
}
else
{
timVerzögerung.Enabled = true;
panel1.Visible = false;
lblAnzeige.Text = " ";
txbStart.Visible = false;
textBox1.Visible = false;
Start_MouseClick = true;
while (summe <= 0)
{
z = r.Next(1, 6);
summe = summe + z;
}
}
}
private void timMessung_Tick(object sender, EventArgs e)
{
if (timMessung.Enabled == true)
{
Time1 = DateTime.Now;
}
else
{
Time2 = DateTime.Now;
ts = Time1 - Time2;
int differenceInMilli = ts.Milliseconds;
}
}
In a first run i tried to alter your code so that it should run. But i found so many (coding style) issues within there that i simply wrote a completely new example. It also has some minor issues (e.g. size of buttons; it is possible that a color button occurs twice). But it hopefully shows you how TimeSpan and all the other parts can work together.
The Form1.cs file:
public partial class Form1 : Form
{
private Random _Random;
private List<TimeSpan> _ReactionTimes;
private Stopwatch _Stopwatch;
public Form1()
{
InitializeComponent();
_Stopwatch = new Stopwatch();
_Random = new Random(42);
_ReactionTimes = new List<TimeSpan>();
}
private Button CreateButton(Color color)
{
var button = new Button();
button.Click += OnColorButtonClick;
button.BackColor = color;
button.Text = color.Name;
return button;
}
private Button GetRandomButton()
{
var randomIndex = _Random.Next(0, flowLayoutPanel.Controls.Count);
return (Button)flowLayoutPanel.Controls[randomIndex];
}
private Color GetRandomColor()
{
var randomKnownColor = (KnownColor)_Random.Next((int)KnownColor.AliceBlue, (int)KnownColor.ButtonFace);
return Color.FromKnownColor(randomKnownColor);
}
private void InitializeColorButtons(int numberOfColors)
{
var buttons = Enumerable.Range(1, numberOfColors)
.Select(index => GetRandomColor())
.Select(color => CreateButton(color));
foreach (var button in buttons)
{
flowLayoutPanel.Controls.Add(button);
}
}
private void OnButtonStartClick(object sender, EventArgs e)
{
InitializeColorButtons((int)numericUpDownColors.Value);
StartMeasurement();
}
private void OnColorButtonClick(object sender, EventArgs e)
{
var button = (Button)sender;
if (button.Text != labelColorToClick.Text)
{
errorProviderWrongButton.SetIconPadding(button, -20);
errorProviderWrongButton.SetError(button, "Sorry, wrong button.");
return;
}
StopMeasurement();
_ReactionTimes.Add(_Stopwatch.Elapsed);
UpdateSummary();
}
private void StartMeasurement()
{
buttonStart.Enabled = false;
numericUpDownColors.Enabled = false;
labelColorToClick.Text = GetRandomButton().Text;
_Stopwatch.Reset();
_Stopwatch.Start();
}
private void StopMeasurement()
{
_Stopwatch.Stop();
errorProviderWrongButton.Clear();
flowLayoutPanel.Controls.Clear();
numericUpDownColors.Enabled = true;
buttonStart.Enabled = true;
labelColorToClick.Text = String.Empty;
}
private void UpdateSummary()
{
labelSummary.Text = String.Format("Current: {0:0.000} Minimum: {1:0.000} Maximum: {2:0.000}", _ReactionTimes.Last().TotalSeconds, _ReactionTimes.Min().TotalSeconds, _ReactionTimes.Max().TotalSeconds);
}
}
The Form1.Designer.cs file:
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.components = new System.ComponentModel.Container();
this.flowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel();
this.labelColorToClick = new System.Windows.Forms.Label();
this.buttonStart = new System.Windows.Forms.Button();
this.labelSummaryHeader = new System.Windows.Forms.Label();
this.labelSummary = new System.Windows.Forms.Label();
this.errorProviderWrongButton = new System.Windows.Forms.ErrorProvider(this.components);
this.numericUpDownColors = new System.Windows.Forms.NumericUpDown();
((System.ComponentModel.ISupportInitialize)(this.errorProviderWrongButton)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownColors)).BeginInit();
this.SuspendLayout();
//
// flowLayoutPanel
//
this.flowLayoutPanel.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.flowLayoutPanel.Location = new System.Drawing.Point(12, 41);
this.flowLayoutPanel.Name = "flowLayoutPanel";
this.flowLayoutPanel.Size = new System.Drawing.Size(560, 386);
this.flowLayoutPanel.TabIndex = 0;
//
// labelColorToClick
//
this.labelColorToClick.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.labelColorToClick.Location = new System.Drawing.Point(174, 12);
this.labelColorToClick.Name = "labelColorToClick";
this.labelColorToClick.Size = new System.Drawing.Size(398, 23);
this.labelColorToClick.TabIndex = 1;
this.labelColorToClick.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// buttonStart
//
this.buttonStart.Location = new System.Drawing.Point(93, 12);
this.buttonStart.Name = "buttonStart";
this.buttonStart.Size = new System.Drawing.Size(75, 23);
this.buttonStart.TabIndex = 2;
this.buttonStart.Text = "Start";
this.buttonStart.UseVisualStyleBackColor = true;
this.buttonStart.Click += new System.EventHandler(this.OnButtonStartClick);
//
// labelSummaryHeader
//
this.labelSummaryHeader.Location = new System.Drawing.Point(12, 430);
this.labelSummaryHeader.Name = "labelSummaryHeader";
this.labelSummaryHeader.Size = new System.Drawing.Size(75, 23);
this.labelSummaryHeader.TabIndex = 3;
this.labelSummaryHeader.Text = "Summary:";
this.labelSummaryHeader.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// labelSummary
//
this.labelSummary.Location = new System.Drawing.Point(93, 430);
this.labelSummary.Name = "labelSummary";
this.labelSummary.Size = new System.Drawing.Size(479, 23);
this.labelSummary.TabIndex = 4;
this.labelSummary.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// errorProviderWrongButton
//
this.errorProviderWrongButton.BlinkStyle = System.Windows.Forms.ErrorBlinkStyle.NeverBlink;
this.errorProviderWrongButton.ContainerControl = this;
//
// numericUpDownColors
//
this.numericUpDownColors.Location = new System.Drawing.Point(12, 14);
this.numericUpDownColors.Minimum = new decimal(new int[] {
2,
0,
0,
0});
this.numericUpDownColors.Name = "numericUpDownColors";
this.numericUpDownColors.Size = new System.Drawing.Size(75, 20);
this.numericUpDownColors.TabIndex = 5;
this.numericUpDownColors.Value = new decimal(new int[] {
10,
0,
0,
0});
//
// Form1
//
this.ClientSize = new System.Drawing.Size(584, 462);
this.Controls.Add(this.numericUpDownColors);
this.Controls.Add(this.labelSummary);
this.Controls.Add(this.labelSummaryHeader);
this.Controls.Add(this.buttonStart);
this.Controls.Add(this.labelColorToClick);
this.Controls.Add(this.flowLayoutPanel);
this.Name = "Form1";
((System.ComponentModel.ISupportInitialize)(this.errorProviderWrongButton)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownColors)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel;
private System.Windows.Forms.Label labelColorToClick;
private System.Windows.Forms.Button buttonStart;
private System.Windows.Forms.Label labelSummaryHeader;
private System.Windows.Forms.Label labelSummary;
private System.Windows.Forms.ErrorProvider errorProviderWrongButton;
private System.Windows.Forms.NumericUpDown numericUpDownColors;
}
I think your problem here is that the resolution of DateTime is less than the intervals that you are trying to measure.
Instead of using DateTime, try the following:
Create a private Stopwatch field called stopwatch.
Stopwatch stopwatch = new Stopwatch();
Then change your tick handler to:
private void timMessung_Tick(object sender, EventArgs e)
{
if (timMessung.Enabled == true)
{
stopwatch.Restart();
}
else
{
ts.stopwatch.Elapsed();
}
}
However, I'm also not sure about your logic to do with when you restart the stopwatch. (Where I put stopwatch.Restart().) Do you really want to keep restarting the stopwatch at that point?
use:
ts = Time1.subtract(Time2);
How to calculate datetime diffrence:
How to calculate hours between 2 different dates in c#

Remove the title bar in Windows Forms

How can I remove the blue border that's on top of the Window Form? (I don't know the name of it exactly.)
You can set the Property FormBorderStyle to none in the designer,
or in code:
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
if by Blue Border thats on top of the Window Form you mean titlebar, set Forms ControlBox property to false and Text property to empty string ("").
here's a snippet:
this.ControlBox = false;
this.Text = String.Empty;

			
				
Also add this bit of code to your form to allow it to be draggable still.
Just add it right before the constructor (the method that calls InitializeComponent()
private const int WM_NCHITTEST = 0x84;
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;
///
/// Handling the window messages
///
protected override void WndProc(ref Message message)
{
base.WndProc(ref message);
if (message.Msg == WM_NCHITTEST && (int)message.Result == HTCLIENT)
message.Result = (IntPtr)HTCAPTION;
}
That code is from: https://jachman.wordpress.com/2006/06/08/enhanced-drag-and-move-winforms-without-having-a-titlebar/
Now to get rid of the title bar but still have a border combine the code from the other response:
this.ControlBox = false;
this.Text = String.Empty;
with this line:
this.FormBorderStyle = FormBorderStyle.FixedSingle;
Put those 3 lines of code into the form's OnLoad event and you should have a nice 'floating' form that is draggable with a thin border (use FormBorderStyle.None if you want no border).
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Set FormsBorderStyle of the Form to None.
If you do, it's up to you how to implement the dragging and closing functionality of the window.
I am sharing my code.
form1.cs:-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BorderExp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
}
private void ExitClick(object sender, EventArgs e)
{
Application.Exit();
}
private void MaxClick(object sender, EventArgs e)
{
if (WindowState ==FormWindowState.Normal)
{
this.WindowState = FormWindowState.Maximized;
}
else
{
this.WindowState = FormWindowState.Normal;
}
}
private void MinClick(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
}
}
Now, the designer:-
namespace BorderExp
{
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.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button1.BackColor = System.Drawing.SystemColors.ButtonFace;
this.button1.BackgroundImage = global::BorderExp.Properties.Resources.blank_1_;
this.button1.FlatAppearance.BorderSize = 0;
this.button1.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.Location = new System.Drawing.Point(376, 1);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(27, 26);
this.button1.TabIndex = 0;
this.button1.Text = "X";
this.button1.UseVisualStyleBackColor = false;
this.button1.Click += new System.EventHandler(this.ExitClick);
//
// button2
//
this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button2.BackColor = System.Drawing.SystemColors.ButtonFace;
this.button2.BackgroundImage = global::BorderExp.Properties.Resources.blank_1_;
this.button2.FlatAppearance.BorderSize = 0;
this.button2.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button2.Location = new System.Drawing.Point(343, 1);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(27, 26);
this.button2.TabIndex = 1;
this.button2.Text = "[]";
this.button2.UseVisualStyleBackColor = false;
this.button2.Click += new System.EventHandler(this.MaxClick);
//
// button3
//
this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button3.BackColor = System.Drawing.SystemColors.ButtonFace;
this.button3.BackgroundImage = global::BorderExp.Properties.Resources.blank_1_;
this.button3.FlatAppearance.BorderSize = 0;
this.button3.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.button3.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button3.Location = new System.Drawing.Point(310, 1);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(27, 26);
this.button3.TabIndex = 2;
this.button3.Text = "___";
this.button3.UseVisualStyleBackColor = false;
this.button3.Click += new System.EventHandler(this.MinClick);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackgroundImage = global::BorderExp.Properties.Resources.blank_1_;
this.ClientSize = new System.Drawing.Size(403, 320);
this.ControlBox = false;
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
}
}
the screenshot:-
NoBorderForm

Windows Forms C# "Input string was not in a correct format"

I have a simple Windows Forms application which is used to calculate the solutions to a quadratic equation. Since it requires some values to be inputted into three different textboxes and then upon clicking a "Calculate" button, makes some calculations with the inputted values. Upon testing the application, and clicking the "Calculate" button prior to inputting any values, I get a Input string was not in a correct format This is due to trying to parse a non-existent value. Is there any way to avoid this? I tried to construct a conditional based on if the button was clicked and there was no values in the textboxes, to not do anything, but that didn't quite work. Here is my designer code:
namespace QuadraticSolver
{
partial class QuadraticSolver
{
/// <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.lblPrompt = new System.Windows.Forms.Label();
this.lblA = new System.Windows.Forms.Label();
this.lblB = new System.Windows.Forms.Label();
this.lblC = new System.Windows.Forms.Label();
this.txtA = new System.Windows.Forms.TextBox();
this.txtB = new System.Windows.Forms.TextBox();
this.txtC = new System.Windows.Forms.TextBox();
this.btnCalculate = new System.Windows.Forms.Button();
this.lblSolutions = new System.Windows.Forms.Label();
this.txtSolution1 = new System.Windows.Forms.TextBox();
this.txtSolution2 = new System.Windows.Forms.TextBox();
this.chkImaginary = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// lblPrompt
//
this.lblPrompt.AutoSize = true;
this.lblPrompt.Location = new System.Drawing.Point(12, 9);
this.lblPrompt.Name = "lblPrompt";
this.lblPrompt.Size = new System.Drawing.Size(92, 13);
this.lblPrompt.TabIndex = 0;
this.lblPrompt.Text = "Enter Your Values";
//
// lblA
//
this.lblA.AutoSize = true;
this.lblA.Location = new System.Drawing.Point(12, 49);
this.lblA.Name = "lblA";
this.lblA.Size = new System.Drawing.Size(16, 13);
this.lblA.TabIndex = 1;
this.lblA.Text = "a:";
//
// lblB
//
this.lblB.AutoSize = true;
this.lblB.Location = new System.Drawing.Point(12, 85);
this.lblB.Name = "lblB";
this.lblB.Size = new System.Drawing.Size(16, 13);
this.lblB.TabIndex = 2;
this.lblB.Text = "b:";
//
// lblC
//
this.lblC.AutoSize = true;
this.lblC.Location = new System.Drawing.Point(12, 122);
this.lblC.Name = "lblC";
this.lblC.Size = new System.Drawing.Size(16, 13);
this.lblC.TabIndex = 3;
this.lblC.Text = "c:";
//
// txtA
//
this.txtA.Location = new System.Drawing.Point(34, 46);
this.txtA.Name = "txtA";
this.txtA.Size = new System.Drawing.Size(360, 20);
this.txtA.TabIndex = 4;
//
// txtB
//
this.txtB.Location = new System.Drawing.Point(34, 82);
this.txtB.Name = "txtB";
this.txtB.Size = new System.Drawing.Size(360, 20);
this.txtB.TabIndex = 5;
//
// txtC
//
this.txtC.Location = new System.Drawing.Point(34, 122);
this.txtC.Name = "txtC";
this.txtC.Size = new System.Drawing.Size(360, 20);
this.txtC.TabIndex = 6;
//
// btnCalculate
//
this.btnCalculate.Location = new System.Drawing.Point(175, 154);
this.btnCalculate.Name = "btnCalculate";
this.btnCalculate.Size = new System.Drawing.Size(75, 23);
this.btnCalculate.TabIndex = 7;
this.btnCalculate.Text = "Calculate!";
this.btnCalculate.UseVisualStyleBackColor = true;
this.btnCalculate.Click += new System.EventHandler(this.btnCalculate_Click);
//
// lblSolutions
//
this.lblSolutions.AutoSize = true;
this.lblSolutions.Location = new System.Drawing.Point(31, 226);
this.lblSolutions.Name = "lblSolutions";
this.lblSolutions.Size = new System.Drawing.Size(53, 13);
this.lblSolutions.TabIndex = 8;
this.lblSolutions.Text = "Solutions:";
//
// txtSolution1
//
this.txtSolution1.Location = new System.Drawing.Point(34, 242);
this.txtSolution1.Name = "txtSolution1";
this.txtSolution1.ReadOnly = true;
this.txtSolution1.Size = new System.Drawing.Size(165, 20);
this.txtSolution1.TabIndex = 9;
//
// txtSolution2
//
this.txtSolution2.Location = new System.Drawing.Point(222, 242);
this.txtSolution2.Name = "txtSolution2";
this.txtSolution2.ReadOnly = true;
this.txtSolution2.Size = new System.Drawing.Size(172, 20);
this.txtSolution2.TabIndex = 10;
//
// chkImaginary
//
this.chkImaginary.AutoSize = true;
this.chkImaginary.Location = new System.Drawing.Point(33, 189);
this.chkImaginary.Name = "chkImaginary";
this.chkImaginary.Size = new System.Drawing.Size(71, 17);
this.chkImaginary.TabIndex = 11;
this.chkImaginary.Text = "Imaginary";
this.chkImaginary.UseVisualStyleBackColor = true;
//
// QuadraticSolver
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(406, 285);
this.Controls.Add(this.chkImaginary);
this.Controls.Add(this.txtSolution2);
this.Controls.Add(this.txtSolution1);
this.Controls.Add(this.lblSolutions);
this.Controls.Add(this.btnCalculate);
this.Controls.Add(this.txtC);
this.Controls.Add(this.txtB);
this.Controls.Add(this.txtA);
this.Controls.Add(this.lblC);
this.Controls.Add(this.lblB);
this.Controls.Add(this.lblA);
this.Controls.Add(this.lblPrompt);
this.Name = "QuadraticSolver";
this.Text = "Quadratic Solver";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label lblPrompt;
private System.Windows.Forms.Label lblA;
private System.Windows.Forms.Label lblB;
private System.Windows.Forms.Label lblC;
private System.Windows.Forms.TextBox txtA;
private System.Windows.Forms.TextBox txtB;
private System.Windows.Forms.TextBox txtC;
private System.Windows.Forms.Button btnCalculate;
private System.Windows.Forms.Label lblSolutions;
private System.Windows.Forms.TextBox txtSolution1;
private System.Windows.Forms.TextBox txtSolution2;
private System.Windows.Forms.CheckBox chkImaginary;
}
}
Here is my program's code which does the actual data manipulation:
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 QuadraticSolver
{
public partial class QuadraticSolver : Form
{
public QuadraticSolver()
{
InitializeComponent();
}
private void btnCalculate_Click(object sender, EventArgs e)
{
if (txtA.Text == "" || txtB.Text == "" || txtC.Text == "")
{
string stringSol = "Please enter some values!";
txtSolution1.Text = stringSol;
txtSolution2.Text = stringSol;
}
double aValue = double.Parse(txtA.Text);
double bValue = double.Parse(txtB.Text);
double cValue = double.Parse(txtC.Text);
double solution1Double, solution2Double;
//Quadratic Formula: x = (-b +- sqrt(b^2 - 4ac)) / 2a
//Calculate discriminant
double insideSquareRoot = (bValue * bValue) - 4 * aValue * cValue;
if (insideSquareRoot < 0)
{
//No real solution
solution1Double = Double.NaN;
solution2Double = Double.NaN;
txtSolution1.Text = solution1Double.ToString();
txtSolution2.Text = solution2Double.ToString();
}
else if (insideSquareRoot == 0)
{
//One real solution
double sqrtOneSolution = Math.Sqrt(insideSquareRoot);
solution1Double = (-bValue + sqrtOneSolution) / (2 * aValue);
solution2Double = double.NaN;
txtSolution1.Text = solution1Double.ToString();
txtSolution2.Text = solution2Double.ToString();
}
else if (insideSquareRoot > 0)
{
//Two real solutions
double sqrtTwoSolutions = Math.Sqrt(insideSquareRoot);
solution1Double = (-bValue + sqrtTwoSolutions) / (2 * aValue);
solution2Double = (-bValue - sqrtTwoSolutions) / (2 * aValue);
txtSolution1.Text = solution1Double.ToString();
txtSolution2.Text = solution2Double.ToString();
}
}
}
}
You can use the double.TryParse method.
This is better than checking for == "" since it will tell you that you can not parse "Hello" as a double too.
You also need to return from the event handler if one of the TryParse returns false.
You may consider using a NumericUpDown control instead. You are guaranteed the input from this control will be numeric. All the code that is required is then:
double userNumber = myNumUpDown.Value;
You can even restrict the number input to ensure it falls within your defined range
myNumUpDown.Minimum = 300;
myNumUpDown.Maximum = 500;
Along with many other things. Finally, it even comes with up/down GUI controls so your users can be super lazy and enter the number with their mouse!
You can try this format,
replace the textbox1 with your textbox name.
int a = textbox1.Text != "" ? Convert.ToInt32(textbox1.Text) : 0;
int b = textbox2.Text != "" ? Convert.ToInt32(textbox2.Text) : 0;
int total = a + b;
you can reassign the result this way:
textbox3 = total.toString();
if (txtA.Text == "" || txtB.Text == "" || txtC.Text == "")
{
string stringSol = "Please enter some values!";
txtSolution1.Text = stringSol;
txtSolution2.Text = stringSol;
return;
}

Picturebox draws artefacts when in RightToLeft mode

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);

Categories