English 中文(简体)
将体缩为正文。 形式上的文字财产造成一种新观念
原标题:Assigning a string to a TextBox.Text property on a form causes a NullReferenceException

采用该守则(名单复制为名单监控):

    private void ShowApplicationPropertiesForm() {
        String FullPath = String.Empty; 
        String Title = String.Empty;
        String Description = String.Empty;
        Boolean Legacy = false;
        Boolean Production = false;
        Boolean Beta = false;
        MyCustomListViewItemDescendant lvi = (MyCustomListViewItemDescendant)listApplications.SelectedItems[0];
        FullPath = lvi.ExePath;
        Title = lvi.Text;
        Description = lvi.ToolTipText;

        ApplicationProperties ap = new ApplicationProperties(
            FullPath,
            Title,
            Description,
            Legacy,
            Production,
            Beta);
        ap.Show();
    }


//overloaded form constructor
public ApplicationProperties(String AFullPath, String ATitle, String ADescription, Boolean ALegacy, Boolean AProduction, Boolean ABeta) {
            this.Text = String.Format("{0} Properties", ATitle);
            textBoxFullPath.Text = AFullPath;
            textBoxTitle.Text = ATitle;
            textBoxDescription.Text = ADescription;
            checkBoxLegacy.Checked = ALegacy;
            checkBoxProduction.Checked = AProduction;
            checkBoxBeta.Checked = ABeta;
        }

...I m getting, "System.NullReferenceException was unhandled Message=Object reference not set to an instance of an object."

炸弹穿透:

textBoxFullPath.Text = AFullPath;

文本BoxFull 途径是一种形式的文本箱; 整体健康具有某种有效价值:“Q:什么是青年,什么是青年。

Updated:

部分解决。

这是旧的“自然转让”问题。 通过将任务从建筑商移至Load()活动,它不再有炸弹(下文编码)。

HOWEVER, 现在没有任何东西在运行时展示这种形式?

public partial class ApplicationProperties : Form {
        String _fullPath = String.Empty;
        String _title = String.Empty;
        String _description = String.Empty;
        Boolean legacy = false;
        Boolean production = false;
        Boolean beta = false;

        public ApplicationProperties() {
            InitializeComponent();
        }

        public ApplicationProperties(String AFullPath, String ATitle, String ADescription, Boolean ALegacy, Boolean AProduction, Boolean ABeta) {
            _fullPath = AFullPath;
            _title = ATitle;
            _description = ADescription;
            legacy = ALegacy;
            production = AProduction;
            beta = ABeta;
            this.CenterToScreen();
        }

        private void ApplicationProperties_Load(object sender, EventArgs e) {
            //this.Text = String.Format("{0} Properties", _title);          
            Text = String.Format("{0} Properties", _title);
            textBoxFullPath.Text = _fullPath;
            textBoxTitle.Text = _title;
            textBoxDescription.Text = _description;
            checkBoxLegacy.Checked = legacy;
            checkBoxProduction.Checked = production;
            checkBoxBeta.Checked = beta;
        }

更新:

向超负荷的建筑商添加“InitializeComponent();”是骗局的。 页: 1

最佳回答

我认为,设计者总是叫作无尽的建筑商,因此,我感到gra惜,不要试图使我自己的建筑为温Form。

下面请见我的建议——如果你不去到你想要的地方,请让我知道,我还要更新。

    public ApplicationProperties(String AFullPath, String ATitle, String ADescription, Boolean ALegacy, Boolean AProduction, Boolean ABeta)
        : this() // --> Call the parameterless constructor before executing this code
    { 
        _fullPath = AFullPath; 
        _title = ATitle; 
        _description = ADescription; 
        legacy = ALegacy; 
        production = AProduction; 
        beta = ABeta; 
        this.CenterToScreen(); // --> Maybe move this to the Shown event (not sure if you need to)
    } 
问题回答




相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.