|
Option 1 - Not good because what's stoping the user from stooping the service? Plus, you can change the system time without Windows even running.
Option 2 - The registry is a poor place to store information like that. It can be easily changed to reflect a date/time (if you store it as such).
It would be better to track how long your application has been in use. This means incrementing a counter for each minute that ticks by. You could then hide this value in a bogus .DLL file somewhere, preferrably encrypting the value before you write it to the file. Then just decrpyt it and start incrementing the value again the next time the app is started. This method has the advantage that it does rely on the system time at all.
After so many minutes, you just give a notification and quit.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I agree with you on what you wrote regarding to option 1 & 2.
But the solution you set forth is also not 100% satisfactory:
1) The marketing people want a solid expiry date, not one depending on the time it is used.
2) The whole encryption issue (also an issue when storing in the registry) is probablematic, since the encryption keys are stored on the machine of the user (remember, the app cannot rely on an internet connection). But the truth since it is .NET, one can just break the whole date verification out of the code, so that we have to take for granted.
Thanks anyway for your response. And let me know if you come up with some other solution.
Gidon
|
|
|
|
|
gnjunge wrote:
But the solution you set forth is also not 100% satisfactory:
And let me know if you come up with some other solution.
Marketings expectations are also outside the capabilities of Windows, or any OS for that matter. There is absolutely no way to guarantee that the system time your getting is accurate and no way to be reliably notified of any changes to the system clock. Sorry...
gnjunge wrote:
since the encryption keys are stored on the machine of the user
Yes, this is true. But not how you might think. There are a more than a few places in the registry to get an encryption key or salt for an algorithm, such as the SID for the Administrators account. This way, you don't have to store the key/salt yourself, it's already done for you, cleverly disguised as a useful part of the system.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks for the info. I will talk here with marketing.
|
|
|
|
|
Two Visual studio user interface questions: Reorder and collapse functions...
(Good abbreviation? )
The first question:
Is there any tool or inbuilt funcion in VS that reorders functions?
I got a 10 classes and each got a lot of funcs and data, but all derive from a special class, and thereby have the same funcs. It would be a lot easier to look at them if they where in the same order.
And the second question:
Is there any way to collapse only all functions?
Niklas Ulvinge aka IDK
|
|
|
|
|
Hi!,
I need to hook 456 port on my machine so that I get informed when a request comes for accessing my system using C#!!
Its urgent,please help!!
Thanks in advance
|
|
|
|
|
You'll probably want too look at TcpListner.
|
|
|
|
|
Thanks a lot,but i was not looking for this answer !!
|
|
|
|
|
I need to set a printer to the default system printer from within my application developed using C#, any ideas?
teeka
|
|
|
|
|
You need to get the default printer and set it to PrinterSetting.PrinterName i dont know managed way to get the default printer name but you can use unmaaged Windows API function like GetDefaultPrinter some thing like
[DllImport("winspool.drv", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool GetDefaultPrinter(StringBuilder pszBuffer, ref int size);
in some where in your code write
StringBuilder defaultPrinter = new StringBuilder(256);
int size = dp.Capacity;
if (GetDefaultPrinter(defaultPrinter, ref size))
{
printDocument.PrinterSettings.PrinterName=defaultPrinter;
}
For More info look at
GetDefaultPrinter^]
GetDefaultPrinter at MSDN[^]
I hope this help
MCAD
-- modified at 14:38 Sunday 11th September, 2005
|
|
|
|
|
Hi All,
I want to make interface like the one made in Visual Studio .NET 2005 "like its window : " which contain dockable forms and tabs.
I want an article illustrate this subject or example
Thanks
|
|
|
|
|
This[^] is a very good control that provides docking and collapsing, just like VS .NET.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hello
I am creating some relationships in code. I have 3 tables Position, Department, and Employee. The relationship is a one to many for these tables. See the details below.
PositionNames are manager, secretary etc
Position - PositionID (PK), PositionName
Department - DepartmentCode (PK), NameOfDepartment
Employee - EmployeeNo (PK), Name, Address, PositionID(FK), DepartmentCode(FK)
I have created a relation with the department and employee as follows:
<br />
DataColumn parentColumn = ds.Tables["Department"].Columns["DepartmentCode"]; <br />
DataColumn childColumn = ds.Tables["Employee"].Columns["DepartmentCode"]; <br />
<br />
ds.Relations.Clear(); <br />
dRelEmployees = new DataRelation("EmployeeDetails",parentColumn,childColumn); <br />
ds.Relations.Add(dRelEmployees); <br />
My problem is l want to add another parent column for the position, do l need to repeat all this code just for the position table. Or can l add another parentColumn and add them all to the dRelEmployees DataSet.
Not sure how to do this.
Thanks in advance,
Steve
|
|
|
|
|
As the relations are two separate relations, you have to add two separate DataRelaction objects to the Relations collection.
To create the second DataRelation object, you need a reference to the partent column and child column.
So, yes, it's most of that code all over again.
---
b { font-weight: normal; }
|
|
|
|
|
Please tell me how to go about taking an existing, working C# application and web enable it.
Rather than produce Windows output as it now does, I need to get it to produce output that can be accessed from a web browser. The output is very simple and contains no clever bits just text and two buttons, one to Print and one for Done.
Regards,
Alf Stockton
-- modified at 2:07 Sunday 11th September, 2005
|
|
|
|
|
Please don't double post.
---
b { font-weight: normal; }
|
|
|
|
|
Is it possible to add a placeholder to a datatable?
If so, how?
Thanks.
|
|
|
|
|
Can you give an example of what you are trying to do?
|
|
|
|
|
I am trying to make a class library that contains some drawing routines for example:
public GraphicsPath DrawRoundRect( Pen p, float X, float Y, float width, float height, float radius)
{
GraphicsPath gp=new GraphicsPath();
gp.AddLine(X + radius, Y, X + width - (radius*2), Y);
gp.AddArc(X + width - (radius*2), Y, radius*2, radius*2, 270, 90);
gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius*2));
gp.AddArc(X + width - (radius*2), Y + height - (radius*2), radius*2, radius*2,0,90);
gp.AddLine(X + width - (radius*2), Y + height, X + radius, Y + height);
gp.AddArc(X, Y + height - (radius*2), radius*2, radius*2, 90, 90);
gp.AddLine(X, Y + height - (radius*2), X, Y + radius);
gp.AddArc(X, Y, radius*2, radius*2, 180, 90);
gp.CloseFigure();
return gp;
}
The compiler doesn's know what GraphicsPath is so you add
using System.Drawing.Drawing2D;
Then the compiler says can resolve symbol Drawing.
Of course all works fine if you are in the applications main form.
How do I get around this problem?
|
|
|
|
|
Hello
Check, that you have added System.Drawing to your project references. Right-click on References folder of your project and select "Add Reference".
With best regards,
Andrew
|
|
|
|
|
I had added System.Drawing but being new to C# I had not added a reference.
Thank you very much.
|
|
|
|
|
I have a WinForm that contains a RectF. I have methods to draw inside the RectF as in, DrawLine(...).
I also have a bool flag in a try/catch block that throws up a MessageBox if the line params (they come from TextBoxes linked to Button events) are false.
Now here's the problem....
When I click the "OK" or the "x" on the MessageBox, the line(s) gets erased partially, based on where the MessageBox overlapped the line.
The RectF, the graph axes and labels all remain. What's up w/ that??
thanks....
Here's some of the code.....
////////////////////////////////////////////////////////////////////////
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
DrawGraphRectF(e.Graphics);
DrawXYAxes(e.Graphics);
DrawGraphXandYTicks(e.Graphics);
}
//Background "reference" rectangle
void DrawGraphRectF(Graphics g)
{
Pen rectPen = new Pen(Color.BlueViolet);
g.DrawRectangle(rectPen, xIndent, yIndent, graphRect.Width, graphRect.Height);
g.FillRectangle(new SolidBrush(Color.Snow), xIndent + 1, yIndent + 1, graphRect.Width - 1, graphRect.Height - 1);
rectPen.Dispose();
}
//Draw x and y axes.
void DrawXYAxes(Graphics g)
{
Pen axisPen = new Pen(new SolidBrush(Color.BlueViolet), 1);
g.DrawLine(axisPen, xIndent, yIndent + graphRect.Height/2, xIndent + graphRect.Width, yIndent + graphRect.Height/2);
g.DrawLine(axisPen, xIndent + graphRect.Width/2, yIndent, xIndent + graphRect.Width/2, yIndent + graphRect.Height);
axisPen.Dispose();
}
//Draw tick marks on the axes.
void DrawGraphXandYTicks(Graphics g)
{
Pen tickPen = new Pen(new SolidBrush(Color.Black), 1);
//Draw x-axis ticks and label graph.
float fxAxis = -8.0f;
float fyAxis = 8.0f;
PointF xtickPoint = new PointF(xIndent, yIndent + graphRect.Height/2);
PointF ytickPoint = new PointF(xIndent + graphRect.Width/2, yIndent);
Font labelFont = new Font("Courier",6);
SolidBrush labelBrush = new SolidBrush(Color.Black);
StringFormat strFmt = new StringFormat();
//Draw x axis ticks and float labels.
for(float fx = 2 * xtickPoint.X; fx <= graphRect.Width; fx += xtickPoint.X)
{
//string measureString = f.ToString("f1");
//float measureLength = measureString.Length;
if(fxAxis == 0.0f)
{
fxAxis += 1.0f;
fx += xtickPoint.X;
}
g.DrawLine(tickPen, fx, xtickPoint.Y - 2, fx, xtickPoint.Y + 2);
g.DrawString((fxAxis > 0? "+" : "" ) + fxAxis.ToString("f1"), labelFont, labelBrush, fx - 7, xtickPoint.Y + 7);
fxAxis++;
}
//Draw y-axis ticks and float labels.
for(float fy = 2 * ytickPoint.Y; fy <= graphRect.Height; fy += ytickPoint.Y)
{
if(fyAxis == 0.0f)
{
fyAxis -= 1.0f;
fy += ytickPoint.Y;
}
g.DrawLine(tickPen, ytickPoint.X - 2, fy, xtickPoint.Y + 2, fy);
g.DrawString((fyAxis > 0? "+" : "") + fyAxis.ToString("f1"), labelFont, labelBrush, ytickPoint.X + 5, fy - 3);
fyAxis--;
}
tickPen.Dispose();
}
private void complexA_OK_Click(object sender, System.EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen cmplxPen = new Pen(Color.Coral, 4);
//
try
{
bShowValue = true;
mValReal = Convert.ToDouble(this.textComplexAReal.Text);
mValComplex = Convert.ToDouble(this.textComplexAComplex.Text);
DrawComplexNumber(g,cmplxPen, mValReal, mValComplex);
bShowValue = false;
}
catch
{
MessageBox.Show("Invalid Complex A Number", "Error!");
}
}
private void complexB_OK_Click(object sender, System.EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen cmplxPen = new Pen(Color.Green, 4);
//
try
{
mValReal = Convert.ToDouble(this.textComplexBReal.Text);
mValComplex = Convert.ToDouble(this.textComplexBComplex.Text);
DrawComplexNumber(g, cmplxPen, mValReal, mValComplex);
}
catch
{
MessageBox.Show("Invalid Complex B Number", "Error!");
}
}
void DrawComplexNumber(Graphics g, Pen cmplxPen, double re_, double im_)
{
g.DrawLine(cmplxPen, (xIndent + graphRect.Width/2), (yIndent + graphRect.Height/2), (xIndent + graphRect.Width/2) + (float)(re_ * xIndent), (yIndent + graphRect.Height/2) - (float)(im_ * yIndent));
}
private void button1_Click(object sender, System.EventArgs e)
{
Invalidate();
}
}
}
|
|
|
|
|
This is happening because you're doing some drawing from a button click event. Thereis no code in your Paint event to redraw these objects when the form is told to repaint itself.
Your app must keep a "state" that contains everything the Paint event needs to know to redraw everything at any time, not just wehen you click a button on your form.
Think about this. You have a button on your form that when you click, you add a random line to the form. Now, if you drew the line from inside the Click event of the button, the line will only be drawn once, ever! If the form is overlayed by another app or form and then moved out of the way, the Paint event doesn't know anything about the line that was drawn, so it can't be redrawn when the form is repainted.
But, if you add the endpoints of the line to an array and your Paint event is coding to redraw the lines using the data in the array, there's no problem. If the lines get overlapped by another app or form, then the app or form is moved out of the way, the Paint event now knows how to redraw the lines.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I've asked this question a couple of time, but never seem to get any replies. I'm not sure if it's just because it's impossible to do or what, but I'm going to give it one more try.
Is there anyway in C# to be notified of changes in the time (i.e. the clock in the system tray). For example if I want to know when the time changes from 4:00 to 5:00 or when the minute changes. Is this possible at all?
Any bit of help will be very appreciated.
Thanks.
- Aaron
|
|
|
|
|
To be notified when time changed
add using Microsoft.Win32; use SystemEvents to subscribe to TimeChanged event some thing like
SystemEvents.TimeChanged +=new EventHandler(SystemEvents_TimeChanged);
and in your event handler
private void SystemEvents_TimeChanged(object sender, EventArgs e)
{
MessageBox.Show("Time Changed");
}
Know run your program and change your time message box Will be displayed
MCAD
|
|
|
|
|