|
|
Hi,
When are the properties that I set in the properties window used in my application?
I have a class that does som plotting. One property in the class is XMax. XMax is set to 10 in the class but in properties window XMax is set to 255. If I print the value of XMax in the constructor of the class "10" is the result. But when "using" the application 255 is the value of XMax.
How do I get the value of XMax that is set in the properties window? I want to store that value as a default value when my program is running.
Please, help.
/Anders
|
|
|
|
|
The properties and events changed in the properties window at design time are mapped to lines of code in FormName.Designer.cs
If you expand the + next to your form in solution explorer, you'll see it, then right click / view code and you can see the auto-generated code.
The flow of logic explains how they're implemented.
----
If you want to change the default value of a property, as it appears in the designer, then you need to apply attributes to your properties. In this case,
[DefaultValue(5)]
Look up System.ComponentModel namespace in MSDN in particular
|
|
|
|
|
In InitializeComponent() ;
|
|
|
|
|
Hi All,
My app seems to run ok on vista, apart from one thing-
it writes to the registry to set up file associations.
Whilst this works fine in XP, in vista i get security exceptions if i'm not an administrator.
Is there a non-administrator way to programmatically configure file associations in vista?
or, how can i invoke UAC in order to gain the correct permissions to access the registry?
Thanks
Jon
|
|
|
|
|
There is not a non-admin way to manipulate that part of the registry. Since you are configuring file associations, the proper way to do that would be as part of the application installer, which will already be running with the required elavated privileges.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Write your associations to HKEY_CURRENT_USER\Software\Classes instead of HKEY_CLASSES_ROOT.
That way they will be set up only for the current user.
If you want to set up associations for all users on the machine, that requires administrative rights. The easiest way to get a UAC prompt is to create a separate .exe with a manifest (with requestedExecutionLevel). The other way would be COM elevation[^].
|
|
|
|
|
Hi,
I'm trying to copy a bitmap of a user control to the clipboard and then into OpenOffice Writer.
The problem I have is that nothing gets copied into OpenOffice Writer. I always have to first paste the bitmap to WordPad, then copy it again to the clipboard from there and only then can I paste the bitmap into OOWriter.
The issue seems to be the format of the bitmap I copy to the clipboard (BITMAP and DIB BITMAP - according to Clipboard Viewer). When I add the step using WordPad, it adds the formats ENHANCED METAFILE and PICTURE.
Here's the question: How can I also copy the bitmap as Enhanced Metafile and Picture, as that would probably solve my problem.
Here's the code I'm using:
<br />
Point topLeft = this.PointToScreen(this.Location);<br />
Size screenshotSize = this.Size;<br />
<br />
Bitmap bmpScreenshot = new Bitmap(screenshotSize.Width, screenshotSize.Height, PixelFormat.Format32bppArgb);<br />
<br />
Graphics gfxScreenshot = Graphics.FromImage(bmpScreenshot);<br />
gfxScreenshot.CopyFromScreen(topLeft, new Point(0, 0), screenshotSize, CopyPixelOperation.SourceCopy);<br />
<br />
Clipboard.SetImage(bmpScreenshot);<br />
<br />
Any help is appreciated. Thanks
|
|
|
|
|
On 2 dbservers we have tables that are equal to achother.
One production DB server and one TestDB Server (Different machines!)
They both have the same tables.
I want to check one table on btoh systems row by row.
I know that the first 10000 rows are equal.
But if I check DataRows with
if (test.Rows[i] != production.Rows[i]) {}
the statement always return true even if both rows have the same data!
How can I properly check the values in the DataRow if they really have differences?
I tried with ItemArray too, but no success.
|
|
|
|
|
spooky manus wrote: if (test.Rows[i] != production.Rows[i]) {}
U R checking the reference of 2 Objects.
It will always evaluate to false.
Try this:
if(IsEqual(test.Rows[i],production.Rows[i]))
{
}
private bool IsEqual(R1,R2)
{
flag=true;
for(int i=0;i<R1.columns.count)
if(R1.ItemArray[i].ToString()!=R2.ItemArray[i].ToString())
flag=false;
return flag;
}
Regards,
Arun Kumar.A
|
|
|
|
|
Hi Arun,
you brought me in the right direction.
if(R1.ItemArray[i].ToString()!=R2.ItemArray[i].ToString()) should be
if(R1.ItemArray.GetValues(i).ToString()!=R2.ItemArray.GetValues(i).ToString())
In that case I could check field by field if any differences occur. Thanks a lot for your help cause my problem was made very clear between the 2 databases in an instant. COOL
|
|
|
|
|
Why do you want to check one table on "both" systems row by row? You then do and extra, non-logical row checkup for the rows on their own table I assume you want to check if the rows of a table in databaseFirst exist in a table in databaseSecond.
1) Execute select * from 1st table and store the result in a DataTable
2) Execute select * from 2nd table and store the result in a DataTable
3) You should compare the values of each row manually or wrap the DataRow object in your own implementation where you override Object.Equals and Object.GetHashCode() methods where you compare specific values ( row[column1], row[column2]...e.t.c.)
4) For value types: != compares values BUT
For reference types like DataRow, it compares the reference (memory address) which is in your case always different because you are already comparing DataRows in different tables.
Hope this helps,
|
|
|
|
|
Hello All
I am updating a database on a server using a web service, the web service, my program is reading a large text files in my local machine and every 1000 line send them as an array of type string to the web service method that accepts string array , it runs will for a while but after 2 or min it gives me an exception "The request failed with HTTP status 400: Bad Request"
can any one help on this plz!
|
|
|
|
|
Does the request exceed the default limit of 4 MB?
---
single minded; short sighted; long gone;
|
|
|
|
|
I don't know exactly what you mean, but if you mean the size of the string array, I had used a string array that contains 1000 line and another one that uses 100 line from the txt file, and both give me the same result.
|
|
|
|
|
Get ProcessExplorer or a similar tool and monitor the asp.net process that is running your webservice, I think that IIS is restarting the process due to large amount of RAM usage. I got the same error uploading large files by calling a webservice, chunk by chunk. A solution is to use free the memory from time to time by calling the Garbage Collector.
http://stefanprodan.wordpress.com
|
|
|
|
|
How can i call the Garbage Collector on the server machine, i am running my application on a client machine all i can do is to call the web service on the server, plz help
|
|
|
|
|
Hello,
As you know helpprovider component helps you to integrate help 1.0 files in the application. These are chm or html files. Is there a way to integrate help 2.0 files (hxs, msdn style help) into my windows forms application? So that it opens at specified place in document explorer like it happens in VS 2005. Thanks
|
|
|
|
|
Hi I have created a a service project in C#
It was installed perfectly. When the service started, It is giving error as "Could not perform requested operation for the Service "ServiceName" in local machine.
The Module is like this:
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Collections.Specialized;
namespace QuoteServer
{
///
/// Summary description for Class1.
///
public class QuoteServer
{
private TcpListener listener;
private int port;
private string filename;
private StringCollection quotes;
private Random random;
private Thread listenerThread;
public QuoteServer(): this ("quotes.txt")
{
}
public QuoteServer(string filename): this (filename,7890)
{
}
public QuoteServer(string filename, int port)
{
this.filename=filename;
this.port=port;
}
protected void ReadQuotes()
{
quotes=new StringCollection();
Stream stream=File.OpenRead(filename);
StreamReader streamReader=new StreamReader(stream);
string quote;
while((quote=streamReader.ReadLine())!=null)
{
quotes.Add(quote);
}
streamReader.Close();stream.Close();
random=new Random();
}
protected string GetRandomQuoteOfTheDay()
{
int index=random.Next(0,quotes.Count);
return quotes[index];
}
public void Start()
{
/*ReadQuotes();
listenerThread=new Thread(new ThreadStart(this.Listener));
listenerThread.Start();*/
}
protected void Listener()
{
try
{
//ReadQuotes();
IPAddress ipAddress=Dns.Resolve("localhost").AddressList[0];
listener=new TcpListener(ipAddress,port);
listener.Start();
while(true)
{
Socket socket=listener.AcceptSocket();//if the processor will take more time,
//we can create a new thread for each client will perform
string message=GetRandomQuoteOfTheDay();
UnicodeEncoding encoder=new UnicodeEncoding();
byte[] buffer=encoder.GetBytes(message);
socket.Send(buffer,buffer.Length,0);
socket.Close();
}
}
catch(SocketException e)
{
Console.WriteLine(e.Message);
}
}
public void Stop()
{
//listener.Stop();
}
public void Suspend()
{
listenerThread.Suspend();
}
public void Resume()
{
listenerThread.Resume();
}
public void RefreshQuotes()
{
ReadQuotes();
}
}
}
////////////////////////
The Service Module is like this:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Threading;
//using QuoteServer;
namespace QuoteService
{
public class QuoteService : System.ServiceProcess.ServiceBase
{
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
private QuoteServer.QuoteServer quoteServer;
private Thread t;
public QuoteService()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();
// TODO: Add any initialization after the InitComponent call
}
// The main entry point for the process
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new QuoteService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
//
// QuoteService
//
this.CanPauseAndContinue = true;
this.ServiceName = "QuoteService";
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
///
/// Set things in motion so your service can do its work.
///
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
/*t=new Thread(new ThreadStart(this.StartQuoteServer));
t.Start(); */
quoteServer=new QuoteServer.QuoteServer(@"C:\Documents and Settings\sumantar\Desktop\C#\C# Experiment\QuoteServer\quotes.txt",4567);
quoteServer.Start();
}
/*protected void StartQuoteServer()
{
quoteServer=new QuoteServer.QuoteServer(@"C:\Documents and Settings\sumantar\Desktop\C#\C# Experiment\QuoteServer\quotes.txt",4567);
quoteServer.Start();
}
*/
///
/// Stop this service.
///
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
quoteServer.Stop();
}
protected override void OnPause()
{
// TODO: Add QuoteService.OnPause implementation
//base.OnPause ();
//quoteServer.Suspend();
}
protected override void OnContinue()
{
// TODO: Add QuoteService.OnContinue implementation
//base.OnContinue ();
//quoteServer.Resume();
}
protected override void OnShutdown()
{
// TODO: Add QuoteService.OnShutdown implementation
//base.OnShutdown ();
//OnStop();
}
public const int commandRefresh=128;
protected override void OnCustomCommand(int command)
{
// TODO: Add QuoteService.OnCustomCommand implementation
//base.OnCustomCommand (command);
switch(command)
{
case commandRefresh:
//quoteServer.RefreshQuotes();
break;
default:
break;
}
}
}
}
//////
The problem lies:
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
quoteServer=new QuoteServer.QuoteServer(@"C:\Documents and Settings\sumantar\Desktop\C#\C# Experiment\QuoteServer\quotes.txt",4567);
quoteServer.Start();
}
If I remove the 2 line:
The service is installed and starting and stoping.
If I put this 2 line,m Service is installed but not starting. It give the following error:
"Could not perform requested operation for the Service "ServiceName" in local machine.
Please help me. Thanks in advance.
|
|
|
|
|
My first guess would be whoever you set up the windows server to run as, that is the username and password does not have rights to do what you are trying to do.
Hope that helps.
Ben
|
|
|
|
|
Thanks Ben!!!
In effect when I try to start the service I
receive an error that says something like that: "The DataBaseService
service on the local computer has been started and then stopped. Some
services stop automatically if there aren't operation to execute, for
example ........ "
|
|
|
|
|
Most of the time when I get that error, it means my username and password are not valid. That is not a good message to get. You want to get sevice started successfully.
Ben
|
|
|
|
|
But I changed the Account Properties to: LocalService
Still I am getting the same error
|
|
|
|
|
I don't think you want it to run as localservice. I was set up a new user and password for that server with the correct rights on the computer to do what it needs to do.
Ben
|
|
|
|
|
Thanks Ben.
The Code works fine if I remove the 2 lines from the Start Method.
QuoteServer.QuoteServer quoteServer;
quoteServer=new QuoteServer.QuoteServer(@"C:\Documents and Settings\sumantar\Desktop\C#\C# Experiment\QuoteServer\quotes.txt",4567);
quoteServer.Start();
Even the start method is not having any thing
public void Start()
{
}
Without the above 2 lines the code works fine. When I put these lines, It gives error
|
|
|
|