Thank you for replying to my post, below is the content of the program.cs
file:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace MPLLoginscreen
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Commented out the Application.Run line 'cause I couldn't see a
way
//to use the text property of textbox1 or call a Form1 method
//Application.Run(new Form1());
Form1 frmNew = new Form1();
Application.Run(frmNew);
frmNew.displaytext();
}
}
}
and here is the content of the Form1.cs file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MPLLoginscreen
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void displaytext()
{
textBox1.Text = "test";
}
}
}
Basically when the application runs I want the text 'test' to be displayed
in the textbox.
Thank you for your help.
Jon Skeet said:
Femi said:
I'm trying to programmatically add text to textbox control to no avail.
I created a method under form1{
public void DisplayText(){
textbox1.text = "Test";
}
In the main method in program.cs I created a new instance of form1
frmNew. I
then call the displaytext method [frmnew.DisplayText();] however no text
is
displayed.
Can anyone point me in the right direction?
Could you post a short but complete program which demonstrates the
problem?
See
http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
You need to actually *show* the form (e.g. with Application.Run) - it's
not clear whether or not that's the problem though.