I’m trying to create my own error window for the project I am working on. When I show my error window I have no way to pass the error message, and user message to the Error window because the ‘ErrorMessage.Text’ cannot be seen in the classes I make.
I went into the form designer generated code and tried to make the TextBox static, but that just breaks things. Can I make a TextBox public / static so I can change it from another form?
- How do I make a TextBox Static Public so I can manipulate it across other forms, or is there another method for doing this?
EDIT:
Okay, for more information…
I have my own Form created. It is called ‘formErrorWindow.’ I need to display the form that i’ve pre-designed with the message set from another form. The only way I can do this is if I create a Function in the windows designer area for the form, and I set the variables with ‘this.errorMsg.text = error.’ The only way I can see that function is if I set it to static. If I set the function to Static, when I try and put ‘this.errorMsg.Text = error’ I get this error: An object reference is required for the non-static field, method, or property.
Here is what I’ve attempted:
namespace LCR_ShepherdStaffupdater_1._0 { partial class formErrorWindow { /// <summary> /// Required designer variable. /// </summary> public 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> // ********* HERE IS THE FUNCTION THAT IVE ADDED BELOW. THIS WOULD WORK BUT.... ********* public static void showError(string errorTitle, string usrMsg, string errorMsg) { formErrorWindow errorWindow = new formErrorWindow(); errorMsgItem.Text = errorMsg; errorTitleItem.Text = 'Error! : ' + errorTitle; usrMsgItem.Text = usrMsg; errorWindow.ShowDialog(); } // ********* HERE IS THE FUNCTION THAT IVE ADDED ABOVE. THIS WOULD WORK BUT.... ********* // ********* I get an error: 'An object reference is required for the non-static field, method, or property.' ********* public void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(formErrorWindow)); this.usrMsgItem = new System.Windows.Forms.TextBox(); this.errorTitleItem = new System.Windows.Forms.Label(); this.errorMsgItem = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.panel1 = new System.Windows.Forms.Panel(); this.label2 = new System.Windows.Forms.Label(); this.panel1.SuspendLayout(); this.SuspendLayout(); // // usrMsgItem // this.usrMsgItem.Enabled = false; this.usrMsgItem.Location = new System.Drawing.Point(13, 37); this.usrMsgItem.Multiline = true; this.usrMsgItem.Name = 'usrMsgItem'; this.usrMsgItem.Size = new System.Drawing.Size(334, 81); this.usrMsgItem.TabIndex = 0; this.usrMsgItem.Text = 'Undefined'; // // errorTitleItem // this.errorTitleItem.AutoSize = true; this.errorTitleItem.Font = new System.Drawing.Font('Microsoft Sans Serif', 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.errorTitleItem.ForeColor = System.Drawing.Color.Red; this.errorTitleItem.Location = new System.Drawing.Point(12, 9); this.errorTitleItem.Name = 'errorTitleItem'; this.errorTitleItem.Size = new System.Drawing.Size(152, 20); this.errorTitleItem.TabIndex = 1; this.errorTitleItem.Text = 'Error! : Undefined'; // // errorMsgItem // this.errorMsgItem.Enabled = false; this.errorMsgItem.Location = new System.Drawing.Point(0, 21); this.errorMsgItem.Multiline = true; this.errorMsgItem.Name = 'errorMsgItem'; this.errorMsgItem.Size = new System.Drawing.Size(329, 101); this.errorMsgItem.TabIndex = 2; this.errorMsgItem.Text = 'Undefined'; // // button1 // this.button1.Location = new System.Drawing.Point(272, 256); this.button1.Name = 'button1'; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 3; this.button1.Text = 'Continue'; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // panel1 // this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128))))); this.panel1.Controls.Add(this.label2); this.panel1.Controls.Add(this.errorMsgItem); this.panel1.Location = new System.Drawing.Point(12, 124); this.panel1.Name = 'panel1'; this.panel1.Size = new System.Drawing.Size(335, 126); this.panel1.TabIndex = 4; // // label2 // this.label2.AutoSize = true; this.label2.Font = new System.Drawing.Font('Microsoft Sans Serif', 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label2.Location = new System.Drawing.Point(68, 1); this.label2.Name = 'label2'; this.label2.Size = new System.Drawing.Size(189, 17); this.label2.TabIndex = 3; this.label2.Text = 'Technical Error Message'; // // formErrorWindow // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192))))); this.ClientSize = new System.Drawing.Size(359, 290); this.Controls.Add(this.panel1); this.Controls.Add(this.button1); this.Controls.Add(this.errorTitleItem); this.Controls.Add(this.usrMsgItem); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; this.Icon = ((System.Drawing.Icon)(resources.GetObject('$this.Icon'))); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = 'formErrorWindow'; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = 'Error!'; this.VisibleChanged += new System.EventHandler(this.formErrorWindow_VisibleChanged); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Button button1; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Label label2; public System.Windows.Forms.TextBox usrMsgItem; public System.Windows.Forms.Label errorTitleItem; public System.Windows.Forms.TextBox errorMsgItem; } }
Look for the function I’ve added above. How do I get that to compile and do what I want it to do WITHOUT that error I keep getting: An object reference is required for the non-static field, method, or property.
Yes! have a function made public that can receive this text:
and have the function update the textbox from there.
don’t mix UI with logic.