公共变量调用不正确的结果 [英] Public variable invoking incorrect result

查看:88
本文介绍了公共变量调用不正确的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public   partial   class  ThanglishToTamilGUI:表格
{
public string anz;

public ThanglishToTamilGUI()
{
InitializeComponent();
}

public void btnConvertToBraille_Click( object sender,EventArgs e)
{
anz = richTextBoxTamil.Text.ToString();

GUI.TamilToBrailleGUI c1 = new GUI.TamilToBrailleGUI();
c1.Visible = true ;
}

}



我需要将我的richtextbox(richTextBoxTamil)内容传递给变量调用anz。

我以其他形式重新启动anz变量作为表单加载事件:

  private   void  TamilToBrailleGUI_Load( object  sender,EventArgs e)
{
ThanglishToTamilGUI tt = new ThanglishToTamilGUI();
String apper = tt.anz;
richTextBoxTamil.Text = apper;
}



我的问题:我得到的是空值。因为我分配了任何正确调用的值。

  public   partial   class  ThanglishToTamilGUI:表格
{
public string anz = Hai;

public ThanglishToTamilGUI()
{
InitializeComponent();
} ...



这里我的ans值传递为Hai。但我的要求是获取richTextBoxTamil中的内容并将其传递给该公共变量调用anz。这里出了什么问题请帮帮我。



谢谢。

解决方案

尝试更改为静态变量



 public string anz; 



as

 public static string anz; 


你会的。线索在 new

 ThanglishToTamilGUI tt = 新的 ThanglishToTamilGUI(); 
String apper = tt.anz;



由于您创建了一个新实例,它将没有用户输入其他实例的值!



尝试使用当前值!看看这个:在两个表格之间传递信息,第1部分:家长给孩子 [ ^ ]

(可能你需要系列中的其他提示之一 - 我看不到你的代码所以我无法告诉)


public partial class ThanglishToTamilGUI : Form
{
    public string anz;

    public ThanglishToTamilGUI()
    {
        InitializeComponent();
    }

    public void btnConvertToBraille_Click(object sender, EventArgs e)
    {
        anz = richTextBoxTamil.Text.ToString();

        GUI.TamilToBrailleGUI c1 = new GUI.TamilToBrailleGUI();
        c1.Visible = true;
    }

}


I need to pass my richtextbox (richTextBoxTamil) content to variable call anz.
I am retrriving anz variable in other form as form load event:

private void TamilToBrailleGUI_Load(object sender, EventArgs e)
    {
        ThanglishToTamilGUI tt = new ThanglishToTamilGUI();
        String apper = tt.anz;
        richTextBoxTamil.Text = apper;
    }


My Problem: I am getting null values as result. Since if I assigned any values that invoked correctly.

public partial class ThanglishToTamilGUI : Form
{
    public string anz = "Hai";

    public ThanglishToTamilGUI()
    {
        InitializeComponent();
    } ...


Here my ans value is passed as "Hai". But my requirement is to get what ever the content in the richTextBoxTamil and pass it to that public variable call anz. What went wrong here please help me.

Thank you.

解决方案

Try by changing to static variable

public string anz;


as

public static string anz;


You will. The clue is in the word new:

ThanglishToTamilGUI tt = new ThanglishToTamilGUI();
String apper = tt.anz;


Since you create a new instance, it will not have the values that the user entered into a different instance!

Try just using the current value! Have a look at this: Transferring information between two forms, Part 1: Parent to Child[^]
(It may be you need one of the other tips in the series - I can''t see your code so I can''t tell)


这篇关于公共变量调用不正确的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆