如何修复"交通不便,由于其保护级别"在winform错误? [英] How to fix "inaccessible due to its protection level" error in winform?

查看:112
本文介绍了如何修复"交通不便,由于其保护级别"在winform错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Form类

    partial class ProgressMainForm : Form
    {
      public ProgressMainForm()
      {
        InitializeComponent();
      }
    }

和然后使用该类并且包含所有的功能为用户类

And then a class that uses that class and contains all functionality for the user

    public class ProgressForm
    {
        public ProgressMainForm myProgressForm;

        public ProgressForm(string title)
        {
            myProgressForm = new ProgressMainForm();
            myProgressForm.Text = title;
        }

        public void SetProgressBar(int min, int max)
        {
        ....
    }

然后我用这个ProgressForm类在我的项目是这样

I then use this ProgressForm class in my project like this

            progresswindow = new ProgressForm("Replacing All Strings");

这样 progresswindow 只包含成员,都涉及到的功能 ProgressForm 和所有形式的成员是对用户隐藏了。

This way progresswindow only contains members that are related to the functionality of the ProgressForm and all those Form members are hidden from the user.

但有时我需要访问这些表的成员,例如,当我需要调用方法。

But sometimes I need to access those Form members, for example when I need Invoke method.

有没有一种方法,使 myProgressForm ProgressForm 访问的用户不作 ProgressMainForm 公开?

Is there a way to make myProgressForm in ProgressForm accessible to users without making ProgressMainForm public?

或者是这种做法不对?

推荐答案

在我看来,你不应该直接形式的合作。如果我正确读取您的设置,要显示进度指示器,而有些工作正在做。 ProgressForm应公开方法来设置柜台,增加他们。当你在另一个线程中运行它,形式的操控应该从内ProgressForm的方法进行。您调用属于那里,包裹在合适的方法。如果你想改变ProgressMainForm一些视觉特性传递这些属性来ProgressForm。

In my opinion you should not work with the form directly. If I read your setup correctly, you want to show progress indicator while some job is being done. ProgressForm should expose methods to set the counters and increment them; as you run it on another thread, form manipulation should be done from inside the methods of ProgressForm. Your Invokes belong there, wrapped in suitable methods. If you want to change some visual properties of ProgressMainForm relay those properties to ProgressForm.

要恢复,调用code应该没有什么线索ProgressForm不超过设定的进展界限,启动整定电流百分比和停止等。这样,如果你被要求端口的应用程序到另一个UI系统的code,你将需要改变量将大幅度减少。

To resume, calling code should have no clue what ProgressForm does other than setting progress boundaries, starting, setting current percentage and stopping. This way, if you are asked to port the application to another UI system the amount of code you will need to change will be drastically reduced.

这篇关于如何修复"交通不便,由于其保护级别"在winform错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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