如何从另一种形式设置Probity [英] How Can Set Probity from another form

查看:90
本文介绍了如何从另一种形式设置Probity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if(radioButton1.Checked == true && textBox1.Text.ToString()==read)

{

this.Hide();

Form1 fm = new Form1();



fm.ShowDialog();

------ - fm.pictureBox31.Visible = false;



}





pictureBox31中没有任何事情发生

解决方案

只需在新表单中创建一个属性,为您完成:



  public   class  Form1:Form 
{
...
< span class =code-keyword> public bool ShowImage
{
get {返回 pictureBox31.Visible; }
set {pictureBox31.Visible = value ; }
}
...
}

并在调用ShowDialog之前设置它的值:

 Form1 fm =  new  Form1(); 
fm.ShowImage = false ;
fm.ShowDialog();



如果使用ShowDialog,那么在表单关闭之前调用不会返回,因此必须设置它的属性在显示表单之前完成。



你可以使用Show代替,但是你需要添加一个FormClosed事件处理程序来检测用户何时关闭它,以及要么重新显示旧表单,要么关闭应用程序。



BTW:帮自己一个忙,并停止使用Visual Studio默认名称 - 你可能还记得TextBox8是今天的手机号码,但是当你需要修改它的时候是三周时间,那你呢?使用描述性名称 - 例如tbMobileNo - 您的代码变得更容易阅读,更自我记录,更易于维护 - 并且编码速度更快,因为Intellisense可以通过三次击键来tbMobile,其中TextBox8需要思考大约和8次击键...


你好,

如果你想隐藏图片框,那么在Form1_Load事件中编写该代码,而不是当前形式。

if (radioButton1.Checked == true && textBox1.Text.ToString() == "read")
{
this.Hide();
Form1 fm = new Form1();

fm.ShowDialog();
------- fm.pictureBox31.Visible = false;

}


Nothing happen in pictureBox31

解决方案

Just create a property in the new form which does that for you:

public class Form1: Form
   {
   ...
   public bool ShowImage
      {
      get { return pictureBox31.Visible; }
      set { pictureBox31.Visible = value; }
      }
   ...
   }

And set it's value before the call to ShowDialog:

Form1 fm = new Form1();
fm.ShowImage = false;
fm.ShowDialog();


If you use ShowDialog, then the call does not return until the form is closed, so the setting of it's properties must be done before you display the form.

You could use Show instead, but then you'd want to add a FormClosed event handler to detect when the user closes it, and either re-display your old form, or close the application.

BTW: Do yourself a favour, and stop using Visual Studio default names for everything - you may remember that "TextBox8" is the mobile number today, but when you have to modify it is three weeks time, will you then? Use descriptive names - "tbMobileNo" for example - and your code becomes easier to read, more self documenting, easier to maintain - and surprisingly quicker to code because Intellisense can get to to "tbMobile" in three keystrokes, where "TextBox8" takes thinking about and 8 keystrokes...


Hello ,
If you want to hide the picture box then write that code in Form1_Load event , not in current form .


这篇关于如何从另一种形式设置Probity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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