Jump to content

How to programmatically write text in a textbox


guix

Recommended Posts

Hello,

 

When I load a custom file, I parse it and get a string from it. Then I would like this string to appear in a textbox in the Save dialog... but no matter what I try, it doesn't work: I read the string from the file successfully, I can set the Title of the textbox, but not it's Value :S

 

private enum PropertyNames
{
    TextBox_ArrayName,
}
string arrayName = "array_name";
 
public override PropertyCollection OnCreateSavePropertyCollection()
{
    List<Property> props = new List<Property>
    {
        new StringProperty(PropertyNames.TextBox_ArrayName, "array_name")
    };
 
    return new PropertyCollection(props);
}
 
public override ControlInfo OnCreateSaveConfigUI(PropertyCollection props)
{
    ControlInfo configUI = CreateDefaultSaveConfigUI(props);
    configUI.SetPropertyControlValue(PropertyNames.​TextBox_ArrayName, ControlInfoPropertyNames.DisplayName, "Give a name to the array:");
            
    // I can do that to confirm that arrayName is successfully read from the the file:
    //configUI.SetPropertyControlValue(PropertyNames.​TextBox_ArrayName, ControlInfoPropertyNames.DisplayName, arrayName);
 
    //Doesn't work
    //PropertyControlInfo pci = configUI.FindControlForPropertyName(PropertyNames.​TextBox_ArrayName);
    //pci.Property.Value = arrayName;
 
    //Doesn't work
    //props[PropertyNames.​TextBox_ArrayName].Value = arrayName;
 
    return configUI;
}
 
protected override Document OnLoad(Stream input)
{
    ...
    arrayName = "name_from_file";
    ...
}
 
protected override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
{
    ...
    arrayName = (string)token.GetProperty(PropertyNames.​TextBox_ArrayName).Value;
    ...
}

 

 

 

I have tried other things but no luck... What did I do wrong?

Edited by guix
Link to comment
Share on other sites

You have to know how PropertyBased is working.

If a dialog opens then it will show the values of the last saved token.

 

There is a difference between PropertyBasedEffects and PropertyBasedFiletypes.

The token of a FileType survives a restart of Paint.NET but an Effect token does not.

 

I forgot to mention that there is an issue which I would call a bug.

Cancel of a PropertyBasedFileType does not reset the token to the values after opening of the dialog.

Edited by midora

midoras signature.gif

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...