StrataFrame Forum

Registry Repository

http://forum.strataframe.net/Topic1771.aspx

By Ricardo Quartier - 7/7/2006

Hi friends, can u explain how to use that control?

Thanks...   BigGrin

By StrataFrame Team - 7/8/2006

Yep, Ricardo,

Start by dropping an instance onto a form.  It should appear down at the bottom in the "components" region of the form. 

Then, simply set the RegistryKey property on it.  This needs to be the full path to the registry key like this: "HKEY_LOCAL_MACHINE\Software\Ricardo"

Then, use the methods on the component to get/set the values within that registry key.  It essentially allows to create/read registry values with a single line of code rather than having to use the objects within the Microsoft.Win32 namespace.

By Ricardo Quartier - 7/10/2006

Thanks Ben, I will try...
By Ricardo Quartier - 11/10/2006

Yo friends after work i get to this:

On the form I found a property called RegistryRepositoryKey

I put this value HKEY_LOCAL_MACHINE\SOFTWARE\teste

Then i went to the register and create that key "teste" (test for u texan people) Smile

I put that on the form_load method:

Me.Width = RegistryRepository1.ReadInt32((Me.RegistryRepositoryKey), "form1_width", 5)

Then, 5 new values appear: SF_FormHeight, SF_FormState, SF_FormWidth, SF_FormX, SF_FormY and the best is that it works, after running the solution and moves the form to a diferent place on a screen, it saves diferent values, and after running again, the form starts in the previous position.

So far, so good, all okidoki, but that makes me thought.. I need to create a key for every form. If the aplication is going to run on my machine only.. ok.. but.. it's not.. so after all that here comes the question:

Is that a way, maybe inside a "if ... then" code to check if the key already exists? if not:

let the form auto create the key, maybe with HKEY_LOCAL_MACHINE\SOFTWARE\teste\My Form Name or Text ?

if this is easy to write? Please post here, if not forget, i do not want to take your time...

Thanks.

 

 

By Ricardo Quartier - 11/10/2006

In fact i saw theres no need of this line on the form load...

Me.Width = RegistryRepository1.ReadInt32((Me.RegistryRepositoryKey), "form1_width", 5)

And setting the property on the form of the key, creates the values.. but the other question still persist... BigGrin

By Ricardo Quartier - 11/10/2006

Yo, another thing i created more 2 forms and insert this code to open the form, on the load of the first form:

Form3.Show()

Form4.Show()

I created the keys in the register too.

But only the form1 saves the new values to the form. If i change the startup form on the AppMain to form3 then it saves the values to the register. What is wrong? w00t

By Ricardo Quartier - 11/10/2006

But only the form1 saves the new values to the form. If i change the startup form on the AppMain to form3 then it saves the values to the register. What is wrong?

Saves the form3 values not the other form's values, I forgot to write..

By Trent L. Taylor - 11/11/2006

Hey Ricardo...here is how it works:

When you set the RegistryRepositoryKey on a form it will update based on three other properties:

RememberFormLocation
RememberFormMaximizedState
RememberFormSize

If you have all of this set, then you will see a total of 5 registry values added to the registry key you provide.

Since this is automated, you will have to provide a unique registry key for each form whose position, size, etc. you want remembered.  If you want to automate the registry key, you could write a shared class method that dynamically sets this property.  For example:

Me.RegistryRepositoryKey = GenerateRegistryKeyValue(Me.Name)

or maybe something like this:

Me.RegistryRepositoryKey = "HKEY_LOCAL_MACHINE\SOFTWARE\teste\" & Me.Name

By Ivan George Borges - 11/11/2006

Hi Trent.

We created a class with a shared function and then we are calling it passing the form name ...

It works great. All the forms have a good memory now ... I wish we did too. Tongue

One thing, we noticed that if it is not an MDI application, and the main form calls some other not modal forms, if the main is closed, the others all get closed but the registry is not saved.

Thanks.

By StrataFrame Team - 11/12/2006

This is most likely because the called forms are not raising their Closing event (the code to save the values to the registry is in the OnFormClosing method).  I'll check into this, but if the event is not being raised, we might not be able to fin another place to attach the code.
By Ivan George Borges - 11/13/2006

Hi Ben.

Yeah, I thought of that.

By the way, I looked for a BeforeClose hook, and couldn't find one. And in the case the OnClosing not being fired, would the Save before closing work and things like that work?

By StrataFrame Team - 11/13/2006

That is a very good point, Ivan... I believe the question to ask if you want to save your changes is being fired from within the OnFormClosing as well...