|
Hi,
I just want to know when a constructor fires? I know it is when a class is instantiated.
I was working through code and they have a CSContext class. In it they have a property called Current, and it returns a CSContext instance. It also has 1 or 2 constructors.
So if I have the following piece of code, does it mean the constructor is fired?
CSContext context = CSContext.Current;
Please explain?
Regards
ma se
|
|
|
|
|
Hi,
CSContext.Current is propably public STATIC property and returns an instance may be created a time ago. During assignment no constructor is called. You should buy a book about C# or at least read about constructors in MSDN
Wizard_01
|
|
|
|
|
ma se wrote: I just want to know when a constructor fires? I know it is when a class is instantiated.
That's it. That is the only time a constructor is called.
ma se wrote: So if I have the following piece of code, does it mean the constructor is fired?
CSContext context = CSContext.Current;
It depends on what the "Current" property does. I'd imagine that it doesn't.
ma se wrote: Please explain?
A constructor is invoked when you instantiate a class. If the property instantiates a class then the constructor is called on the new object. If the property does not instantiate a class then the constructor is not called. It really is that simple.
If you have access to the source then you can see if the constructor is called or not. If not then the documentation should give some hints.
|
|
|
|
|
Hi all,
I have a datetimePicker control on my form.
The format of that dateTimePicker is CustomFormat ("MMMM yyyy") (January 2007)
However, I have faced a problem while using this Customformat.
If Today's date is 31st January 2007 and if I click the "Up Arrow" Button (to navigate to the February month), then I get an error "Year, Month, and Day parameters describe an unrepresentable DateTime".
This problem only occurs if the date is between 29th January and 31st January. On the contrary, if the current (today's) date is 28th January and if i press the "Up Arrow", I am not faced with that error
Please help
Thanking you in Advance
Pratik Shah
|
|
|
|
|
Seems the up arrow increments the month number and tries to leave the day number intact for you.
it works fine on my system (XP SP2, .NET 1.1 SP1).
Luc Pattyn
|
|
|
|
|
Hi,
Just to reconfirm.
Steps to reproduce
Change the system date is 01/31/2007 (31st January 2007)
The CustomFormat of the dateTimePicker should be "MMMM yyyy" (January 2007) and then try to click the "UP" arrow of the datetimepicker control (to move to the February month).
I have created a sample project and the error is being reproduced. Though my .net version is 2.0, so that could be a difference. As far as the OS goes, the version is same as yours.
Thanking you in Advance
Pratik Shah
|
|
|
|
|
Yes, that is what I did yesterday, as well as setting Format=Custom.
It worked, it moved from January 31 to February 28; when clicking down it went
back to January 28 (both when still "open", the result field went January 2007 ->
February 2007 -> January 2007.
I have now tried in on .NET 2.0 and once again it works fine.
I did not modify the system time (dont like to do that), but I used the arrow keys to
change the date picked by one day, and the arrow buttons to move it by one moth.
The keys make it move February 1 -> January 31 etc and the arrow buttons react as said before.
So everything seems OK to me.
If intersted, send me an e-mail and I attach my project to the reply.
Luc Pattyn
|
|
|
|
|
Hi,
Further to your reply, please find a sample project attached
However, to bring to your notice, I dont have .Net 1.1 with SP1, In fact I have .Net 2.0.
Also, this error is reproduced only if your PC(System) Date is 31st January 2007.
Apart from that, there is a property called "CustomFormat" of datetimePicker Control which has to set to "MMMM yyy"
Since CodeProject does not have any attachment faciliy, and neither I have your email address, I am attaching the code of the ".Designer.cs" in this reply itself. Just create a new project and paste this below code in the
newly created Form of the project
Regards
Pratik Shah
Code
Code in DateTimePicker.Designer.cs
namespace DateTimePicker
{
partial class DateTimePicker
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// <param name="disposing" />true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
this.SuspendLayout();
//
// dateTimePicker1
//
this.dateTimePicker1.CustomFormat = "MMMM yyy";
this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
this.dateTimePicker1.Location = new System.Drawing.Point(34, 12);
this.dateTimePicker1.Name = "dateTimePicker1";
this.dateTimePicker1.ShowUpDown = true;
this.dateTimePicker1.Size = new System.Drawing.Size(105, 20);
this.dateTimePicker1.TabIndex = 0;
//
// DateTimePicker
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(176, 87);
this.Controls.Add(this.dateTimePicker1);
this.Name = "DateTimePicker";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DateTimePicker dateTimePicker1;
}
}
|
|
|
|
|
With the "email" option (to the right of "reply") you can send me an email (without attachment).
Upon that, I can reply with attachment using my regular mail tools.
Luc Pattyn
|
|
|
|
|
Hi,
you are absolutely right, when ShowUpDown=true the look and behavior change,
and you can get an ArgumentOutOfRangeException; seems the DateTimePicker gets
initialized to DateTime.Now with all details (year, month, day, h, m, s) even
when only parts of it are used. And adding 1 month to 31-JAN throws.
(This is not a big surprise, there is no such thing as a partial DateTime,
and when you were to modify ShowUpDown to false again, you would hope to see
the current date, not something else...)
Obviously the workaround must be to modify the DateTimePicker.Value at LOAD time,
i.e. before the buttons can be activated. I would suggest:
myPicker.Value=new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
Luc Pattyn
|
|
|
|
|
Hello everyone,
I have made a basic windows form that I can draw on. The problem is that
when I resize the form the drawing disappears or gets clipped accordingly
how can I draw on the form and maintain the drawing even if I resize the form?
clear steps in a tutorial manner would be highly appreciated
thanks everybody for being there
|
|
|
|
|
You need to redraw it each time the window is damaged. You do this by overriding the OnPaint() method.
|
|
|
|
|
well sounds good but the code for drawing on the form is kept inside the MouseMove Event whenever it is fired it checks to see whether the left mouse button is pressed and then it draws according to the mouse movement.
The drawing is using the graphics object, let's say of a form or a panel on the form. How will the OnPaint method recognize the drawing?
I mean I get your point and it seems that it will work but can you explain a bit more?
|
|
|
|
|
You have to track all the drawing you do then when OnPaint fires recreate the drawing - if the form has changed size you can then rescale the drawing.
|
|
|
|
|
You really need an internal representation of your drawing.
You should build it up with mouse and/or keyboard events
and paint it in the OnPaint handler.
You then can also add file open and file save operations.
OnPaint is called automatically whenever there is a good reason to repaint the form or panel,
such as:
- form/panel became visible again (an overlapping form has been moved or closed)
- form gets resized (including form maximize, restore from minimize, restore from maximize)
- probably many more
- or you explicitly causing a repaint by calling Invalidate(), e.g. after you loaded a new file.
Luc Pattyn
|
|
|
|
|
Call Invalidate and pass it the region to be redrawn whenever you cause an event that needs to be drawn.
File Not Found
|
|
|
|
|
How in C# when I try to write over a file which another user has open do I find out their username so I can show it in a MessageBox?
TIA.
|
|
|
|
|
You have 2 people editing a file at the same time?
|
|
|
|
|
No, the application creates a PDF file - occasionally somebody might want to recreate the PDF file and even more occasionally somebody might already have the PDF file open - the chances of it happening are slim but if it does happen I would like to be able to display the username of the user who has the file open.
|
|
|
|
|
Why not just have a policy where users save the PDF to their local machine before opening? If they are viewing it via the web, send it via a stream, instead of the actual file.
|
|
|
|
|
What is the simpliest way to make a direct system call in managed C# (i.e. equivalent to system() function in C)?
I'm unable to find it on the internet..
|
|
|
|
|
If you'd like to call a function in the external library, you should look at DllImportAttribute and P/Invoke mechanism in .NET.
Wizard_01
|
|
|
|
|
No, I'd like to execute a shell command, for example 'chkdsk' or 'rm' or 'dir' (whatever). In the old ANSI C this was done by calling system(string) function from stdlib. I can't find a corresponding solution in .NET. If I have to, I will use P/Invoke to call system(...), but I don't know what library I have to import either (I don't think it is stdlib.dll..?).
|
|
|
|
|
I believe you want the System.Diagnostics.Process class.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
Have a look at the Process class.
For simple commands a simple Process.Start(string) will do.
Luc Pattyn
|
|
|
|