在Windows中传递值,C# [英] Passing values in windows,c#

查看:69
本文介绍了在Windows中传递值,C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我必须将日期从登录表单传递给所有表单.它不应显示在表单上.有什么方法可以将值传递给C#,Windows应用程序中的所有表单?

解决方案

这是有关表单协作的常见问题.最健壮的解决方案是在Form类中实现适当的接口,并传递接口引用而不是对Form的整个实例"的引用.请查看我过去的解决方案以获取更多详细信息:如何以两种形式在列表框之间复制所有项目 [如何以两种形式复制列表框之间的所有项目 [ 公共 静态 DateTime日期 { 获取设置; }


在表单之间传递数据 [ ^ ]

Hi,

I have to pass a date to all forms from the login form. It shouldn''t display on a form. any method to pass the value to all forms in c#, windows application?

解决方案

This is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class and passing the interface reference instead of reference to a "whole instance" of a Form. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

Please see other answers to this question: How to copy all the items between listboxes in two forms[^].

Even though I think that my solution is the most comprehensive, you may prefer somewhat simpler ones, which could be adequate for simpler projects.

—SA


If you want to pass the value to all form better add one static property at your program.cs

In Program.cs

public static DateTime date
{
    get;
    set;
}


Passing Data Between Forms[^]


这篇关于在Windows中传递值,C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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