Hi Tony
Firstly, if you change
Application.Run(new FormUserInfo());
to
Application.Run(FUI);
your program should work.
This is because you are creating an instance of FormUserInfo and setting
the data on it but then showing a new instance that has not had the data
set.
BUT..
You have not got a very good design there.
I would suggest that you move your entry point into FormUserInfo and
then in the load event of your form, create an instance of your
avdetails class and use the methods to load itself.
PSEUDOCODE
public class frmMain : sys.win.forms.form
{
...........
this.load =+ new eventhandler(this.load);
private void load(obj sender, eventargs e)
{
AVDETAILS avd = new AVDETAILS();
this.txtAppVersion.text = avd.getAppVersion();
}
}
Do you know how to use events?
It is better for a form / class to use other classes to load itself than
to rely on them to load it. This allows for easier reuse of the class.
Please see my inline comments.
HTH
JB
Im a Starship Trooper
This is my letter to dad
Transferred from Saigon to Baghdad
And now Im dead --Ozi Batla, Starship Trooper
Tony W wrote:
Hi,
Thanks for replying to my post. I'm still unsure where I am going wrong so have taken the liberty of posting an edited version of my code below. I
have removed code relating to other controls and registry entries as well as comments etc.
As you can see I have a class called FormUserInfo that handles form creation and changes. I have another class for getting registry data and
manipulating it prior to displaying via the form form the first class.
The settboAppVer method appears to work as the passed string value displays correctly prior to the control property change and the control text value
reflects the new value after changing the value.
The only problem I have is showing the changes on screen.
Once again any advice will be most welcome, I've searched the web and can't find an answer to this anywhere.
Thanks again,
Tony W
// code starts here~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Text;
namespace AVMonitor
{
public class FormUserInfo : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox tboAppVer;
public FormUserInfo()
{
InitializeComponent();
}
private void InitializeComponent() {
this.tboAppVer = new System.Windows.Forms.TextBox();
this.SuspendLayout();
// tboAppVer
this.tboAppVer.BackColor = System.Drawing.SystemColors.Control;
this.tboAppVer.Location = new System.Drawing.Point(128, 184);
this.tboAppVer.Name = "tboAppVer";
this.tboAppVer.ReadOnly = true;
this.tboAppVer.TabIndex = 12;
this.tboAppVer.Text = "textBox1";
// FormUserInfo
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(528, 302);
this.Controls.Add(this.tboAppVer);
this.Name = "FormUserInfo";
this.Text = "AVM";
this.ResumeLayout(false);
}
public void settboAppVer(string strAppVer)
{
MessageBox.Show (strAppVer); //displays correct value as passed to method
tboCurrentDatVer.Text = strAppVer;
MessageBox.Show(tboAppVer.Text); //displays correct value as passed to method
}
Should not need to expose public method like this.
}
public class AVDetails
{
//? ATTRIBUTES
Not attributes but fields or private / member variables.
Fields are public varaibles
Private variables are private and not accessible through a property.
Member variables are private but are accessible through property accessors.
string strAppVersion;
What is this for?
is it public / private, do you want outside classes to be able to 'see'
this?
You can wrap this in a region such as
#region Member Variables
private int m_MyID;
#endregion
#region Properties
public int MyID
{
get
{
return m_MyID;
}
set
{
m_MyID = value;
}
#endregion
//?METHODS
public string getAppVersion()
{
//? get the Application version
AVDetails AVD = new AVDetails();
You do not need to create an instance here as you already have an
instance (this).
strAppVersion = this.getRegistryEntry("<Registry path>",
"Version").ToString();
or
strAppVersion = getRegistryEntry("<Registry path>", "Version").ToString(); strAppVersion = AVD.getRegistryEntry("<Registry path>", "Version").ToString();
return strAppVersion;
}
public object getRegistryEntry(string strKeyName, string strKeyElement)
{
//? read the registry
RegistryKey pRegKey = Registry.LocalMachine;
pRegKey = pRegKey.OpenSubKey(strKeyName);
Object strKeyValue = pRegKey.GetValue(strKeyElement);
return strKeyValue;
}
public static void Main()
{
string strAppVer;
AVMonitor.AVDetails AVD = new AVDetails();
AVMonitor.FormUserInfo FUI = new FormUserInfo();
//? get the AppVer
strAppVer = AVD.getAppVer();
//? apply values to form
FUI. settboAppVer (strAppVer);
Application.Run(new FormUserInfo());
You are creating a new instance that has no relation to FUI, the one you
have previously loaded.
}
}
}