winform - Create control like Visual Studio's anchor property control - c#

I find the Visual Studio's anchor property control very user friendly.
If I don't have this control, I need to create 4 check-boxes (or a CheckedlistBox):
Top, Bottom, Left, Right.
So this anchor will make the GUI of the software looks neat. How can I create the control like this Visual Studio's anchor property control?

Create your own using a Panel, 1 Button and 4 Checkbox, set chkTop.Appearance = System.Windows.Forms.Appearance.Button
Normal style
Checked style
Code
partial class Form2
{
/// <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.panel1 = new System.Windows.Forms.Panel();
this.chkTop = new System.Windows.Forms.CheckBox();
this.button1 = new System.Windows.Forms.Button();
this.chkBottom = new System.Windows.Forms.CheckBox();
this.chkRight = new System.Windows.Forms.CheckBox();
this.chkLeft = new System.Windows.Forms.CheckBox();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.White;
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Controls.Add(this.chkLeft);
this.panel1.Controls.Add(this.chkRight);
this.panel1.Controls.Add(this.chkBottom);
this.panel1.Controls.Add(this.chkTop);
this.panel1.Controls.Add(this.button1);
this.panel1.Location = new System.Drawing.Point(43, 49);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(207, 148);
this.panel1.TabIndex = 0;
//
// chkTop
//
this.chkTop.Appearance = System.Windows.Forms.Appearance.Button;
this.chkTop.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.chkTop.FlatAppearance.CheckedBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
this.chkTop.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.chkTop.Location = new System.Drawing.Point(95, 2);
this.chkTop.Name = "chkTop";
this.chkTop.Size = new System.Drawing.Size(17, 58);
this.chkTop.TabIndex = 1;
this.chkTop.UseVisualStyleBackColor = false;
//
// button1
//
this.button1.BackColor = System.Drawing.Color.Gray;
this.button1.Enabled = false;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.Location = new System.Drawing.Point(73, 61);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(58, 23);
this.button1.TabIndex = 0;
this.button1.UseVisualStyleBackColor = false;
//
// chkBottom
//
this.chkBottom.Appearance = System.Windows.Forms.Appearance.Button;
this.chkBottom.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.chkBottom.FlatAppearance.CheckedBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
this.chkBottom.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.chkBottom.Location = new System.Drawing.Point(95, 85);
this.chkBottom.Name = "chkBottom";
this.chkBottom.Size = new System.Drawing.Size(17, 59);
this.chkBottom.TabIndex = 2;
this.chkBottom.UseVisualStyleBackColor = false;
//
// chkRight
//
this.chkRight.Appearance = System.Windows.Forms.Appearance.Button;
this.chkRight.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.chkRight.FlatAppearance.CheckedBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
this.chkRight.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.chkRight.Location = new System.Drawing.Point(132, 64);
this.chkRight.Name = "chkRight";
this.chkRight.Size = new System.Drawing.Size(71, 17);
this.chkRight.TabIndex = 3;
this.chkRight.UseVisualStyleBackColor = false;
//
// chkLeft
//
this.chkLeft.Appearance = System.Windows.Forms.Appearance.Button;
this.chkLeft.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.chkLeft.FlatAppearance.CheckedBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
this.chkLeft.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.chkLeft.Location = new System.Drawing.Point(1, 63);
this.chkLeft.Name = "chkLeft";
this.chkLeft.Size = new System.Drawing.Size(71, 17);
this.chkLeft.TabIndex = 4;
this.chkLeft.UseVisualStyleBackColor = false;
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.panel1);
this.Name = "Form2";
this.Text = "Form2";
this.Load += new System.EventHandler(this.Form2_Load);
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.CheckBox chkTop;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.CheckBox chkLeft;
private System.Windows.Forms.CheckBox chkRight;
private System.Windows.Forms.CheckBox chkBottom;
}

The AnchorStyles enumeration type has an attribute that determines how this value type configured in the winforms designer.
[Editor("System.Windows.Forms.Design.AnchorEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
So in ordner to do that with your own type, you need to build your type specific UITypeEditor class and tag your type with the Editor attribute.
Get ILSpy or any other .NET disassembler and see what the the AnchorEditor class does and how its structured.

Related

When I try to execute my Windows Form in C#, It's blank?

When I try to execute my windows form application, all I see is a completely white blank form. When I look in my form1.cs[Design] everything looks normal, but not when I run it? I can't see the labels, or the buttons or anything. I've never had this issue before and my InitializeComponent I think is where it should be? Here is my Form1.Designer.Cs, or maybe there's an issue in my form1.cs?
partial class Identity
{
/// <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.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.label6 = new System.Windows.Forms.Label();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(278, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(116, 87);
this.label1.TabIndex = 0;
this.label1.Text = "VÄLKOMMEN!";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.Location = new System.Drawing.Point(67, 87);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(222, 23);
this.label2.TabIndex = 1;
this.label2.Text = "Skriv in ditt namn och personnummer nedan.:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(67, 181);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(51, 13);
this.label3.TabIndex = 2;
this.label3.Text = "Förnamn:";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(63, 217);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(58, 13);
this.label4.TabIndex = 3;
this.label4.Text = "Efternamn:";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(30, 269);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(161, 13);
this.label5.TabIndex = 4;
this.label5.Text = "Personummer:(ååååmmdd - xxxx)";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(127, 174);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 5;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(127, 210);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 20);
this.textBox2.TabIndex = 6;
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(197, 266);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(164, 20);
this.textBox3.TabIndex = 7;
//
// button1
//
this.button1.Location = new System.Drawing.Point(307, 329);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(87, 51);
this.button1.TabIndex = 8;
this.button1.Text = "Kör!";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(337, 395);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(35, 13);
this.label6.TabIndex = 9;
this.label6.Text = "label6";
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(33, 423);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(492, 296);
this.richTextBox1.TabIndex = 10;
this.richTextBox1.Text = "\"\"";
//
// button2
//
this.button2.Location = new System.Drawing.Point(662, 650);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(116, 69);
this.button2.TabIndex = 11;
this.button2.Text = "Avsluta:";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Identity
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1207, 755);
this.Controls.Add(this.button2);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.label6);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Identity";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.Button button2;
private EventHandler label1_Click;
}
}
Here I am calling the IntializeComponent in my Form1.cs, I haven't moved it since I started this new program at all.
public partial class Identity : Form
{
public Identity()
{
InitializeComponent();
}
public struct Person
{
public double idok;
public string fname;
public string lname;
public string id;
public string sex;
public string year;
public string fyear;
}
Per the comment trail, you made a new solution, copied some select lines over from the problematic form's designer code, commented out some event handlers that were missing in the designer code, and then were able to load the designer and add the missing event handlers and their body code. The resulting form worked OK

How to delete record from database with checkbox in telerik radgridview C#

I want to delete record from database with checkbox in telerik radgridview
...
Please Help Me!
Thanks
See the code below. That should do what you want!!
namespace WindowsFormsApplication6
{
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.dataGridView1 = new System.Windows.Forms.DataGridView();
this.button2 = new System.Windows.Forms.Button();
this.Column1 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
this.button3 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(13, 13);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(113, 23);
this.button1.TabIndex = 0;
this.button1.Text = "Import Data";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// dataGridView1
//
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Column1});
this.dataGridView1.Location = new System.Drawing.Point(13, 43);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(692, 209);
this.dataGridView1.TabIndex = 1;
//this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick);
//
// button2
//
this.button2.Location = new System.Drawing.Point(144, 13);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(113, 23);
this.button2.TabIndex = 2;
this.button2.Text = "Export Data";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Column1
//
this.Column1.HeaderText = "Column1";
this.Column1.Name = "Column1";
//
// button3
//
this.button3.Location = new System.Drawing.Point(331, 13);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(183, 23);
this.button3.TabIndex = 3;
this.button3.Text = "Delete If CheckBox Checked";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(717, 264);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.dataGridView1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.DataGridViewCheckBoxColumn Column1;
private System.Windows.Forms.Button button3;
}
}

Add textbox value to webpage C# using Webbrowser?

I am adding value to a textbox on webpage.
Here is the Inspect Element code:
<input type="text" name="DERIVED_LAM_GRADE_1$0" id="DERIVED_LAM_GRADE_1$0"
tabindex="90" value="0.00" class="PSEDITBOX" style="width:44px;
text-align:right; " maxlength="6" onchange="addchg_win0(this);oChange_win0=this;">
and here is my C# code:
Which is giving me Exception "Object reference not set to an instance of an object."
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string username = textBox1.Text;
HtmlDocument doc = this.webBrowser1.Document;
doc.GetElementById("DERIVED_LAM_GRADE_1$0").SetAttribute("value", username);
}
}
}
i Dont know whats wrong. i am giving a perfect id and still its throwing exception.
Designer CODE:
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.webBrowser1 = new System.Windows.Forms.WebBrowser();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.button1 = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox1 = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.SuspendLayout();
//
// webBrowser1
//
this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
this.webBrowser1.Location = new System.Drawing.Point(0, 0);
this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
this.webBrowser1.Name = "webBrowser1";
this.webBrowser1.Size = new System.Drawing.Size(527, 309);
this.webBrowser1.TabIndex = 0;
this.webBrowser1.Url = new System.Uri("http://cms.nust.edu.pk/psp/ps/?cmd=login", System.UriKind.Absolute);
//
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Location = new System.Drawing.Point(0, 0);
this.splitContainer1.Name = "splitContainer1";
this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.button1);
this.splitContainer1.Panel1.Controls.Add(this.label2);
this.splitContainer1.Panel1.Controls.Add(this.label1);
this.splitContainer1.Panel1.Controls.Add(this.textBox2);
this.splitContainer1.Panel1.Controls.Add(this.textBox1);
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.webBrowser1);
this.splitContainer1.Size = new System.Drawing.Size(527, 398);
this.splitContainer1.SplitterDistance = 85;
this.splitContainer1.TabIndex = 1;
//
// button1
//
this.button1.Location = new System.Drawing.Point(330, 31);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 4;
this.button1.Text = "Insert";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(149, 61);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(53, 13);
this.label2.TabIndex = 3;
this.label2.Text = "Password";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(149, 15);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(55, 13);
this.label1.TabIndex = 2;
this.label1.Text = "Username";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(208, 58);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 20);
this.textBox2.TabIndex = 1;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(208, 12);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(527, 398);
this.Controls.Add(this.splitContainer1);
this.Name = "Form1";
this.Text = "Form1";
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel1.PerformLayout();
this.splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.WebBrowser webBrowser1;
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox1;
}
}

webbrowser component print qplot graph with an offset

does anyone has an idea concerning the webbrowser component that always print jqplot graphs with a weird offset ?
This very simple exemple loading a jqplot exemple page in a webbrowser component, showes the page correctly, but when you try to print it you get an offset in the graph only.
The same web page show and print correctly from within IE !
I also tryied this exemple programed in Delphi2007 and DelphiXE3 and got exactly the same results.
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.Windows.Forms;
namespace testwebbrowser
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
wb.Navigate("http://www.jqplot.com/tests/bar-charts.php");
}
private void button2_Click(object sender, EventArgs e)
{
wb.ShowPrintPreviewDialog();
}
}
}
Form1.Designer.cs
namespace testwebbrowser
{
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.panel1 = new System.Windows.Forms.Panel();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.wb = new System.Windows.Forms.WebBrowser();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.Controls.Add(this.button2);
this.panel1.Controls.Add(this.button1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(597, 71);
this.panel1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(12, 12);
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;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(93, 12);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 1;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// wb
//
this.wb.Dock = System.Windows.Forms.DockStyle.Fill;
this.wb.Location = new System.Drawing.Point(0, 71);
this.wb.MinimumSize = new System.Drawing.Size(20, 20);
this.wb.Name = "wb";
this.wb.Size = new System.Drawing.Size(597, 370);
this.wb.TabIndex = 1;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(597, 441);
this.Controls.Add(this.wb);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.WebBrowser wb;
}
}

Panel visibility not changing in C# visual studio 2010

I'm trying to do something that i would think to be rather simple. I have 2 toolstrip items.
test1: ToolStripMenuItem which should show panel -> test_panel_1
test2: ToolStripMenuItem which should show panel -> panel1
test_panel_1 contains button -> panel_1_button1 which should hide test_panel_1 and show test_panel_2
panel1 contains button -> button1 which should hide test_panel2 and then show panel2
However, when I run the code and click on test1ToolStripMenuItem it shows test_panel_1 like it's supposed to, then when i click on panel_1_button_1 it just clears test_panel_1 and doesn't show test_panel_2. And regardless of what I click first, test2ToolStripMenuItem doesn't show panel1 at all.
Here's my code...
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 panel_test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void panel_1_button1_Click(object sender, EventArgs e)
{
test_panel2.Visible = true;
test_panel_1.Visible = false;
}
private void test1ToolStripMenuItem_Click(object sender, EventArgs e)
{
test_panel_1.Visible = true;
panel1.Visible = false;
}
private void button1_click(object sender, EventArgs e)
{
test_panel_1.Visible = false;
test_panel2.Visible = true;
}
private void test2ToolStripMenuItem_Click(object sender, EventArgs e)
{
test_panel2.Visible = false;
panel1.Visible = true;
}
private void button1_Click_1(object sender, EventArgs e)
{
this.panel1.Visible = false;
this.panel2.Visible = true;
}
}
}
and, not sure if this helps, but...
namespace panel_test
{
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.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.testToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.test1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.test2ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.test3ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.test_panel_1 = new System.Windows.Forms.Panel();
this.panel1 = new System.Windows.Forms.Panel();
this.button1 = new System.Windows.Forms.Button();
this.panel2 = new System.Windows.Forms.Panel();
this.label3 = new System.Windows.Forms.Label();
this.test_panel2 = new System.Windows.Forms.Panel();
this.label2 = new System.Windows.Forms.Label();
this.panel_1_button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.menuStrip1.SuspendLayout();
this.test_panel_1.SuspendLayout();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.test_panel2.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.testToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(467, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// testToolStripMenuItem
//
this.testToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.test1ToolStripMenuItem,
this.test2ToolStripMenuItem,
this.test3ToolStripMenuItem});
this.testToolStripMenuItem.Name = "testToolStripMenuItem";
this.testToolStripMenuItem.Size = new System.Drawing.Size(38, 20);
this.testToolStripMenuItem.Text = "test";
//
// test1ToolStripMenuItem
//
this.test1ToolStripMenuItem.Name = "test1ToolStripMenuItem";
this.test1ToolStripMenuItem.Size = new System.Drawing.Size(99, 22);
this.test1ToolStripMenuItem.Text = "test1";
this.test1ToolStripMenuItem.Click += new System.EventHandler(this.test1ToolStripMenuItem_Click);
//
// test2ToolStripMenuItem
//
this.test2ToolStripMenuItem.Name = "test2ToolStripMenuItem";
this.test2ToolStripMenuItem.Size = new System.Drawing.Size(99, 22);
this.test2ToolStripMenuItem.Text = "test2";
this.test2ToolStripMenuItem.Click += new System.EventHandler(this.test2ToolStripMenuItem_Click);
//
// test3ToolStripMenuItem
//
this.test3ToolStripMenuItem.Name = "test3ToolStripMenuItem";
this.test3ToolStripMenuItem.Size = new System.Drawing.Size(99, 22);
this.test3ToolStripMenuItem.Text = "test3";
//
// test_panel_1
//
this.test_panel_1.Controls.Add(this.test_panel2);
this.test_panel_1.Controls.Add(this.panel_1_button1);
this.test_panel_1.Controls.Add(this.label1);
this.test_panel_1.Location = new System.Drawing.Point(44, 28);
this.test_panel_1.Name = "test_panel_1";
this.test_panel_1.Size = new System.Drawing.Size(442, 317);
this.test_panel_1.TabIndex = 1;
this.test_panel_1.Visible = false;
//
// panel1
//
this.panel1.Controls.Add(this.button1);
this.panel1.Location = new System.Drawing.Point(218, 187);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(328, 318);
this.panel1.TabIndex = 1;
this.panel1.Visible = false;
//
// button1
//
this.button1.Location = new System.Drawing.Point(86, 155);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "panel 3 to 4";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click_1);
//
// panel2
//
this.panel2.Controls.Add(this.panel1);
this.panel2.Controls.Add(this.label3);
this.panel2.Location = new System.Drawing.Point(95, 194);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(398, 260);
this.panel2.TabIndex = 1;
this.panel2.Visible = false;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(86, 118);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(71, 13);
this.label3.TabIndex = 0;
this.label3.Text = "this is panel 4";
//
// test_panel2
//
this.test_panel2.Controls.Add(this.panel2);
this.test_panel2.Controls.Add(this.label2);
this.test_panel2.Location = new System.Drawing.Point(154, 101);
this.test_panel2.Name = "test_panel2";
this.test_panel2.Size = new System.Drawing.Size(358, 237);
this.test_panel2.TabIndex = 3;
this.test_panel2.Visible = false;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(70, 118);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(71, 13);
this.label2.TabIndex = 0;
this.label2.Text = "this is panel 2";
//
// panel_1_button1
//
this.panel_1_button1.Location = new System.Drawing.Point(86, 155);
this.panel_1_button1.Name = "panel_1_button1";
this.panel_1_button1.Size = new System.Drawing.Size(75, 23);
this.panel_1_button1.TabIndex = 2;
this.panel_1_button1.Text = "button1";
this.panel_1_button1.UseVisualStyleBackColor = true;
this.panel_1_button1.Click += new System.EventHandler(this.panel_1_button1_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(28, 21);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(42, 13);
this.label1.TabIndex = 0;
this.label1.Text = "panel 1";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(467, 357);
this.Controls.Add(this.test_panel_1);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "Form1";
this.Text = "Form1";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.test_panel_1.ResumeLayout(false);
this.test_panel_1.PerformLayout();
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.panel2.PerformLayout();
this.test_panel2.ResumeLayout(false);
this.test_panel2.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem testToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem test1ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem test2ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem test3ToolStripMenuItem;
private System.Windows.Forms.Panel test_panel_1;
private System.Windows.Forms.Panel test_panel2;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button panel_1_button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button button1;
}
}
I've toyed with Usercontrols a little, and i like the way i can edit and view them much better than panels; however, i don't know how to control hiding and showing them.
Thanks for the help. I know this must be coding 101, but it's something i haven't quite fully figured out yet.
It looks like your test_panel_2 is a child of test_panel_1. panel1 is a child of panel2. This is likely not what you intended. What's happening is that, because test_panel_2 is inside test_panel_1, hiding test_panel_1 also hides test_panel_2. There's a hierarchy there.
There's one or two spots where you set the visibility to false again - I'm not sure if those are correct.

Categories