|
I want to bring up a second form to adjust variables on the first form. Any help appreciated! -mutty
|
|
|
|
|
First Is This Variable Public if Yes You Can Do Somthing Like That in Form1
Form2 form2=new Form2();
form2.variableName=value;
If this variable is not public which will be better
You can Write public function in the form and make it set the value of the variable you can code somthing like thar in Form2 which have the variable you wwant to access
public voide SetValue(int i)
{
myVariable=i;
}
and in Form1 You can Write
Form2 form=new Form2();
form2.SetValue(1);
MCAD
|
|
|
|
|
Sorry, I should have been clearer what I mean. I am trying to open a new form, (Form2), from my main form (form1)
On form2 are numerous controls which should change variables of form1.
|
|
|
|
|
Pass a reference to form1 in form2's constructor and store it inside form2:
in form 1:
Form2 form2 = new Form2(this);
form2.Show();
in form 2:
public Form2(Form1 refToForm)
{
this.form1 = refToForm;
}
private someMethod()
{
refToForm.SomeProperty = someValue;
}
|
|
|
|
|
Mutty wrote:
am trying to open a new form, (Form2), from my main form (form1)
In Form1
Form2 form2=new Form2();
form2.Show();
<small>Mutty wrote:</small>
On form2 are numerous controls which should change variables of form1
in form2 like in my other message
<pre><code>
Form1 form1=new Form1();
form1.var=value;
MCAD
|
|
|
|
|
Hi All,
I doing some research for NUnit testing. I had a question related to its use for database testing. Should we avoid writing the tests for databases?
Please let me know.
Any comment will be appreciated.
|
|
|
|
|
Anonymous wrote:
Should we avoid writing the tests for databases?
Why? Don't you care if the database functionality works?
You should test all the database functions against a test version of the DB (with know data inserted), verifying that every function in you data access layer works as expected, and handles errors in a graceful way. Unless you do, changes to stored procedures, or schema changes, or fixes to other bugs, or enhancements could break your application in unanticipated ways. Test everything, including verifying that all schema is as expected, then you have a way to run regression tests that you can rely on.
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
All that is necessary for the triumph of evil is that good men do nothing.
Edmund Burke
|
|
|
|
|
Thanks for your response. I was told that it takes a lot of time and may not be useful, not even the client side code. It's good to test the business logic.
I am still tryinin to learn to write the tests...it's not easy to write them for the entire scope of the application.
|
|
|
|
|
ANy comments on my previous comment would be appreciated.
Has anyone used NUnitASP for testing.
|
|
|
|
|
Only test your coded methods such as business objects and data access objects and their interaction with handling the data that will be extracted and manipuated from a database.
Don't test the database such as how it handles data; otherwise you are an Oracle, Microsoft, DB3, or FoxPro database tester, which will be a complete waste of time.
Lastly leave the data isssues and normalization to a DBA. That is why they are paid the medium size bucks....
IMHO
|
|
|
|
|
Hello gurus,
I'd like to know how can I programmatically set the focus on tree node freshly created?
I can programmatically select it but the focus still remain to the top node. I'd like to programmatically set the focus on any new created tree node.
Best regards.
Fred.
There is no spoon.
|
|
|
|
|
you can set the focus on any node on the tree by using this syntax :
//TreeView object
System.Windows.Forms.TreeView treeview = new System.Windows.Forms.TreeView();
// Now you have to get the object to that node you want to focus
System.Windows.Forms.TreeNode node = //node rerefence of u want to focus
treeview.SelectedNode = node;
treeview.focus();
-
hope it will help you
Ankit Singhal
|
|
|
|
|
ok thanks
Fred.
There is no spoon.
|
|
|
|
|
Hi,
I am creating a window service in c# and when I starts the service at that time on some conditions I want to start the service. At that time I want to some error message and abort the service.
Please help me ASAP
Ankit Singhal
- ankit@earlysail.com
|
|
|
|
|
Services start before any login is possible. Normal applications do not start until a user logs in. A good solution would be to have your service start automatically (ServiceInstaller.StartType set to ServiceStartMode.Automatic ) and throw an exception from OnStart if the conditions are valid. Do not try to stop the service from within OnStart using the ServiceController . At this point the service controller database is still locked while startup code runs. If you try to stop it you will have a deadlock and any services scheduled to start after yours will not start - ever.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
i have 2 applications , 1º is in windows service and the other is windows application.
i need to start, stop and pause service from windows application.
i have done that,but the problem is when i start the service, it works, when i stop the service, it wors. but when i try to start again the service, it does not work, i need to close the project and reopen and then it works again.
Please Help
|
|
|
|
|
Use this code...
System.ServiceProcess.ServiceController scm = new System.ServiceProcess.ServiceController ("MyService","MyServer");
//then to start it...
scm.Start();
//or to stop it...
scm.Stop();
You might have to create a new instance of the service control manager object each time you want to start or stop the service. I use this same code in a number of applications and have never had a problem with it.
Darryl Borden
Principal IT Analyst
dborden@eprod.com
|
|
|
|
|
this is my code in windows application, that calls the other project the windows application
class ServiceInstaller
{
#region Private Variables
private string _servicePath;
private string _serviceName;
private string _serviceDisplayName;
#endregion Private Variables
#region DLLImport
[DllImport("advapi32.dll")]
public static extern IntPtr OpenSCManager(string lpMachineName,string lpSCDB, int scParameter);
[DllImport("Advapi32.dll")]
public static extern IntPtr CreateService(IntPtr SC_HANDLE,string lpSvcName,string lpDisplayName,
int dwDesiredAccess,int dwServiceType,int dwStartType,int dwErrorControl,string lpPathName,
string lpLoadOrderGroup,int lpdwTagId,string lpDependencies,string lpServiceStartName,string lpPassword);
[DllImport("advapi32.dll")]
public static extern void CloseServiceHandle(IntPtr SCHANDLE);
[DllImport("advapi32.dll")]
public static extern int StartService(IntPtr SVHANDLE,int dwNumServiceArgs,string lpServiceArgVectors);
[DllImport("advapi32.dll",SetLastError=true)]
public static extern IntPtr OpenService(IntPtr SCHANDLE,string lpSvcName,int dwNumServiceArgs);
[DllImport("advapi32.dll")]
public static extern int DeleteService(IntPtr SVHANDLE);
[DllImport("kernel32.dll")]
public static extern int GetLastError();
#endregion DLLImport
public bool InstallService(string svcPath, string svcName, string svcDispName)
{
#region Constants declaration.
int SC_MANAGER_CREATE_SERVICE = 0x0002;
int SERVICE_WIN32_OWN_PROCESS = 0x00000010;
//int SERVICE_DEMAND_START = 0x00000003;
int SERVICE_ERROR_NORMAL = 0x00000001;
int STANDARD_RIGHTS_REQUIRED = 0xF0000;
int SERVICE_QUERY_CONFIG = 0x0001;
int SERVICE_CHANGE_CONFIG = 0x0002;
int SERVICE_QUERY_STATUS = 0x0004;
int SERVICE_ENUMERATE_DEPENDENTS = 0x0008;
int SERVICE_START =0x0010;
int SERVICE_STOP =0x0020;
int SERVICE_PAUSE_CONTINUE =0x0040;
int SERVICE_INTERROGATE =0x0080;
int SERVICE_USER_DEFINED_CONTROL =0x0100;
int SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED |
SERVICE_QUERY_CONFIG |
SERVICE_CHANGE_CONFIG |
SERVICE_QUERY_STATUS |
SERVICE_ENUMERATE_DEPENDENTS |
SERVICE_START |
SERVICE_STOP |
SERVICE_PAUSE_CONTINUE |
SERVICE_INTERROGATE |
SERVICE_USER_DEFINED_CONTROL);
int SERVICE_AUTO_START = 0x00000002;
#endregion Constants declaration.
try
{
IntPtr sc_handle = OpenSCManager(null,null,SC_MANAGER_CREATE_SERVICE);
if (sc_handle.ToInt32() != 0)
{
IntPtr sv_handle = CreateService(sc_handle,svcName,svcDispName,SERVICE_ALL_ACCESS,SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START,SERVICE_ERROR_NORMAL,svcPath,null,0,null,null,null);
if(sv_handle.ToInt32() ==0)
{
CloseServiceHandle(sc_handle);
return false;
}
else
{
//now trying to start the service
int i = StartService(sv_handle,0,null);
// If the value i is zero, then there was an error starting the service.
// note: error may arise if the service is already running or some other problem.
if(i==0)
{
//Console.WriteLine("Couldnt start service");
return false;
}
//Console.WriteLine("Success");
CloseServiceHandle(sc_handle);
return true;
}
}
else
//Console.WriteLine("SCM not opened successfully");
return false;
}
catch(Exception e)
{
throw e;
}
}
public bool UnInstallService(string svcName)
{
int GENERIC_WRITE = 0x40000000;
IntPtr sc_hndl = OpenSCManager(null,null,GENERIC_WRITE);
if(sc_hndl.ToInt32() !=0)
{
int DELETE = 0x10000;
IntPtr svc_hndl = OpenService(sc_hndl,svcName,DELETE);
if(svc_hndl.ToInt32() !=0)
{
int i = DeleteService(svc_hndl);
if (i != 0)
{
CloseServiceHandle(sc_hndl);
return true;
}
else
{
CloseServiceHandle(sc_hndl);
return false;
}
}
else
return false;
}
else
return false;
}
public bool Installer(string svcName)
{
bool Ativo=false;
int GENERIC_WRITE = 0x40000000;
IntPtr sc_hndl = OpenSCManager(null,null,GENERIC_WRITE);
if(sc_hndl.ToInt32() !=0)
{
int DELETE = 0x10000;
IntPtr svc_hndl = OpenService(sc_hndl,svcName,DELETE);
if(svc_hndl.ToInt32() !=0)
{
System.ServiceProcess.ServiceController myController =
new System.ServiceProcess.ServiceController(svcName);
if (myController.CanStop)
{
Ativo=true;
}
}
}
CloseServiceHandle(sc_hndl);
return Ativo;
}
public void StopService(string svcName)
{
System.ServiceProcess.ServiceController myController =
new System.ServiceProcess.ServiceController(svcName);
if (myController.CanStop)
{
myController.Stop();
myController.Refresh();
}
myController.Dispose();
}
public void Dispose()
{
System.GC.Collect();
}
}
|
|
|
|
|
Why not just use the ServiceController class and save yourself most of the work? You can make half of this code disappear, making it much easier to support.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Can anyone give me an example of using WM_CALLWNDPROC hook or the WH_GETMESSAGE hook to capture the cut/copy/paste messages. Need a example without using a textbox contol in forms class but would like to use the API. A working program using this API would be great.
Thanks for the help
|
|
|
|
|
http://www.codeproject.com/cs/menu/TcMagicalEditMenu.asp
should be useful and for keyboard events
http://www.dotnetspider.com/technology/kbpages/1107.aspx
Hope this helps
Live Life King Size
Alomgir Miah
|
|
|
|
|
Thanks for it but need to capture the windows mouse cut/copy and paste events. The code project shows how to creat your own menus and the other needs a textbox control with the overiding WNDPROC messages. I may not have explained it clearly but i can capture keyboard inputs using the SetWindowsHookEx hook but am unable to capture the cut and paste events when using the mouse. I need a fully working example to do this.
|
|
|
|
|
I'm currently doing some work on extending an application and would greatly appreciate some pointers. Currently the application makes heavy use of rather big matrices of floats (approx. 2M elements). A matrix is used to represent a property for a set of relations. Let’s assume we have a base set of matrices that are read from disk at application startup. A matrix in this base set could for example represent the number of users of the relations, i.e., the value stored on index i,j within this matrix represents the number of users using relation i,j. My current task is to write a tool that will select relations using a criterion and the information stored within these base matrices. This basically comes down to first selecting relations based on their names (wildcards allowed) and then filter theses selections using the criterion and the matrices. An example could be to select all relations x, y with more than z users. The easiest way of doing this would obviously be to loop through all relations. However I get the distinct feeling that there must be a better way of doing this. Having rather limited experiences using DBs I would like to ask you if you think a DB could be beneficial?
|
|
|
|
|
In my opinion DBs are surely slower and less disk/ram space efficient.
I think also that 2M elements use at least *some* megabytes of memory.
Iterating over all the elems may waste much time, but if there is NO relation between, for example, adjacent elems in the matrix, it is, in my opinion, the only way...
You can use something like BinTrees, but the data MUST be structured in a some kind of ordered status.
[ITA] Tozzi ha ragione: Gaia si sta liberando di noi.
[ENG] Tozzi is right: Gaia is obliterating us.
|
|
|
|
|
Thanks for your quick reply. I am not entirely sure we have understood each other correctly, my explantion beeing anything but good. However, my interpretation of you answear is that looping over all relations and filtering out the interseting ones using the matrices in memory is likely to be more efficient than placing the same information in a DB and retrieve them from there?
|
|
|
|