A
anthony
I am new to C# programming and have a simple question for the group
here. I'll just display my code and Warning message.
-------------------------------------------------------------------------------------
//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;
using System.Runtime.InteropServices;
namespace NewForm
{
public partial class Form1 : Form {
[DllImport("ole32.dll")]
static extern void CoFreeUnusedLibraries();
private System.Windows.Forms.ComboBox comboBox1;
public Form1() {
InitializeComponent();
}
public void DisplayMessage() {
MessageBox.Show("test");
}
}
}
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
//Form1.Designer.cs
namespace NewForm
{
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.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Font;
this.Text = "Form1";
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.comboBox1.SuspendLayout();
this.SuspendLayout();
//
// comboBox1
this.comboBox1.Anchor =
((System.Windows.Forms.AnchorStyles.Bottom
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.comboBox1.DropDownWidth = 280;
this.comboBox1.Location = new System.Drawing.Point(21,
20);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(284, 21);
this.comboBox1.TabIndex = 0;
this.comboBox1.BackColor = System.Drawing.Color.White;
// Form1
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.DodgerBlue;
this.ClientSize = new System.Drawing.Size(338, 67);
this.Controls.Add(this.comboBox1);
this.Name = "Form1";
this.Text = "ComboBox";
this.DisplayMessage(); // WARNING
ASSOCIATED WITH THIS LINE
this.comboBox1.ResumeLayout(false);
this.comboBox1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
}
}
-------------------------------------------------------------------------------------
Warning message: Method 'System.Windows.Forms.Form.DisplayMessage' not
found.
Comment: I know that DisplayMessage is not a method of the Form
object. I am trying to get Form1 class to define a new form in
adddition to those derived from Form. I thought that was what the
following line was doing from Form1.cs:
public partial class Form1 : Form {
Apparently, I do not know how to add additional methods to a class
which was derived from another class. In any event, this is what I
wish to do. Does someone know how to do this? Also, I know that this
method does not have a purpose here. It is going to be substituted
with another method, but I chose to write something smaller and
simpler to generally illustrate the issue I am having. Thanks you for
your assistance in advance.
here. I'll just display my code and Warning message.
-------------------------------------------------------------------------------------
//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;
using System.Runtime.InteropServices;
namespace NewForm
{
public partial class Form1 : Form {
[DllImport("ole32.dll")]
static extern void CoFreeUnusedLibraries();
private System.Windows.Forms.ComboBox comboBox1;
public Form1() {
InitializeComponent();
}
public void DisplayMessage() {
MessageBox.Show("test");
}
}
}
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
//Form1.Designer.cs
namespace NewForm
{
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.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Font;
this.Text = "Form1";
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.comboBox1.SuspendLayout();
this.SuspendLayout();
//
// comboBox1
this.comboBox1.Anchor =
((System.Windows.Forms.AnchorStyles.Bottom
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.comboBox1.DropDownWidth = 280;
this.comboBox1.Location = new System.Drawing.Point(21,
20);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(284, 21);
this.comboBox1.TabIndex = 0;
this.comboBox1.BackColor = System.Drawing.Color.White;
// Form1
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.DodgerBlue;
this.ClientSize = new System.Drawing.Size(338, 67);
this.Controls.Add(this.comboBox1);
this.Name = "Form1";
this.Text = "ComboBox";
this.DisplayMessage(); // WARNING
ASSOCIATED WITH THIS LINE
this.comboBox1.ResumeLayout(false);
this.comboBox1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
}
}
-------------------------------------------------------------------------------------
Warning message: Method 'System.Windows.Forms.Form.DisplayMessage' not
found.
Comment: I know that DisplayMessage is not a method of the Form
object. I am trying to get Form1 class to define a new form in
adddition to those derived from Form. I thought that was what the
following line was doing from Form1.cs:
public partial class Form1 : Form {
Apparently, I do not know how to add additional methods to a class
which was derived from another class. In any event, this is what I
wish to do. Does someone know how to do this? Also, I know that this
method does not have a purpose here. It is going to be substituted
with another method, but I chose to write something smaller and
simpler to generally illustrate the issue I am having. Thanks you for
your assistance in advance.