Preventing users from resizing columns widths in ListView? - c#

I have a ListView In My Winform that has 4columns, Name, Money, ID and Level.
The problem is when I run my app, I still have the ability to mess with the columns widths
and change them.
I searched And found that I should do something like this:
private void listView1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
e.Cancel = true;
e.NewWidth = listView1.Columns[e.ColumnIndex].Width;
}
But the problem is that when I debugged and Ccanged the columns widths, this event didn't even fire!
Why didn't it fire?
And how can I make the column widths fixed?
I made a new winform app just in case if there was something wrong in my old one,
it fired, but only for the first time running the app .. here's the code:
namespace CsharpWinformTestingStuff
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
listView1.ColumnWidthChanging += new ColumnWidthChangingEventHandler(listView1_ColumnWidthChanging);
}
void listView1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
e.Cancel = true;
e.NewWidth = listView1.Columns[e.ColumnIndex].Width;
}
}
}
here is the initialize component just in case you might wanna know:
private void InitializeComponent()
{
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.SuspendLayout();
//
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3});
this.listView1.GridLines = true;
this.listView1.Location = new System.Drawing.Point(12, 12);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(284, 275);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;
//
// columnHeader1
//
this.columnHeader1.Text = "Name";
this.columnHeader1.Width = 97;
//
// columnHeader2
//
this.columnHeader2.Text = "Age";
this.columnHeader2.Width = 52;
//
// columnHeader3
//
this.columnHeader3.Text = "Email";
this.columnHeader3.Width = 157;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(308, 299);
this.Controls.Add(this.listView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}

You need to register the ColumnWidthChanging event with your form:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// This line registers the event, soc that the form can "hear" it and call the indicated handling code:
this.listView1.ColumnWidthChanging += new ColumnWidthChangingEventHandler(listView1_ColumnWidthChanging);
}
void listView1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
Console.Write("Column Resizing");
e.NewWidth = this.listView1.Columns[e.ColumnIndex].Width;
e.Cancel = true;
}
}

Just click on the Properties>>Events>>ColumnWidthChanging.
Then add this code:
private void lstItems_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
e.Cancel = true;
e.NewWidth = lstItems.Columns[e.ColumnIndex].Width;
}
Happy coding! ^_^

You may check Better ListView Express. We have implemented AllowResize property on the columns, which does exactly what you need.

Related

CheckListBox for each

I'm losing my mind with CheckListBox, I tried to get all of my checked items in my list. Here the code I use, with the button which are on my User interface:
public partial class formPCRBaseline : Form
{
public formPCRBaseline(List<GetBaselineSectionTasks> m_objPCRCheck)
{
InitializeComponent();
setDefaults(m_objPCRCheck);
}
private void setDefaults(List<GetBaselineSectionTasks> m_objPCRCheck)
{
checkedListBox.BackColor = Color.White;
List<GetBaselineSectionTasks> m_objCheckeditem = new List<GetBaselineSectionTasks>();
int i= 0;
foreach (GetBaselineSectionTasks i_objPCRCheck in m_objPCRCheck)
{
checkedListBox.Items.Add(i_objPCRCheck.taskname);
}
}
private void buttonConfirm_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
private void buttonClose_Click_1(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
public List<GetBaselineSectionTasks> GetCheckedItems()
{
List<GetBaselineSectionTasks> m_objCheckeditem = new List<GetBaselineSectionTasks>();
m_objCheckeditem.AddRange(checkedListBox.CheckedItems.OfType<GetBaselineSectionTasks>());
return m_objCheckeditem;
}
}
}
And here the class I use to Initialize my component:
private void InitializeComponent()
{
this.buttonClose = new System.Windows.Forms.Button();
this.buttonConfirm = new System.Windows.Forms.Button();
this.checkedListBox = new System.Windows.Forms.CheckedListBox();
this.SuspendLayout();
//
// buttonClose
//
this.buttonClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonClose.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F);
this.buttonClose.Location = new System.Drawing.Point(306, 299);
this.buttonClose.Name = "buttonClose";
this.buttonClose.Size = new System.Drawing.Size(100, 30);
this.buttonClose.TabIndex = 0;
this.buttonClose.Text = "Cancel";
this.buttonClose.UseVisualStyleBackColor = true;
this.buttonClose.Click += new System.EventHandler(this.buttonClose_Click_1);
//
// buttonConfirm
//
this.buttonConfirm.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonConfirm.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F);
this.buttonConfirm.Location = new System.Drawing.Point(192, 299);
this.buttonConfirm.Name = "buttonConfirm";
this.buttonConfirm.Size = new System.Drawing.Size(100, 30);
this.buttonConfirm.TabIndex = 4;
this.buttonConfirm.Text = "OK";
this.buttonConfirm.UseVisualStyleBackColor = true;
this.buttonConfirm.Click += new System.EventHandler(this.buttonConfirm_Click);
//
// checkedListBox
//
this.checkedListBox.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.checkedListBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 5.5F);
this.checkedListBox.FormattingEnabled = true;
this.checkedListBox.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.checkedListBox.Location = new System.Drawing.Point(16, 41);
this.checkedListBox.Name = "checkedListBox";
this.checkedListBox.Size = new System.Drawing.Size(394, 244);
this.checkedListBox.TabIndex = 5;
//
// formPCRBaseline
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(418, 334);
this.Controls.Add(this.checkedListBox);
this.Controls.Add(this.buttonConfirm);
this.Controls.Add(this.buttonClose);
this.Name = "formPCRBaseline";
this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "PMIS – Project Planning";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button buttonClose;
private System.Windows.Forms.Button buttonConfirm;
private System.Windows.Forms.CheckedListBox checkedListBox;
But it doesn't work, when I use my breakpoint, it reached the foreach, I have two selected items but it doesn't get in
Any idea of what I could do?
Are you looking for CheckedItems / CheckedIndices property? Providing that CheckListBox - checkedListBox contains GetBaselineSectionTasks items, i.e. you fill it like this:
checkedListBox.Items.Add(new GetBaselineSectionTasks(...));
...
checkedListBox.Items.Add(new GetBaselineSectionTasks(...));
You can put
List<GetBaselineSectionTasks> m_objCheckeditem = new List<GetBaselineSectionTasks();
...
m_objCheckeditem.AddRange(checkedListBox.CheckedItems.OfType<GetBaselineSectionTasks>());
or if you want to create a list in one go:
List<GetBaselineSectionTasks> result = checkedListBox.CheckedItems
.OfType<GetBaselineSectionTasks>()
.ToList();
Edit: If are working with strings i.e. you fill checkedListBox like this:
checkedListBox.Items.Add("Some Value");
...
checkedListBox.Items.Add("Some other value");
you can loop over checked items and when trying to foind out the corresponding
foreach (int index in checkedListBox.CheckedIndices) {
string taskName = Convert.ToString(checkedListBox[index]);
// Now you have item index and item text (which is taskName). Let's try filling the list
// We can try finding the item by string
for (var item in m_objPCRCheck) {
if (item.taskname == taskName) {
m_objCheckeditem.Add(item);
break;
}
}
// Or (alternatively) you can trying to get index-th item:
// m_objCheckeditem.Add(m_objPCRCheck[index]);
}

How to open a C# windows form in another correctly by clicking a button?

![enter image description here][1]I want to design a c# windows form which when user clicks a button, a new form opens and gets some values. Then I use that values in parent form.
But when I start the program and click the button, Visual Studio opens a blank win form, while I expected it opens the child form that I designed before.
So what is the reason? I can't find any solutions. What is your ideas?
Here are the codes:
Form1
private void button1__Click(object sender, EventArgs e)
{
Form2 f = new Form2();
f.Show();
}
Form2
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 Date_Time
{
public partial class Form2 : Form
{
private Label label1;
private Label label2;
private Label label3;
private TextBox txtYear;
private TextBox txtMonth;
private Button btnOk;
private TextBox txtDay;
public void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.txtYear = new System.Windows.Forms.TextBox();
this.txtMonth = new System.Windows.Forms.TextBox();
this.txtDay = new System.Windows.Forms.TextBox();
this.btnOk = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(91, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Change in Years: ";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(13, 36);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(99, 13);
this.label2.TabIndex = 1;
this.label2.Text = "Change in Months: ";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(13, 62);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(88, 13);
this.label3.TabIndex = 2;
this.label3.Text = "Change in Days: ";
//
// txtYear
//
this.txtYear.Location = new System.Drawing.Point(109, 6);
this.txtYear.Name = "txtYear";
this.txtYear.Size = new System.Drawing.Size(100, 20);
this.txtYear.TabIndex = 3;
//
// txtMonth
//
this.txtMonth.Location = new System.Drawing.Point(109, 33);
this.txtMonth.Name = "txtMonth";
this.txtMonth.Size = new System.Drawing.Size(100, 20);
this.txtMonth.TabIndex = 4;
//
// txtDay
//
this.txtDay.Location = new System.Drawing.Point(109, 59);
this.txtDay.Name = "txtDay";
this.txtDay.Size = new System.Drawing.Size(100, 20);
this.txtDay.TabIndex = 5;
//
// btnOk
//
this.btnOk.ImageKey = "(none)";
this.btnOk.Location = new System.Drawing.Point(73, 85);
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(75, 23);
this.btnOk.TabIndex = 6;
this.btnOk.Tag = "";
this.btnOk.Text = "&Ok";
this.btnOk.UseVisualStyleBackColor = true;
//
// Options
//
this.ClientSize = new System.Drawing.Size(238, 120);
this.Controls.Add(this.btnOk);
this.Controls.Add(this.txtDay);
this.Controls.Add(this.txtMonth);
this.Controls.Add(this.txtYear);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Options";
this.Text = "Options";
this.ResumeLayout(false);
this.PerformLayout();
}
}
}
From a glance, the thing that stands out to me is your second form is defined as so:
public partial class Options : Form
{
//code
}
But when you try to show it to the user, you are using a Form2 class instead of an Options class. Try changing your button1_Click to the following:
private void button1__Click(object sender, EventArgs e)
{
Options opt = new Options();
opt.Show();
}
You might also want to make sure that the constructor for the Options form is calling the InitializeComponent method:
public partial class Options : Form
{
public Options()
{
InitializeComponent();
}
private void btnOk_Click(object sender, EventArgs e)
{
//Coding for your Options' Form ok button
}
}
private void button1__Click(object sender, EventArgs e)
{
Form2 newForm = new Form2();
newForm.ShowDialog();
// here you can take your parameters
int x = newForm.x;
int y = newForm.y;
}
// you should have definitions for x and y in your child form
public partial class Form2: Form
{
public int x{get; set;}
public int y{get; set;}
public Form2(){}
// do stuff
}
Sorry for taking your time friends. I found the reason finally by #user3189142's and Yorye's help. :) Thank you!
The child form(Options) was not complete. It was missing following code:
public Options()
{
InitializeComponent();
}
Thanks all.

Bind List<class> to DataGridView

I need your help on how to bind List to the DataGridView. I tried to use the BindingList<T> but still it does not display the records in my gridview. I tried using the List<T>, but it still does not work.
Below is the code which I used:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ToolClientController ctrl = new ToolClientController();
IpAddressTextbox.Text = ctrl.GetIPv4Config();
PortNumberTextbox.Text = ctrl.GetPortNumber();
}
private void BrowseButton_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
ToolMsgFileTextbox.Text = openFileDialog1.FileName;
}
}
private void UploadButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(ToolMsgFileTextbox.Text))
{
FileTypeError.SetError(UploadButton, "Please enter filename.");
return;
}
if (!openFileDialog1.FileName.Contains(".txt"))
{
FileTypeError.SetError(UploadButton, "File should be in .txt");
return;
}
ToolClientController ctrl = new ToolClientController();
List<ToolMessages> test = new List<ToolMessages>();
ToolMessages tool = new ToolMessages();
tool.IsPass = true;
tool.ToolMessageReply = string.Empty;
tool.ToolMessageRequest = "x";
test.Add(tool);
MessageGridViews.AutoGenerateColumns = false;
DataGridViewTextBoxColumn col1 = new DataGridViewTextBoxColumn();
col1.DataPropertyName = "ToolMessageRequest";
col1.HeaderText = "Request";
MessageGridViews.Columns.Add(col1);
BindingList<ToolMessages> bind = new BindingList<ToolMessages>(test);
MessageGridViews.VirtualMode = true;
MessageGridViews.DataSource = bind;
}
}
Based on your code I prepared simple WinForms app:
public Form1()
{
InitializeComponent();
List<ToolMessages> test = new List<ToolMessages>();
ToolMessages tool = new ToolMessages();
tool.IsPass = true;
tool.ToolMessageReply = string.Empty;
tool.ToolMessageRequest = "x";
test.Add(tool);
dataGridView1.AutoGenerateColumns = false;
DataGridViewTextBoxColumn col1 = new DataGridViewTextBoxColumn();
col1.DataPropertyName = "ToolMessageRequest";
col1.HeaderText = "Request";
dataGridView1.Columns.Add(col1);
BindingList<ToolMessages> bind = new BindingList<ToolMessages>(test);
dataGridView1.DataSource = bind;
dataGridView1.Show();
}
I added dataGridView1 into form directly via WinForms designer, so InitializeComponent method looks like:
private void InitializeComponent()
{
this.dataGridView1 = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// dataGridView1
//
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Location = new System.Drawing.Point(560, 57);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(240, 150);
this.dataGridView1.TabIndex = 1;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(967, 399);
this.Controls.Add(this.dataGridView1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.gridControl1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.gridView1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
}
And everything seems to work just fine... Data are bound to grid and ouput looks like:
which is exactly what I would expect to see, so I don't see any real problem with you solution, unless you post bigger piece of your code on which I can reproduce the issue you are experiencing.

How to set my form icon off if the form is maximized with IsMdiContainer = true

How to set my form icon off when the child form is maximized into its parent form. I have set my IsMdiContainer = true. I just wanted to get the icon off coz it messes up my menu bar.
minimized :
maximized :
Sorry, i'm still new in c# winforms. Thanks for helping me out .. :)
The MenuStrip is adding a menu for you. You can stop it with this code:
private void menuStrip1_ItemAdded(object sender, ToolStripItemEventArgs e)
{
if (e != null && e.Item != null && e.Item.GetType().Name == "SystemMenuItem")
{
this.menuStrip1.Items.RemoveAt(0);
}
}
Here's my full working example:
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public class ExampleForm : Form
{
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
public ExampleForm()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(1002, 24);
this.menuStrip1.TabIndex = 1;
this.menuStrip1.Text = "menuStrip1";
this.menuStrip1.ItemAdded += new System.Windows.Forms.ToolStripItemEventHandler(this.menuStrip1_ItemAdded);
//
// fileToolStripMenuItem
//
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.openToolStripMenuItem});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
this.fileToolStripMenuItem.Text = "&File";
//
// openToolStripMenuItem
//
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
this.openToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O)));
this.openToolStripMenuItem.Size = new System.Drawing.Size(146, 22);
this.openToolStripMenuItem.Text = "&Open";
this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1002, 674);
this.Controls.Add(this.menuStrip1);
this.IsMdiContainer = true;
this.MainMenuStrip = this.menuStrip1;
this.Name = "Form1";
this.Text = "Form1";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
var form = new Form
{
Text = "Child",
MdiParent = this,
ShowIcon = false
};
form.Show();
}
private void menuStrip1_ItemAdded(object sender, ToolStripItemEventArgs e)
{
if (e != null && e.Item != null && e.Item.GetType().Name == "SystemMenuItem")
{
this.menuStrip1.Items.RemoveAt(0);
}
}
}
}

My C# Windows Form Application is blank?

I'm Making A windows form application , And everytime I Excute it , All i see is a blank form , My project is named frmMain.cs and this is the header that i use :
using System;
using System.Windows.Forms;
public class frmMain : Form
{
private TextBox txtYear;
private Button btnCheck;
private Button btnClose;
private Label label1;
#region windows code
private void IntitializeComonent()
{
}
#endregion
public frmMain()
{
IntitializeComonent();
}
[STAThread]
public static void Main()
{
frmMain main = new frmMain();
Application.Run(main);
}
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.txtYear = new System.Windows.Forms.TextBox();
this.btnCheck = new System.Windows.Forms.Button();
this.btnClose = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label1.Location = new System.Drawing.Point(25, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(98, 20);
this.label1.TabIndex = 0;
this.label1.Text = "Year To Test: ";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtYear
//
this.txtYear.Location = new System.Drawing.Point(129, 24);
this.txtYear.Name = "txtYear";
this.txtYear.Size = new System.Drawing.Size(100, 20);
this.txtYear.TabIndex = 1;
//
// btnCheck
//
this.btnCheck.Location = new System.Drawing.Point(25, 93);
this.btnCheck.Name = "btnCheck";
this.btnCheck.Size = new System.Drawing.Size(75, 23);
this.btnCheck.TabIndex = 2;
this.btnCheck.Text = "Leap Year?";
this.btnCheck.UseVisualStyleBackColor = true;
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(154, 93);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(75, 23);
this.btnClose.TabIndex = 3;
this.btnClose.Text = "&Close";
this.btnClose.UseVisualStyleBackColor = true;
//
// frmMain
//
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.btnCheck);
this.Controls.Add(this.txtYear);
this.Controls.Add(this.label1);
this.Name = "frmMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Determain a Leap Year";
this.Load += new System.EventHandler(this.frmMain_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
private void frmMain_Load(object sender, EventArgs e)
{
}
}
I also have a habit that i delete program.cs and frmMain.Designer.cs because i dont need them in my program , Does that have anything to do with my problem ? Help Please!
In frmMain() you're calling InitializeComonent() (which is empty) instead of calling InitializeComponent(). Probably just a typo.
Your code is fine. Just a small typo
public frmMain()
{
// In your constructor change 'IntitializeComonent' to 'InitializeComponent'
IntitializeComonent();
}

Categories

Resources