从C#中的另一个表单调用ComboBox [英] Call ComboBox from another form in C#

查看:61
本文介绍了从C#中的另一个表单调用ComboBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个表单 - Form1和Form2,Form1有ComboBox,Form2属性有FormBorderStyle作为FixedToolWindow。我需要从Form2调用ComboBox,我该怎么办?

I have 2 forms - Form1 and Form2, Form1 have ComboBox, Form2 property has FormBorderStyle as FixedToolWindow. I need to call ComboBox from Form2, how do I?

推荐答案

如果要访问其他页面中的控件属性,可以使用跨页面发布。有关详细信息,请查看以下链接。

ASP.NET中的回发和跨页面发布 [ ^ ]
If you want to access the control properties in other page you can use cross page posting. For more details check the following link.
Postback and Cross Page Posting in ASP.NET [^]


只需从form1创建一个对象,然后就可以访问ComboBox

form1()form1_Obj = new Form1();

form1_Obj.ComboBox1.SelectedValue = 1;
just create an object from form1 then you can access the ComboBox
form1() form1_Obj = new Form1();
form1_Obj.ComboBox1.SelectedValue= 1;


表单1

Form 1
{
    public Form1()
    {
        ...
    }
    
    public GetCmbBox
    {
        get { return cmbBox; }
        set {cmbBox = value; } 
        }
    }
    
    Button_Click(... ...)
    {
        new Form2(this).Show();
    }
}



表格2


Form 2

{
    Form1 f;
    
    public Form2(Form1 f)
    {
        this.f = f;
        lbl.Text = f.GetCmbBox.SelectedValue.ToString();
    }
}



-KR


-KR


这篇关于从C#中的另一个表单调用ComboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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