|
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
LoginForm lf = new LoginForm();
if (lf.ShowDialog() == DialogResult.OK)
{
Application.Run(new MainForm());
}
else
{
Application.Exit();
}
}
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
indeed, this does also work, after you set a AcceptButton property in the login screen/Form.
anyway, i had my code working.
you helped remember how to use DialogResult.OK again.
what is the advantage from your code over mine?
Bad = knowing 2 much
|
|
|
|
|
No real advantage, just less coding all round, saves worrying about declaring the boolean member and setting it in the button click.
As well as the AcceptButton , there is the CancelButton , and don't forget to set the DialogResult property for the buttons, if you use this method.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Natural_Demon wrote: doesn't work, the class gets disposed after the login screen gets closed
I think that is correct.
There probably are many ways to achieve what you want. Here are two ways I would try:
1. Use a modal dialog for the login stuff; this is the logical approach as I assume the MainForm isn't going to do any useful work if you're not logged in. Use the DialogResult value to indicate success.
Modal dialogs need disposing, so a using statement is used.
bool loggedIn=false;
using (LoginForm lf=new LoginForm()) loggedIn=lf.ShowDialog()==DialogResult.OK;
if (loggedIn) Application.Run(new MainForm());
2. However if MainForm could do useful things while user is looking around/typing name&password:
MainForm mf=new MainForm();
bool loggedIn=false;
using (LoginForm lf=new LoginForm()) loggedIn=lf.ShowDialog()==DialogResult.OK;
if (loggedIn) Application.Run(mf);
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
indeed, your reply is very usefull to me.
i'm making an agenda for a client.
(it's my first attemp to sell a program to someone and i want to be as good as possible)
i could keep the mainform running and after some time lock the mainform again.
to prevent other people from messing the agenda or data.
Bad = knowing 2 much
|
|
|
|
|
Hey guys!
How can i make it that he opens Firefox or any other Prog or file every x sec?
|
|
|
|
|
|
|
A nag screen? Most users don't like those; do you?
|
|
|
|
|
Hi every body,
I was just trying to know if a message send from my computer reaches another computer(which is peer to peer only 2 computers) ..... So how could I know whether they r connected or not .... and If connected how do I know my messages delivered there ??
Thanks
|
|
|
|
|
Some sort of confirmation of receipt would be the general idea.
|
|
|
|
|
I didnt even cant connect to the other computer ..... that is why I cant do other stuffs ... like to check wheterh the my messages reachs there??
How could I do that ?
|
|
|
|
|
The other computer would have to have a client set to receive 'messages' from your end (which is also a client), that client would have the logic to confirm receipt of data in its entirety.
|
|
|
|
|
Hey buddy ... I think u didnt get ma idea ...... Here is z code what I am working on(Msdn's code)
using System;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
public class GetSocket
{
private static Socket ConnectSocket(string server, int port)
{
Socket s = null;
IPHostEntry hostEntry = null;
hostEntry = Dns.GetHostEntry(server);
foreach(IPAddress address in hostEntry.AddressList)
{
IPEndPoint ipe = new IPEndPoint(address, port);
Socket tempSocket =
new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
tempSocket.Connect(ipe);
@ the last line of z above code .... it is the place where the problem occurs @ run time .....
it says "a socket was trying to unreachable network 127.0.0.1:80
and here is the remaining code
if(tempSocket.Connected)
{
s = tempSocket;
break;
}
else
{
continue;
}
}
return s;
}
private static string SocketSendReceive(string server, int port)
{
string request = "GET / HTTP/1.1\r\nHost: " + server +
"\r\nConnection: Close\r\n\r\n";
Byte[] bytesSent = Encoding.ASCII.GetBytes(request);
Byte[] bytesReceived = new Byte[256];
Socket s = ConnectSocket(server, port);
if (s == null)
return ("Connection failed");
s.Send(bytesSent, bytesSent.Length, 0);
int bytes = 0;
string page = "Default HTML page on " + server + ":\r\n";
do {
bytes = s.Receive(bytesReceived, bytesReceived.Length, 0);
page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes);
}
while (bytes > 0);
return page;
}
public static void Main(string[] args)
{
string host;
int port = 80;
if (args.Length == 0)
host = Dns.GetHostName();
else
host = args[0];
string result = SocketSendReceive(host, port);
Console.WriteLine(result);
Console.Read();
}
}
If u got it please help me
|
|
|
|
|
Looks like you are trying to connect to yourself! 127.0.0.1 is loopback address, not the remote computer. btw this is really a TCP/IP issue and not C#.
|
|
|
|
|
That is what I was thinking .............. So how can I search the IPs of another computers in my networkk?............
Richard MacCutchan wrote: btw this is really a TCP/IP issue and not C#.
The connection works perfectly for datasharing,internet sharing, So I hope it is not a TCP/IP question. Or is there something that I didnt know abt?
Thank you.
|
|
|
|
|
Mati,
I have tried your code on my system and the following occurred:
1. run program with NO parameters on command line. The default action in function Main() is to use the hostname of the machine that the code is running on. In this case the IP address resolves to 127.0.0.1 and the connect fails as there is no listener at port 80.
2. Run with the name of my remote system in the command and the connection works; but not completely as I have no port 80 listener on that system either.
As I said before this is really a TCP/IP question and that is about the extent of my knowledge.
|
|
|
|
|
So do you think it will work if I am give the address of the other client computer(i.e not the host where the program is running)
Richard MacCutchan wrote: I have no port 80 listener on that system either.
Can u tell me about how do I know if wheterh port 80 listner in my system exists or not?
Thank you
|
|
|
|
|
You need to give either the IP address or DNS (network) name of the computer that you are trying to connect to, in order to communicate. From what I can see of your code you are trying to send a HTTP request to port 80 (HTTP server port) of the destination machine. This means that you must have a Web server process running on that machine, which will listen on port 80 by default.
From your questions I suspect that you need to spend some more time studying TCP/IP and general network communication before proceeding further.
I repeat this question really belongs in an alternative forum as it is not a C# issue.
|
|
|
|
|
Thank you for ur help body. I should read more........ Even if I learned Networking around 36 credit hour I should read more abt Socket and networking ........ thanks for ur help ........ I will contact u if i have any questions. with this thread ......... by z way do u have an experience working on Socket Programming??
Thank you
|
|
|
|
|
Mati,
My experience of socket programming was on UNIX rather than Windows systems and was sometime ago, so I have probably forgotten quite a lot. I cannot really provide an online tutorial for you so I would repeat my earlier advice to go and study some tutorials and other publications before proceeding further. If you still have problems in the future then reopen your questions in the correct forum, as these are really not C# issues.
regards,
Richard
|
|
|
|
|
If it is difficult, then is there a portable compiler that I can use?
|
|
|
|
|
You compile it from the command line using csc.exe .
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
The C# Express Edition is free. So is SharpDevelop.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|