C#从主窗体到控制页面获取标签值

C#从主窗体到控制页面获取标签值

本文介绍了C#从主窗体到控制页面获取标签值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个主表单,我有选项卡控件和标签页,内部标签页我使用了用户控件。在Main表单中我有datetime.Text(Label),我想调用/获取它的值到标签页(这是用户控件)告诉我如何使datetime.Text全局,这样我就可以获得值它的。谢谢,抱歉我的英文不好 这里是图片,请复制并粘贴链接到浏览器查看图片 tinypic.com/ view.php?pic = 2w20yg4& s = 9Hi, i have one Main form, and i have tab control and tab pages, Inside tab pages i used User Control. In Main form I have datetime.Text(Label), and i wanted to call/get value of it to tab page (which is the user control) tell me how to make the datetime.Text global, so that i can get the value of it. Thanks , sorry for my bad englishhere's the pic, Please copy and paste the link to browser to view the image tinypic.com/view.php?pic=2w20yg4&s=9推荐答案public static class CommonInfo{ private static string _DateTimeInfo = string.Empty; public static string DateTimeInfo { get { return _DateTimeInfo; } set { _DateTimeInfo = Value; } }} 现在,您可以从项目内的任何位置存储和访问DateTimeInfo的信息。加载主窗体时,将DateTime信息分配给 CommonInfo.DateTimeInfo 属性。在Main表单的Load事件中分配这样的DateTime信息,Now you can store and access information to DateTimeInfo from anywhere inside your project. Assign the DateTime information to CommonInfo.DateTimeInfo property when you load the main form. In the Load event of Main form assign DateTime information like this,CommonInfo.DateTimeInfo = your expression; 现在,您可以从标签页中获取此信息。为此,只需使用 CommonInfo.DateTimeInfo 。 这篇关于C#从主窗体到控制页面获取标签值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-07 09:25