|
zeeShan anSari,
File -> New
Regards,
Gareth
|
|
|
|
|
Hi all,
I'm trying to implement code that will shut down a form before it is even shown, in my case the form is an MDI child but I suppose the same principle will hold for any type of form.
The MDI parent invokes the form:
FormUser objfrmUser = new FormUser();<br />
objfrmUser.MdiParent = this;<br />
objfrmUser.Show();
I want the form itself to do some check that will determine whether it may be shown or not and, if not, display a nice little MessageBox after which it closes down. Something like:
if (doTest())<br />
{<br />
MessageBox.Show("No can do");<br />
this.Close();<br />
}
If I put this code in the Activated event handler I get an exception informing me that "Value Close() cannot be called while doing CreateHandle()".
If I put the code in the Shown event handler it works sort of. It displays the message and closes the form gracefully but it shows the form first and then display the message. I don't want the form to be visible when the message is shown.
Any ideas?
|
|
|
|
|
Dewald wrote: I don't want the form to be visible when the message is shown.
Any ideas?
Close it before showing the message box?
|
|
|
|
|
won't work
The problem is that you can't ".Close()" a form that's not already loaded.
So you can't use .Close in events like Load() which is called before the form is totaly loaded.
|
|
|
|
|
Depending on what you want to do:
- check the conditions in the constructor of FormUser - if they fail throw an exception (this is the best approach for security)
- check the condition before objfrmUser.Show (you will have to declare doTest "public")
- overload the Show-Method (calling the original Show-method) with additional doTest-Check
Best approach seems to be option 3
|
|
|
|
|
Excellent! I can't believe I didn't think of that (option 3 that is). Does exactly what I want.
Cheers,
D
|
|
|
|
|
Why can't you check before opening the form?
if(CanShowFormUser())<br />
{<br />
FormUser objfrmUser = new FormUser();<br />
objfrmUser.MdiParent = this;<br />
objfrmUser.Show();<br />
}<br />
else<br />
{<br />
MessageBox.Show("No can do");<br />
}
codito ergo sum
|
|
|
|
|
You'll have to implement this check in your static void Main() in your Program.CS. You can do something like this:
static void Main()
{
if (true == YourCondition)
{
yourMainForm MainForm = new yourMainForm ();
Application.Run();
}
else
{
MessageBox.Show("Some condition hasn't been met. Must close.");
Application.Exit();
}
}
I remember a while back I was trying to do the same thing. I can't remember why, but you can't close the form, without it showing, until after it has been initialized and loaded. So, the work-around is to preform your check in your Main method in Program.CS.
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|
|
I want to make a Email Client like Form with multiple columns, Sender,Subject,Date etc in a Listview Control and showing further Info w.r.t ID(PrimaryKey) in a text area.
Now, I can hide a column by setting it's width to 0. How do I extract Info of Hidden Column ?
Thanks
|
|
|
|
|
Adnan Siddiqi wrote: Now, I can hide a column by setting it's width to 0. How do I extract Info of Hidden Column ?
Wow, that is one of the funniest posts I have ever read. You really should check this out[^].
led mike
|
|
|
|
|
are you trying to offend or just trolling around?
my friend if you can't be helpful then it doesn't mean you become painful for others.
|
|
|
|
|
Adnan Siddiqi wrote: if you can't be helpful
In my opinion I possibly gave you the best advice you will ever get.
led mike
|
|
|
|
|
hai all1
I am fresher to .Net plz help me!!!!!!11111
In my project i want to print a current doucment with print previews so plz help me!!!
srinivas
|
|
|
|
|
First of all, you should post this to the ASP.NET forum. Secondly, if this really is an ASP.NET application then you are tied into what the browser can do for you with regards to printing. To style your output for print, you normally need to include a Print Media stylesheet.
|
|
|
|
|
Hi All.
I have written an application with a logon form. Previously I used to hardcode the users logon details withing the code. The problem I have with my current project is that I could possibly have upto 100 users and would have to add or remove users from time to time. I am using an Access DB with the application. I want to create a table in the DB to store the Users details.
My problem is that I am not sure how to check the details entered on the logon form back to the DB. Below is what I currently have. Can somebody please help me change the below so that it rather reads through a table in the db to check the users details. Once the details have been verified it should then go onto opening the main form of the application. Any help or advice with this would be greatly appreciated.
private void btnLogon_Click(object sender, EventArgs e)
{
MainApp mnapp = new MainApp();
if (txtboxUserName.Text == "user1" && txtboxPassword.Text == "user1pwd"
||txtboxUserName.Text == "user2" && txtboxPassword.Text == "user2pwd")
{
this.DialogResult = DialogResult.OK;
}
else MessageBox.Show("Invalid username and or password supplied", "Logon Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
|
|
|
|
|
I have two applications(projects) say A and B. A accessed a data from database only once and store in hashtable. Is there any way so that i can pass hashtable or any object to app B? Whether I have to use some server/client architecture? Suggest me any simple method.
thanks in advance
|
|
|
|
|
Well, there's things like shared memory, named pipes, or just connect to yourself using sockets.
Named pipes and sockets would probably be the best, and last time i wanted to use pipes in C# i think i had to import the methods from one of the DLLs. That leaves sockets as probably the easiest option.
There's probably more stuff, but i havn't needed to use it, so i don't know about it
My current favourite word is: Nipple!
-SK Genius
|
|
|
|
|
I have used sockets but can i pass objects also, like hashtable?
|
|
|
|
|
Are they both exes? Sounds like a standard n-tier app otherwise.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Yes. A is having capability of accessing huge data so that whenever I used to debug B there will be no need to load that much of data every time. So i just want to load data in App A, and further accessed by B.
|
|
|
|
|
In which case then probably sockets would be a good choice, but I would look at the overall architecture as it sounds like application A is really a data server. Potential for web service perhaps?
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hmm. Sounds like a job for WCF (Windows Communication Foundation). This opens up many different types of bindings for you.
|
|
|
|
|
class Program
{
static void Main(string[] args)
{
Dictionary<book,object> entries = new Dictionary<book, object="">();
entries[new Book("C# Cookbook", 234)] = null;
entries[new Book("ADO.NET Cookbook", 277)] = null;
entries[new Book(".NET Framework", 455)] =null;
entries[new Book("Windows Forms", 873)] = null;
getproperties(entries,"books");
}
private static Dictionary < Book,object > getproperties(Dictionary< Book,object> entries,string myString)
{
//Return new dicitonary of type Dictionary < Book,object> which has myString in as value and entries as book
}
}
class Book
{
private string m_Title;
public string Title
{
get { return m_Title; }
set { m_Title = value; }
}
private int m_Pages;
public int Pages
{
get { return m_Pages; }
set { m_Pages = value; }
}
public Book(string title, int pages)
{
m_Title = title;
m_Pages = pages;
}
public string Display()
{
return String.Format("{0} ({1} pages)", m_Title, m_Pages);
}
}
|
|
|
|
|
So, Queer-Boy, er, Justin Timberlake, what's your specific problem you have had in implementing this yourself?
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|
|
I am unable to modify the value of dicitonry iterating all the keys using foreach loop
|
|
|
|