|
Hi,
seems like "you can only ever have one" is meant to read "you can do all you need with just one".
Having the Form as a class member brings you several things:
1. you only can have one Form object at a time, provided you don't create any local Form variables anywhere; so it is not the class member that keeps your count at maximum one, it is your coding discipline.
2. you can still do myForm=new Form(); , and each of myForm.Visible=false; myForm.Visible=true; myForm.Show(); myForm.Hide(); as often as you want, so "i want to only be able to show it once" is not met, unless again you apply coding discipline (that's "If it's set already, you don't need to new it up").
3. you can reuse it (i.e. turn invisible then visible again) keeping the Control settings from one occasion to the next; this is the real benefit of making it a class member, without being a class member your Form object would be in limbo whether still visible on the screen (assuming a modeless window that has not been closed yet) or not (assuming a modeless but closed window, or a modal window obviously closed since you left the method containing the ShowDialog call).
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Luc Pattyn wrote: that's "If it's set already, you don't need to new it up"
hmm well i took that to mean, i dont need to use the new command when i want to make the form appear, so i tried everything i could to get a form to appear without using 'new'.
so by coding discipline you mean something like:
try
{
setting.Activate();
}
catch
{
setting = new Settings();
setting.Show();
}
Cos i was thinking of just using something like an if statement but it didnt feel right. it just felt like there should be some way of declaring a form that was used across the whole class (like declaring a variable, where if i change it in one method, it can be accessed in another method and have the same value. although thinking about this, the variable must be created as the application starts, just like my form was when i was using public Settings setting = new Settings(); - i kept getting a form straight away. its a pity that in order to own a form, you need another form to own it, otherwise i could have used something like
setting = new Settings();
setting.showdialog(this);
which would allow only one to be created?
so as for number 3, is it better to reuse the same form? should i create my form as soon as my application starts but use a myForm.Hide(); ? at the minute im using Application.Run(); and not Application.Run(new myForm); as it would be when you start a default windows application on c#. the later would create the form straight away... but i could then hide it somehow?
if i created my form straight away, i could use a notifyicon attached to it to Show and Hide it and exit my script, if not, i can do what i am doing at the minute and include my notifyicon in my Main() area...
|
|
|
|
|
Sorry, you "think" and "feel" too much. I suggest you gather some facts. Buying and studying a tutorial book seems like an appropriate step. Right now you need to read more and write less.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:24 AM
|
|
|
|
|
this is the only question i have asked, i just wanted to make sure i was doing it properly (my instinct from my past programming experience would be to make an if statement). i have got pretty far just reading, i dont have a book and dont have access to one right know.
thanks for your help, ill go back to google now
|
|
|
|
|
hi,
I am developing an client server application using socket communication, in which a port always be in listen mode.
How can i make sure the port is secure from virus?
Is there any property in socket to make itself secure from unauthorized access?
Regards,
Yesuprakash
|
|
|
|
|
yesu prakash wrote: How can i make sure the port is secure from virus?
A port is like the door to your house. Your door does not get infected by a virus. Someone opens the door, brings the virus in, then you get infected.
yesu prakash wrote: Is there any property in socket to make itself secure from unauthorized access?
No, authorized access is a protocol decision. You can check the peer info on accept (or accept callback) and filter out based on ip or mac but that's about as much help as you'll get from the socket api.
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
How an unauthorised IP thru my lisitning port destroy my system?
|
|
|
|
|
hi
in a hash tabele i got key as modem numbers and value is an incrementing int values .how can i know which key value is the highest or lowest in c#?
|
|
|
|
|
Hi,
the keys and the values are available as an ICollection in Hashtable.Keys and Hashtable.Values,
so you can figure it out yourself. Same for Dictionaries.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Friday, February 20, 2009 12:04 AM
modified on Sunday, June 12, 2011 8:24 AM
|
|
|
|
|
can somebody help me with a c# code to get the highest int value in a hash table..plzz
|
|
|
|
|
this means you have a Hashtable and the keys are INT?
you may get all the keys of a HT, by using Keys property, just create a function that returns the MAX from keys array.
Calin
|
|
|
|
|
I have been trying to parse the Directory list into usable information.
For example if I am given the following:
-rw-r--r-- 1 ftp ftp 87040 Feb 17 23:46 Test_test Resume_Full.doc
The problem is how to know what is what. I can't parse/split based on a space " " because what happens is the date is seperated on spaces as well as the file names.
Can anybody help me?
Code Information below: In the code below the method "ExecuteCommand" just gets the response from the server.
------------------------------CODE BLOCK----------------------------------
Socket l_ClientDataSocket = null;
int l_iDataPort;
TcpListener l_FTPListener = null;
Byte[] l_bRecvData = new Byte[5120];
int l_iBufferLimit = 5119;
FileStream l_fsOutFile = null;
BinaryWriter l_fbOutFile = null;
string l_strCommand = "";
StringCollection l_strOutput = new StringCollection();
int l_iRetval = 0;
l_FTPListener = new TcpListener(0);
l_FTPListener.Start();
IPEndPoint pt = (IPEndPoint)l_FTPListener.LocalEndpoint;
l_iDataPort = pt.Port;
string l_strPortParams = GetPortParameters(l_iDataPort);
string l_strPortCommand = "PORT " + l_strPortParams + "\r\n";
l_iRetval = ExecuteCommand(l_strPortCommand, ref l_strOutput);
l_strCommand = "LIST " + l_strCurrDir + "\r\n";
l_iRetval = ExecuteCommand(l_strCommand, ref l_strOutput);
Thread.Sleep(500);
if (l_FTPListener.Pending())
{
l_ClientDataSocket = l_FTPListener.AcceptSocket();
}
l_ClientDataSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, RecvTimeOut);
l_ClientDataSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, SendTimeOut);
l_bRecvData.Initialize();
l_strOutput = new StringCollection();
l_iRetval = 0;
string l_strTemp = "";
Thread.Sleep(1000);
for (; l_ClientDataSocket.Available > 0; )
{
l_bRecvData.Initialize();
l_iRetval = l_ClientDataSocket.Receive(l_bRecvData, l_iBufferLimit, 0);
l_strTemp = Encoding.ASCII.GetString(l_bRecvData, 0, l_iRetval);
Thread.Sleep(400);
}
if (l_FTPListener != null)
{
l_FTPListener.Stop();
l_FTPListener = null;
}
modified 13-Feb-19 21:02pm.
|
|
|
|
|
I'm having a really strange problem with trying to access a SharePoint site via code.
I have an application that is using the SharePoint object model, like this
using (SPSite site = new SPSite(SiteIP))
The code is running on one server(SP is on this server) but now it needs to be moved to another server. Since the SiteIP is read from a config file I thought, no problem, change the IP and it should work. However, every time I try I get the FileNotFoundException. No matter what machine I try running it on I get the same exception.
To make it even more strange if I run this code on another box but use the IP of the site that is currently work I get the same exception.
A couple of articles pointed to a problem about giving the AppPool identity permissions in SQL Server, but that didn't help.
This is really baffling me. Anyone have some ideas?
only two letters away from being an asset
|
|
|
|
|
i want to count using c# how many times a particular methos is called...can somebody help me wit that!!!
|
|
|
|
|
Try using a static variable inside the function that you increment every time it is called!!!!!!!!
|
|
|
|
|
Hi
I'm looking for update only records which has been changed. usually, when u use SqlDataAdapter class, u can update existing records and send changes to database like this :
sqlDataAdapter1.Update(dataTable);
dataTable.AcceptChanges();
but i don't use SqlDataAdapter, i use SqlCommand.ExecuteNonQuery.
does anyone has the same experience with update only changed records ?
thanks
|
|
|
|
|
One presumes you use a proc to update each row. Inspect the rowstate of the datatable to identify rows that have changed or are new.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks Mycroft
ok, my another question (main question) is how to only refresh records in datagridview which has been changed ?
(for example, when user open one records in details form and update data then click ok, that specific record refresh in my datagridview)
thanks
|
|
|
|
|
There are a number of ways to do this, again assumes you have a proc that saves 1 record at a time.
You can identify the record by filtering the defaultview on the datatable on rowstate and process the results. This can be done anytime before acceptchanges.
Change your method to accept a datarow, you already know the row, it was identified when you entered the detail form. This can then be done on the save of the detail form.
I actually use a listview/grid for browsing on the main form and when the user selects something I pop a detail form, passing the ID (or 0 for insert). On the way out of the detail form I save the row (completely different table used by the detail only). The main form refreshes the list datatable based on the dialogresult of the detail form. Trick being to limit your main form list to a reasonable size, 2-300 records only. I know this is expensive in database reads but I never have data sitting on the client that has not been saved and the speed has been more than acceptable for decades now.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Why the IDictionary interface is inherited from ICollection & IEnumerable
public interface IDictionary : ICollection, IEnumerable
When the ICollection interface is already inherited from IEnumarable???
|
|
|
|
|
It is an explicit statement by the author or an error of omission.
Need custom software developed? I do C# development and consulting all over the United States.
If you don't ask questions the answers won't stand in your way.
Doing a job is like selecting a mule, you can't choose just the front half xor the back half so when you ask me to do a job don't expect me to do it half-assed.
|
|
|
|
|
I am using axWebBrowser.
How can i get html code of page that in browser now?
|
|
|
|
|
Hi,
you should have a look at the WebBrowser class, and its Document property.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:25 AM
|
|
|
|
|
What can i do with this property? Hw can i get source of page in browser?
|
|
|
|
|
Try DocumentText[^] property of WebBrowser class. It will give you the HTML for the current page displayed in webbrowser.
|
|
|
|