|
Ranger49 wrote: The advice I got here is basically not to try to take too big steps in your learning process.
Absolutely right - But it is also important not to learn bad habits because it takes longer to unlearn them that it did to learn them in the first place.
Ranger49 wrote: I am a little bit embarrassed to run into problems which are so simple if you know how to solve it.
To reiterate what Pete said, don't be embarrased. If you feel too embarrassed and don't want your friends or colleagues to see what you've posted set up a second account and post under a psudonym if you prefer.
|
|
|
|
|
Ranger49 wrote: But that if my program won't work because Visual C# 2005 Express Edition cannot handle it, then you really have a problem as a beginner!
The express edition can run any C# code. That is not the problem
Ranger49 wrote: So now I have just one error left during compiling. Still my program won't run!
So, you post your code with a statement explaining the error, and what you're trying to achieve.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Christian Graus wrote: The express edition can run any C# code
That is really nice to hear! And lets face it, express edition wouldn't be any good if it didn't.
It is all a matter of me being a newbe.
About the error message that the compiler handed me, I cut and pasted it into the search/how do I? help line in express edition, and I got the impression that this particular error wasn't listed in the help database. If it had been I probably wouldn't have needed to post in this forum...
Ranger.
Beginner
|
|
|
|
|
All questions are answered here as long as you show that you have made an effort to find a solution yourself. Posts that include existing code fragments are often answered.
Post that as people to do the work for you are usually ignored.
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Text;
namespace Operator3
{
class Matrix
{
double a11;
double a12;
double a13;
double a14;
double a21;
double a22;
double a23;
double a24;
double a31;
double a32;
double a33;
double a34;
double a41;
double a42;
double a43;
double a44;
public Matrix(double Ina11, double Ina12, double Ina13, double Ina14, double Ina21, double Ina22, double Ina23, double Ina24, double Ina31, double Ina32, double Ina33, double Ina34, double Ina41, double Ina42, double Ina43, double Ina44)
//this method should make an instance of the class Matrix, instead I get the error message that the name Matrix is the same as the name of the class so that it isn't allowed. I haven't got a clue why this doesn't compile!
{
this.a11 = Ina11;
this.a12 = Ina12;
this.a13 = Ina13;
this.a14 = Ina14;
this.a21 = Ina21;
this.a22 = Ina22;
this.a23 = Ina23;
this.a24 = Ina24;
this.a31 = Ina31;
this.a32 = Ina32;
this.a33 = Ina33;
this.a34 = Ina34;
this.a41 = Ina41;
this.a42 = Ina42;
this.a43 = Ina43;
this.a44 = Ina44;
}
public static Matrix operator *(Matrix M1, Matrix M2)
{
// the compiler doesn't seem to have a problem here
return new Matrix(
//kolom 1
M1.a11 * M2.a11 + M1.a21 * M2.a12 + M1.a31 * M2.a13 + M1.a14 * M2.a14,
M1.a12 * M2.a11 + M1.a22 * M2.a12 + M1.a32 * M2.a13 + M1.a24 * M2.a14,
M1.a13 * M2.a11 + M1.a23 * M2.a12 + M1.a33 * M2.a13 + M1.a34 * M2.a14,
M1.a14 * M2.a11 + M1.a24 * M2.a12 + M1.a34 * M2.a13 + M1.a44 * M2.a14,
//kolom 2
M1.a11 * M2.a21 + M1.a21 * M2.a22 + M1.a31 * M2.a23 + M1.a14 * M2.a24,
M1.a12 * M2.a21 + M1.a22 * M2.a22 + M1.a32 * M2.a23 + M1.a24 * M2.a24,
M1.a13 * M2.a21 + M1.a23 * M2.a22 + M1.a33 * M2.a23 + M1.a34 * M2.a24,
M1.a14 * M2.a21 + M1.a24 * M2.a22 + M1.a34 * M2.a23 + M1.a44 * M2.a24,
//kolom 3
M1.a11 * M2.a31 + M1.a21 * M2.a32 + M1.a31 * M2.a33 + M1.a14 * M2.a34,
M1.a12 * M2.a31 + M1.a22 * M2.a32 + M1.a32 * M2.a33 + M1.a24 * M2.a34,
M1.a13 * M2.a31 + M1.a23 * M2.a32 + M1.a33 * M2.a33 + M1.a34 * M2.a34,
M1.a14 * M2.a31 + M1.a24 * M2.a32 + M1.a34 * M2.a33 + M1.a44 * M2.a34,
//kolom 4
M1.a11 * M2.a41 + M1.a21 * M2.a42 + M1.a31 * M2.a43 + M1.a14 * M2.a44,
M1.a12 * M2.a41 + M1.a22 * M2.a42 + M1.a32 * M2.a43 + M1.a24 * M2.a44,
M1.a13 * M2.a41 + M1.a23 * M2.a42 + M1.a33 * M2.a43 + M1.a34 * M2.a44,
M1.a14 * M2.a41 + M1.a24 * M2.a42 + M1.a34 * M2.a43 + M1.a44 * M2.a44);
}
}
public class Vector
{
double v1, v2, v3, v4;
public Vector(double v1, double v2, double v3, double v4)
//This won't compile, why won't this method just create an instance of the class Vector?
{
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
this.v4 = v4;
}
public static Vector operator *(Matrix M, Vector V)
{
return new Vector(
M.a11 * V.v1 + M.a12 * V.v2 + M.a13 * V.v3 + M.a14 * V.v4,
M.a21 * V.v1 + M.a22 * V.v2 + M.a23 * V.v3 + M.a24 * V.v4,
M.a31 * V.v1 + M.a23 * V.v2 + M.a33 * V.v3 + M.a34 * V.v4,
M.a41 * V.v1 + M.a24 * V.v3 + M.a43 * V.v3 + M.a44 * V.v4);
}
}
class Program
{
static void Main(string[] args)
{
Matrix M = new Matrix(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0);
Vector V = new Vector(1.0, 0.0, 0.0, 0.0);
}
}
}
//This version is really my 2nd attempt of making a class that defines and multiplies matrices and vectors. So I am a newbe. Please give me some advice.
Beginner.
|
|
|
|
|
Your code compiles just fine for me, using Studio 7.1
Luc Pattyn
|
|
|
|
|
Hi there,
Your code compiles for me on VS2005 Professional. Note, I had to make two changes:
1. "class Matrix" should be "public class Matrix" since the Vector class is public, and the * operator is public and returns a Matrix. The default protection level of a class, if none is specified, is "protected". This resulted in an inconsistent protection level - the Vector * operator was public, but the object it returned is protected.
2. I had to make all the doubles in the Matrix class public, so that the Vector class could access them to do the multiplication.
|
|
|
|
|
Patrick Sears wrote: Note, I had to make two changes
Thanks a lot! I can now get it compiled without any errors!
All this is caused by my inexperience I think...
But that I try to log all lessons I learn so that I won't make the same mistake twice!
Ranger
Beginner
|
|
|
|
|
Hi
I have a little problem.
I'm saving a picture that I captured from a camera to a file like this:
string path = "c:\\DisplayPicture.bmp";<br />
<br />
pictureBoxSavedPicture.Image.Save(path);<br />
<br />
this.Close();<br />
and after that I close the form and return to the main form.
The thing is that I can save the file only once and on the second time that I try to do the same code above, I get an external exception:
A generic error occurred in GDI+.
I was told that I have to realese resources but that didn't help.
Sombody knows what is the reason for this exception?
|
|
|
|
|
place the picturebox into a stream, save from the stream, then release the picturebox.
|
|
|
|
|
Yes, "A generic error occurred in GDI+." is a very popular result; it is unfortunate GDI+
most often isnt more specific.
In your case something went wrong saving the file, my guess is as long as your image is
alive, your file will be "in use" (I know this is true when you use Image.FromFile),
so you can not overwrite it.
You can try to dispose the image which means your picturebox must leave it alone too.
Better is to try ed's stream suggestion.
Luc Pattyn
|
|
|
|
|
The bitmap is tricky with file locks. Use a stream. Dispose of said stream when done. Also, use different file names and delete them when finished.
GUIDs are your friend.
File Not Found
|
|
|
|
|
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?
|
|
|
|
|