|
There is a simpler way to do that:
Lets say we have two forms:
1) Form1 : The main form
2) FormLogon : Logon form that should appear at the beginning
onLoad of Form1:
private void Form1_Load(object sender, EventArgs e)
{
this.Visible = false;
FormLogon myFormLogon = new FormLogon();
myFormLogon.ShowDialog(this);
if (myFormLogon.logonResult == 1)
this.Visible = true;
else
Application.Exit();
}
In FormlLogon have a public variable named logonResult to track which button was clicked.
public int logonResult = 0;
private void button1_Click(object sender, EventArgs e)
{
logonResult = 1;
Close();
}
private void button2_Click(object sender, EventArgs e)
{
Close();
}
|
|
|
|
|
zafersavas - that answered my question perfectly!
As a followup...
I am setting the user and password in the logon form, and the main form will be able to get the values as long as the login object is instantiated. After the login form returns I will move the values into variables on the main form so they will always be available.
Is this approach acceptable or is there a better way?
Thanks again for the help!
|
|
|
|
|
Yes quite acceptable. Most people probably will do that way.
Good luck.
|
|
|
|
|
Hi,
Can anyone guide me (links, ebooks)on creating C# programs that can run in mobile phones, I am interested in gps programs (or others kinds)
i already downloaded some articles in codeproject on the subject, (going to see that after finishing present work)
Thanks
i really don´t know many about it
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
Check this google result.[^]
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
Hello,
You can always download the Windows mobile SDK for visual studio its very good for beginning apps on phones.
-Steven
Windows Mobile Team
|
|
|
|
|
I was wondering where I could find out how to make it when you Right click a row in a GridView that it shows a drop down menu. Like when you click File at the top of a window and drops down and usually has Save, Save As, Exit, etc...
I see tons of examples on how to do it in ASP.NET but not for a windows application?
|
|
|
|
|
|
|
It's called a context menu, add it to the form and assign it to the datagridview
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Well that seems to easy. Thanks
|
|
|
|
|
how can i change the statusbar on windows form to be just like the windows vista style?
|
|
|
|
|
If I have a system where the client instantiates a business object and then the business object calls the DAC and then the DAC calls the database then is the business object an example of a facade design pattern?
|
|
|
|
|
Not really. A Facade presents a simplified composite interface to work with, while sitting atop and masking an underlying morass of interfaces that actually makes everything work.
If for example you had data coming from multiple sources (e.g. a sql server db, a web service and an xml file), then your business object would be a facade, or if the DAC returned a single source of data (e.g. DataTable, DbDataReader etc) then it could be considered a facade as it's collated data from multiple sources but exposes only a composite (and in theory would save changes to the correct location).
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
It seems like my example of a business object would match the definition of a facade design pattern described in wikipedia because it "provides a simplified interface to a larger body of code" - http://tinyurl.com/3s22hk[^]
Do you agree?
|
|
|
|
|
I am trying to make sure that I use the preferred implementation for returning a DataSet in ADO.NET 2.0. The following code seems to be the best way to me. Please let me know if it can be improved:
using (SqlConnection connection = new SqlConnection(_connectionString))
{
using (SqlCommand command = new SqlCommand("MyTestSP", connection))
{
command.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet ds = new DataSet();
adapter.Fill(ds);
return ds;
}
}
|
|
|
|
|
Looks OK if that's what you want to do. But...
Do you really need a DataSet or will a single DataTable do?
I would do new SqlCommand("MyTestSP", new SqlConnection(_connectionString) ) , but that's just me.
Other than that, are you sure you won't need the Connection and Command again? I prefer to create a Connection and Command and use them multiple times throughout a program's run. If you're doing that Web crap it may not matter.
|
|
|
|
|
While I retain the connection I always use a new command object. And yes I find the datatable more satisfactory to manipulate, although the overhead would be identical.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
The Current Design:
You click on the shortcut and a window pops up asking you for the source directory and target directory. You provide this information and then the files in one directory get copied to another directory. When I schedule this to run as a automated task, the window always pops up asking for the source dir and target dir.
What I would like:
When you schedule the program to run as an automated task, it doesn't ask the user for the source and target directories. If the user needs to change the source and target, they double click on the shortcut and the interface pops up again asking them for the source and target info.
Question:
How do I do this in C#?
|
|
|
|
|
Hi,
I think your problem is more about design rather than any particular language. If I read you correctly your current design is interactive and prompts the user for source and target directories.
When running unattended what is your source of directory data? One solution would be to provide a command line interface. e.g.
FileCopier srcdir targetdir
Your code could then do the following:
1) If there are any command line arguments assume that this is an unattended run.
2) Validate the arguments to ensure that the directories exist.
3) Perform your actions on the src and dest directories.
4) Write a log file so that you can check what happened when you weren't there.
Hope that helps, ....Alan.
|
|
|
|
|
Check System.Environment.UserInteractive
|
|
|
|
|
Thank you both. I will try your suggestions.
|
|
|
|
|
Hey there,
I'm really stuc and would appreciate anybody's help on this..
I am using visual c# express edition (windows forms app) and need to on Form_load event open a textfile that i specify in the code automatically and display its contents into a textbox on my form. Below is an example:
on form load
open c:\hello.txt
read c:\hello.txt
insert c:\hello.txt into Textbox.Text
-- I know that that above example is nothing like the way you'd code it but i'm am completely stuck on this pls help! i'd really appreciate it, thank you
|
|
|
|
|
Welcome to CodeProject
I strongly urge you to use beginner based materials to start learning how to program rather than asking questions on internet forums. Things like books or tutorials found on the web. We have a large collection of Articles here at CodeProject some of which are targeting beginners. You can find those articles under the Chapters section of the site menu.
I believe most people will learn beginner level subjects much faster from coordinated material rather than using internet forums.
led mike
|
|
|
|
|
Check out msdn and look at the FileInfo, DirectoryInfo, StreamReader, and StreamWriter classes. MSDN gives some good examples as to how to use these classes.
|
|
|
|