English 中文(简体)
准入形式变量
原标题:Access form variables

When using a basic form application in C# I am having trouble accessing the variabels within it.

因此,原为第一类。

public partial class pingerform : Form 
{
  ..
  ..

  private System.Windows.Forms.TextBox textBox2;

  public string textBox2Text
  {
      get { return textBox2.Text; }
      set { textBox2.Text = value; }
  }

之后,在主要应用中,我已经提出过。

Application.Run(new pingerform());
...
...

pingerform.textBox2Text.text() = str;

但我被告知,没有反对意见。

Error 1
An object reference is required for the non-static field, method, or property pingerform.textBox2Text.get C:Usersaaron.streetDocumentsVisual Studio 11ProjectsPingDropPingDropProgram.cs 54 21 PingDrop

因此,我认为,我会把歌唱成静态,但我会胜过吗?

Error 1
Cannot create an instance of the static class PingDrop.pingerform C:Usersaaron.streetDocumentsVisual Studio 11ProjectsPingDropPingDropProgram.cs 21 29 PingDrop

我如何利用这些财产的形式,具体介绍形式,

我的背景已经成熟,我想定期更新以表格形式定期提交的文本?

卡车

页: 1

最佳回答

你们别无选择,只能创造新的榜样,或者把它作为直线通过,或是将其储存在你的主要方案类别中。

第二种选择的实例:

private static pingerform myPingerform = null;
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    myPingerform = new pingerform();
    Thread thread = new Thread(new ThreadStart(UpdateTextBox));
    thread.Start();
    Application.Run(myPingerform);
}

private static void UpdateTextBox()
{
    while (true)
    {
        myPingerform.textBox2.Text = DateTime.Now.Ticks.ToString();
        Thread.Sleep(1000);
    }
}

不要忘记将案文箱改为public

<说明>:这是简单可行的办法,可以解决一个背景阅读文本箱的简单案例。 如果你们有了更多的通道,就会打破。 最佳做法方法要求开展更多工作,请read this

问题回答

不能在不设立案件的情况下获得案件财产,而是非专利(或同等的VB)。 并且你已经创立了你随后通过<代码>Application.Run(的例子。 不管怎么说,你都无法在<条码>后填写表格。 如果你想与你在其他地方需要做些什么。 当然,由于你需要制造一些事例,你不能使表格的等级固定不变。

如果你需要以另一种形式做事的话,那么,你在创建时,就应该把形式通过到深处。 请注意,与来自非古董校对面的通用公平观要素直接挂钩是一种坏的想法,但你应使用<编码>Control.BeginInvoke()。

请尝试:

pingerform myForm = new pingerform();    
Application.Run(myForm);
myForm.textBox2Text = "this is text";




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签