using System; using System.Collections.Generic; using System.Linq; using System.
ID: 3786378 • Letter: U
Question
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
namespace Assignment8a
{
class Program : Form
{
Button btnClickME = new Button();
TextBox textMessage = new TextBox();
Button btnExit = new Button();
Button button1 = new Button();
Label label1 = new Label();
// Button btnClickME_Click = new Button();
public Program()
{
this.btnClickMe = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnClickMe
//
this.btnClickMe.Location = new System.Drawing.Point(15, 20);
this.btnClickMe.Name = "btnClickMe";
this.btnClickMe.Size = new System.Drawing.Size(75, 23);
this.btnClickMe.TabIndex = 0;
this.btnClickMe.Text = "Press Me";
this.btnClickMe.UseVisualStyleBackColor = true;
this.btnClickMe.Click += new System.EventHandler(this.btnClickMe_Click);
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(15, 60);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(75, 23);
this.btnExit.TabIndex = 1;
this.btnExit.Text = "Exit";
this.btnExit.UseVisualStyleBackColor = true;
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 111);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnClickMe);
this.Name = "Form1";
this.Text = "Assignment8";
this.ResumeLayout(false);
//
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.DialogResult = System.Windows.Forms.DialogResult.Abort;
this.button1.Location = new System.Drawing.Point(188, 70);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "OK";
this.button1.UseVisualStyleBackColor = true;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(58, 27);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(151, 13);
this.label1.TabIndex = 1;
this.label1.Text = " The Button Has Been Clicked";
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 111);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "Form2";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "CLICKME";
this.ResumeLayout(false);
this.PerformLayout();
}
protected void btnClickMe_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.ShowDialog();
if (f2.DialogResult == DialogResult.Abort)
{
//do this
}
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Dispose();
}
static void Main(string[] args)
{
Application.Run(new Program());
}
}
}
not compliling correctly help please language is C#
Explanation / Answer
The error is coming due to using System.Windows.Forms namespace added directly.
A console application does not automatically add a reference to System.Windows.Forms.dll.
Right-click your project in Solution Explorer and select Add reference and then find System.Windows.Forms and add it.
Right click on "Reference" "Add New Reference" "System.Windows.Forms"
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.