|
Hi
I have an application which runs a login screen before the main program runs.
The login only succees when the user enters the right credentials.
The login screen is loaded to show as a dialog. When it closes the main class is run which is tha actual application. I need to access a property which I created in the Login screen's class, in the form_load event of the main class.
However I cannot access the variable which is declared in the Program.cs which is used to load the login screen. It keeps telling me : "The name 'frmTheLogin' does not exist in the current context"
Here the Program.cs code :
namespace ChequeApp
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
frmLogin frmTheLogin;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
frmTheLogin = new frmLogin();
if (frmTheLogin.ShowDialog() == DialogResult.OK)
{
Application.Run(new frmChequeApp());
}
}
}
}
Here the Login class code :
namespace ChequeApp
{
public partial class frmLogin : Form
{
private string strUsername; //private variable for username.
IntPtr iptrTheToken;
private Int32 intAccessRight;
//Read-only property for username.
public string Username
{
get
{
return strUsername;
}
}
//Read-only property for the access rights.
public Int32 AccessRight
{
get
{
return intAccessRight;
}
}
...
}
Here the main class code :
namespace ChequeApp
{
public partial class frmChequeApp : Form
{
private string strUsername;
private Int32 intAccessRight;
private System.Windows.Forms.UserControl ctrlChequeApp;
public frmChequeApp()
{
InitializeComponent();
}
private void DisposeControl()
{
if (ctrlChequeApp != null)
{
this.Controls.Remove(ctrlChequeApp);
ctrlChequeApp.Dispose();
ctrlChequeApp = null;
}
}
private void ShowControl()
{
ctrlChequeApp.Location = new Point(1, 1);
this.Controls.Add(ctrlChequeApp);
ctrlChequeApp.BringToFront();
ctrlChequeApp.Dock = DockStyle.Fill;
}
private void frmChequeApp_Load(object sender, EventArgs e)
{
strUsername = frmTheLogin.Username; //IT ERRORS HERE
intAccessRight = frmTheLogin.AccessRight; //IT ERRORS HERE
}
...
}
|
|
|
|
|
Oederu wrote: It keeps telling me : "The name 'frmTheLogin' does not exist in the current context"
You don't understand "scope" and yet your are writing an application which requires logging in.
|
|
|
|
|
frmChecqueApp has no knowledge of frmTheLogin since they are in separate scopes.
You need to make frmChecqueApp aware of the form (and preferably only the data from the form that you want access to).
My suggestion would be to pass in the username and accessright into frmChecqueApp's constructor as follows:
public frmChequeApp(string userName, Int32 accessRight)
{
InitializeComponent();
strUsername = userName;
intAccessRight = accessRight;
}
and then in your Program.cs you would change it to:
namespace ChequeApp
{
static class Program
{
[STAThread]
static void Main()
{
frmLogin frmTheLogin;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
frmTheLogin = new frmLogin();
if (frmTheLogin.ShowDialog() == DialogResult.OK)
{
Application.Run(new frmChequeApp(frmTheLogin.UserName, frmTheLogin.AccessRight));
}
}
}
|
|
|
|
|
Thank You that helped a lot. I thought that all components/variables in the
base class could see each other but that is not so. Now I know. Thanks again.
|
|
|
|
|
Hello,
I am trying to fill a datagridview with a very large file (about 600 000 rows), i keep getting a ("Exception of type 'System.OutOfMemoryException' was thrown.")Error, but I do not see how I could be out of memory. Is there a max amount of rows that a data grid view can hold?
Hope some one can help
J
|
|
|
|
|
jasper018 wrote: but I do not see how I could be out of memory
Just a wild guess but maybe memory is not an infinite resource
Use "virtual mode" see the documentation for details
|
|
|
|
|
Hi,
I am facing a problem while using pepared statement for inserting data in MS-Access db.
<code>private const String CONN_STR = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Temp\\TestDb.mdb";
conDatabase.Open(CONN_STR, "", "", -1);
String sQuery = "INSERT INTO " + sTableName +
" ([FileName],[IsCopied],[Size]) VALUES (@FileName,@IsCopied,@Size)";
cmdPrepStmnt.ActiveConnection = conDatabase;
cmdPrepStmnt.CommandText = sQuery;
cmdPrepStmnt.CommandType = CommandTypeEnum.adCmdText;
cmdPrepStmnt.Prepared = true;
int iCount = 0;
foreach (FileInfo f in fInfo)
{
Console.WriteLine("Adding File " + ++iCount + " of " + fInfo.Length + "; " + f.Name);
Parameter p1 = cmdPrepStmnt.CreateParameter("@FileName", ADODB.DataTypeEnum.adVarWChar, ParameterDirectionEnum.adParamInput, 255, f.FullName);
Parameter p3 = cmdPrepStmnt.CreateParameter("@IsCopied", ADODB.DataTypeEnum.adBoolean, ParameterDirectionEnum.adParamInput, 10, false);
Parameter p5 = cmdPrepStmnt.CreateParameter("@Size", ADODB.DataTypeEnum.adInteger, ParameterDirectionEnum.adParamInput, 10, f.Length);
cmdPrepStmnt.Parameters.Append(p1);
cmdPrepStmnt.Parameters.Append(p3);
cmdPrepStmnt.Parameters.Append(p5);
cmdPrepStmnt.Execute(out objAffected, ref obj, 0);
}
</code>
FileName is coming as blank in db, while in debug mode i can see that it is being set with a proper filename. The other 2 params are inserting fine.
The FileName field is set as Text field with width length 255, and the incoming data is always shorter than 255 chars. The insertion happens without any errors/exceptions. I have also tried replacing the data for filename with a string like "Test", still it is inserting blank string.
Please help.<code></code>
|
|
|
|
|
Access uses the ? placeholder for parameters, not SQL Server type parameters. It is positional based, so you should use something like
String sQuery = "INSERT INTO " + sTableName +
" ([FileName],[IsCopied],[Size]) VALUES (?,?,?)";
Then, add your parameters using CreateParameter("?", ....); in the order they appear in the list, i.e. FileName then IsCopied an finally Size.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I found recently that named parameters do work with Access/Jet, and they can even be used more than once, but they still need to be in order.
I didn't respond to the post earlier because the code doesn't look like OleDb / ADO.net
|
|
|
|
|
this is slightly stupid but how do i pass command line arguments with Visual Studio???
|
|
|
|
|
Select Project->Properties menu item, then (in the newly appeared window) select the Configuration properties->Debug node and finally set the command line arguments line content to whatever you need.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hi,
I'm wondering if there's any way to disable "Close" button on window's title bar?
Thanks in advance.
Goran
|
|
|
|
|
Have you looked at the properties on the form?
|
|
|
|
|
Actually, I forgot to tell that I need this in TreeView derived control, not on Form derived control.
So, the question is how to disable "Close" button in .NET's class which is derived from Control class, in my case TreeView control?
I'm sorry I've missed full information.
-- modified at 11:11 Monday 30th July, 2007
|
|
|
|
|
To display the treeview you still have to put it on a form?
|
|
|
|
|
I'm not sure what you mean. I'm creating TreeView derived control programmatically and I'm not able to disable "Close" button.
|
|
|
|
|
In .Net a TreeView is a control. Controls go on forms. FOrms are then displayed to the user. The close button is on the form. To disable the close button you must access the properties on the form.
If your not putting your treeview on a form what are you doing?
Edit:
Are you talking about WinForms or Asp.Net?
|
|
|
|
|
Do you mean "collapse"? To keep the nodes from being collapsed? (Not closed?)
|
|
|
|
|
Does anyone know of an alternative to Pegasus' ImagXpress for opening/viewing/scrolling an image? The product works very well, but the licensing fees are way too high ($60,000-$100,000).
Thanks
R.Myers
|
|
|
|
|
Leadtools - www.leadtools.com/
or
Accusoft - www.accusoft.com/
Leadtools has no runtime fees, which is pretty darn nice. Pegasus looks like a great product, but how in the heck do they justify the pricing structure?
|
|
|
|
|
Thanks, I appreciate the input.
|
|
|
|
|
Most of the Image toolkits are expensive and have some form of runtime licenses or reporting requirements. I have used Accusoft controls in the past, from a development perspective it is easy to use and feature rich. Unfortunately, they have a runtime license fee as well as quarterly reporting requirements (At least last year).
|
|
|
|
|
Do you happen to know what the pricing was on that? Just a ballpark figure.
Thanks
|
|
|
|
|
The Accusoft website. The pricing is, from what I remember, was around $1400 per developer and $8 per user for runtime royalities, plus annual maintenance.
|
|
|
|
|
Help me to get the memory details as u retrieve the hardware info.
If possible send the code
|
|
|
|