|
That's one of the easiest errors to track down. One of the objects you're using is null. It's that simple.
Use the debugger to find out which one. You're getting this error because you're code is assuming that every property and method you're calling is returning an object. One or more of them returned null.
Step through the code line by line in the debugger and hover the mouse over each and every variable to see what it's value is.
|
|
|
|
|
You can set the development environment (Visual Studio) to break where the exception was originally throw (if it's re-thrown) by changing the following setting: "Debug->Exceptions..." and check the Thrown column for "Common Language Runtime Exceptions".
modified 12-Feb-22 21:01pm.
|
|
|
|
|
Goodmorning,
I would like to start my form having the mouse set in the form area (in any position is ok, but in the form) at the start.
Is it possible?
Thanks
|
|
|
|
|
Windows Forms? If so, just set MouseLocation to your desired location.
|
|
|
|
|
MouseLocation is it a proprties? of which object?
|
|
|
|
|
Yes - you have to work relative to the Form Location property, but it's pretty simple:
private void frmMain_Load(object sender, EventArgs e)
{
Cursor.Position = new Point(Location.X + 10, Location.Y + 10);
}
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
{
Point mid = new Point(Width / 2, Height / 2);
Cursor.Position = new Point(this.Left + mid.X, this.Top + mid.Y);
}
Happy Coding...
modified 3-Sep-19 21:02pm.
|
|
|
|
|
I’m developing a Window’s forms application for collecting and graphing historical data and utilizing a monthcalendar control that allows the user to select a day or range of days for graphing (MaxSelectionCount = 7). Additionally, since the user should never be selecting future dates, I have set the maxdate property to today (DateTime.Now).
Utilizing this configuration the user is allowed select any individual valid date (including today) without a problem, AND the user is allowed select any group of “previous” dates without a problem. However, the control will NOT allow the user to select a range of dates that includes today. Any ideas on why this doesn’t work???
I can even set the MaxDate to tomorrow (DateTime.Now.AddDays(1)) with similar results; However, setting MaxDate to the day after tomorrow (DateTime.Now.AddDays(2)) DOES allow the user to select a range including today… But it also lets them select a range of dates that includes tomorrow, and the day after tomorrow can be selected as an individual date…
Kip
|
|
|
|
|
The MaxDate property works up to the exact DateTime that you set: but DateTime.Now includes the hours, minutes and seconds - so setting MaxDate to it pretty much excludes the final date from a range as it has already passed (I think - I haven;t looked at the .NET code). What you need to do is set it to the end of day that you want to include:
myMonthCalendar.MaxDate = DateTime.Now.AddDays(1).Date.AddSeconds(-1); Should do it.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Or just use DateTime.Today.
|
|
|
|
|
You could, but you'd have to make it:
myMonthCalendar.MaxDate = DateTime.Today.AddDays(1).AddSeconds(-1);
DateTime.Today is midnight last night, which gives the same problem on it's own.
But it's tidier with Today, I'll admit!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Thank you for the quick replies! I went with the “DateTime.Today.AddDays(1).AddSeconds(-1)” solution. Works great; thanks again!
|
|
|
|
|
You're welcome!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
As we can't see your code, we have no way other than randomly guessing.
|
|
|
|
|
I don't randomly guess, I try it!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
how to add coding to send Encryption text via smtp mail and this is the code. thanks
private void SendMail_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
{
MessageBox.Show("Require, must content the row !!!");
}
else
try
{
obj_SMTPClient = new SmtpClient("smtp.gmail.com");
Obj_MailMsg = new MailMessage();
obj_Attachment = new System.Net.Mail.Attachment(textBox7.Text);
Obj_MailMsg.From = new MailAddress(textBox1.Text);
Obj_MailMsg.To.Add(textBox3.Text);
Obj_MailMsg.Body = textBox5.Text;
Obj_MailMsg.Attachments.Add(obj_Attachment);
Obj_MailMsg.Subject = textBox4.Text;
SmtpClient smtps = new SmtpClient("smtp.gmail.com", 587);
obj_SMTPClient.Credentials = new NetworkCredential();
obj_SMTPClient.Port = 587;
obj_SMTPClient.Credentials = new System.Net.NetworkCredential(textBox1.Text, textBox2.Text);
obj_SMTPClient.EnableSsl = true;
obj_SMTPClient.Send(Obj_MailMsg);
obj_SMTPClient.EnableSsl = true;
obj_SMTPClient.Send(Obj_MailMsg);
MessageBox.Show("Message Successfuly Sent!!!");
}
catch
{
MessageBox.Show("Failed to Send Message!!!");
}
}
private void EncryptionText_Click_1(object sender, EventArgs e)
{
cipherData = textBox6.Text;
plainbytes = Encoding.ASCII.GetBytes(cipherData);
desObj.GenerateKey();
desObj.GenerateIV();
desObj.Mode = CipherMode.CBC;
desObj.Padding = PaddingMode.PKCS7;
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms,
desObj.CreateEncryptor(),
CryptoStreamMode.Write);
cs.Write(plainbytes, 0, plainbytes.Length);
cs.Close();
cipherbytes = ms.ToArray();
ms.Close();
textBox5.Text = Encoding.ASCII.GetString(cipherbytes);
}
private void DecryptionText_Click_1(object sender, EventArgs e)
{
MemoryStream ms1 = new MemoryStream(cipherbytes);
CryptoStream cs1 = new CryptoStream(ms1,
desObj.CreateDecryptor(),
CryptoStreamMode.Read);
plainbytes = new Byte[cipherbytes.Length];
cs1.Read(plainbytes, 0, cipherbytes.Length);
cs1.Close();
ms1.Close();
textBox5.Text = Encoding.ASCII.GetString(plainbytes);
}
|
|
|
|
|
What's the problem?
That's just code without any explanation of the help you need.
Remember that we can't see your screen, access your HDD, or read your mind, so we only get what you tell us to work on.
Help us to help you!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
This is a small problem to sending text without attachment file, need your help me??
|
|
|
|
|
It'd probably be easier to tackle both problems separately; mailing a text and encrypting a text.
So, what's the problem with above code? Does it throw an exception? Does it encrypt?
If you're having trouble decrypting the text on another machine, then take in consideration that you're generating a new key
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yes, I will send encryption file using mail but code above only file attachment which sending. how to i adding the code to sending encrypt file without attachment. thanks
|
|
|
|
|
KaKoten wrote: how to i adding the code to sending encrypt file without attachment You're now encoding the text from "TextBox6", writing the result to "TextBox5". The contents of TextBox5 are written to the body, so I would expect it to encrypt the body.
If that works, then you'd only have to stop adding the attachment, and it would behave as requested.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
which only sending the attachment in this??
obj_Attachment = new System.Net.Mail.Attachment(textBox7.Text);
whereas which ignored by app is this and only side
Obj_MailMsg.Body = textBox5.Text;
how i add the code to sending only textbox5 which in encryption without attachment. thanks
|
|
|
|
|
KaKoten wrote: which only sending the attachment in this?? That line turns the content of the textbox into an attachment. Remove it if you're going to send mail without attachments.
KaKoten wrote: how i add the code to sending only textbox5 which in encryption without
attachment You don't need to add code to do that, only remove code. I assume that it IS encrypting the body correctly, and that you'd only want to remove the attachment.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
but I need the both without remove the both??
|
|
|
|
|
No, just the first
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|