|
+5
Small addition: If you catch Exceptions to log them or to do anything else that doesn't include mitigating the error, re-throw the exeption at the end of the catch-Block, either with "throw;" to re-throw the exact same Exception or by throwing a custom Exception and providing the original Exception as an InnerException to the constructor. See here: Anti-Patterns and the Solutions[^] especially the part "Error Hiding Anti-Pattern".
|
|
|
|
|
I would think hard before even trying to put a try ... catch block "inside" a foreach loop.
Exception handling can be expensive. If you were looping "thousands" of times, that would potentially mean "thousands" of exceptions.
An exception "inside" a loop, generally doesn't happen just once because the data / processing requirements are usually similar.
(IMO) One generally wraps a loop "inside" a try ... catch block; not the other way around; in which case, to "continue or not" is a non-issue. Repeated exceptions in a loop are a symptom of bigger problems that should be solved; not just "handled".
Exceptions are for "exceptions"; not general error handling.
|
|
|
|
|
In catch, continue will automatically work so no need to add the keyword there.
hi
|
|
|
|
|
But it is still a very bad (stupid) thing to do.
|
|
|
|
|
If one does not include the "continue" then execution will continue after the catch-block, not at the start of the loop.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Apart from what ever has been answered it is a good practice to catch the general exception also. In both the catch blocks you have to do 2 things log an exception as well as Display the exception to the user.
But my suggestion is if you can avoid exceptions that would be even better so have proper checks where ever required like null check etc etc.
|
|
|
|
|
i have been supplied with a public key as text and need to encrypt data using this in c sharp before sending via an http post. i am using RSACryptoServiceProvider to try and do this but i obviously cannot use the FromXmlString method as the public key is not in that format. can you help. the public key is attached
the key is
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArwPRGxD31m9GoCucD8tU
OPvacmS9J93Oj5b8OsLEzeTYgvgPnGOej3pOfU9MFtN7XZTMQvGtFapdOLe7xX3B
q7bQEXJZQalUgaGMUikKvekw3rmfPUYzKu9TW1w4SJzlqp4DTZ2Qb7M1S7XI2a2B
dK47NmW3x6squnVDVoVmcdCwSW6U3bQOKlhKLdVzvT8i0dGnswrgcI7JzvdujdsR
qycx6N+NqlKxzMZ7iQLT2/x5PQFN1pRLPc07pRq9vwPyOxLYeq+CnYklAXw1/GIo
uv4mn7dQ2ljOkExFgPi98+dQ1h5kUk63bh9RsvtT4oGuoR/3Lr37kffQZse8io5U
dQIDAQAB
-----END PUBLIC KEY-----
|
|
|
|
|
Don't post the same question in two places - all you will do is duplicate work and annoy people. Pick either the C# forum or the Q&A and stick with it.
Annoyed people are less likely to be helpful than happy ones...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
How to Crop Pdf page and save as image in c# winforms ?
Please help me to crop pdf file and save as image with coordinate in c# windows application ...?
modified 4-Jul-22 21:01pm.
|
|
|
|
|
What have you done so far? What have you used to render the PDF to an image? Where, exactly, are you stuck?
It's important to remember that we can't see your code so we don't know what you've done or where you are having problems.
|
|
|
|
|
hi all,
i saw in this link:
https://msdn.microsoft.com/en-us/library/system.windows.forms.splitcontainer.orientation(v=vs.110).aspx
how to vertical container
my question is: how i do when i click iin button opened duplicate form but vertical???
thanks for all the helpers
|
|
|
|
|
Your question is not clear.
Creating a new Form is one task.
Creating a new Form and inserting a SplitContainer Control in it with 'Vertical orientation is another task.
Duplicating a Form ... creating a new version of a design-time specified Form ... is another possible Task.
Please describe exactly what you want to achieve.
«To kill an error's as good a service, sometimes better than, establishing new truth or fact.» Charles Darwin in "Prospero's Precepts"
|
|
|
|
|
i have a mdi form name "Main".
the mdi form include 1 form with container horenzial name "Sub"
i want to do a button on the Main form that open the "Sub" form as a new winform (not in mdi) and the container be a vertical
sorry on my bad English.
thank you
|
|
|
|
|
First, I'd define a public Property on your 'sub Form that allowed me to set and get the SplitContainer's 'Orientation property:
public Orientation CurrentSplitterOrientation
{
set { splitContainer1.Orientation = value; }
get { return splitContainer1.Orientation; }
} I'd use a public Property because I'd assume that I would want access the current value of 'Orientation, as well as set it.
In the Main MDI Form, you can "release" the MdiChildForm by setting its 'MdiParent property to 'null:
private SubForm1 subForm1 = new SubForm1();
private void Form1_Load(object sender, EventArgs e)
{
subForm1.MdiParent = this;
subForm1.Show();
}
private void button1_Click_1(object sender, EventArgs e)
{
subForm1.MdiParent = null;
subForm1.CurrentSplitterOrientation = Orientation.Vertical;
} I'd like to suggest you consider the following:
1. MDI architecture is now really out-dated, and if you have the choice, I suggest you don't use it.
2. Putting any Control on the MDI Parent Form itself, except maybe a ToolStripMenu, is generally a bad idea.
3. Changing a Form's status from being an 'MdiChildForm to being "just another" Form on the Desktop is ... well ... unusual. This may be confusing to your end-users. You might consider, instead of an MDI Parent to Child relationship, using the 'Owner property of the secondary Form ... set it to the Main Form, instead. A Form which has an 'Owner is guaranteed to remain in front of its'Owner Form.
«To kill an error's as good a service, sometimes better than, establishing new truth or fact.» Charles Darwin in "Prospero's Precepts"
|
|
|
|
|
thank you again..
its not working..
i just want to duplicate the MDI CHILD
on:
test frm = new test();
frm.show();
and do it verticl just on the "outside" form - not on the mdi child
|
|
|
|
|
i have a string like this 2+4 ,(s[0]=2,s[1]=+,s[2]=4).
how can i get 2, 4 from it ?
|
|
|
|
|
your question needs a bit more refinement before anyone can attempt to answer it
for example, I see 3 x '2's and 2 x '4's in your 'string' - which ones do you need?
if for example you want the '2' and '4' from this '2+4', is the '+' a constant/does it change & what are the values ?
knowing exactly which 2 & 4 and what may change in that string might help someone give you an answer
|
|
|
|
|
Please don't cross-post. You already got answers in the Q&A forum.
|
|
|
|
|
Hi,
I am using the following code to generate a bitmap:
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(panelControl1.Width, panelControl1.Height);
panelControl1.DrawToBitmap(bmp, panelControl1.ClientRectangle);
I would like t ask how can I embed the bmp in my MailMessage's email body?
Thanks,
Jassim[^]
Technology News @ www.JassimRahma.com
|
|
|
|
|
It would need to be encoded and part of a MIME message[^]. Also part of .NET[^] and I'm sure CodeProject has some articles on the subject too.
Try this; send yourself an email and open in outlook. Now right-click and select "view source".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
There's an example here[^].
There's also an example of creating attachments from a stream[^]. (The LinkedResource class works in a similar way.)
Combining the two would give you something like this:
using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress("me@mycompany.com");
mail.To.Add("you@yourcompany.com");
mail.Subject = "This is an email";
AlternateView plainView = AlternateView.CreateAlternateViewFromString("This is my plain text content, viewable by those clients that don't support html", null, "text/plain");
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("<p>Here is an embedded image: <img src=\"cid:myimage\"></p>", null, "text/html");
MemoryStream stream = new MemoryStream();
theImage.Save(stream, ImageFormat.Jpeg);
stream.Seek(0L, SeekOrigin.Begin);
LinkedResource imageResource = new LinkedResource(stream, MediaTypeNames.Image.Jpeg);
imageResource.ContentId = "myimage";
htmlView.LinkedResources.Add(imageResource);
mail.AlternateViews.Add(plainView);
mail.AlternateViews.Add(htmlView);
SmtpClient smtp = new SmtpClient("127.0.0.1");
smtp.Send(mail);
}
You just need to make sure that each embedded resource has a ContentId which is unique within the message, and refer to the resource within the view as cid:ContentId .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
When a hidden form was shown again, after I clicked on the Cancel button in the form, the change in the TextBox of the form was kept.
I am new in C#. Any advise will be appreciated.
modified 10-Mar-15 11:52am.
|
|
|
|
|
Your program needs to respond to the Cancel button event and actually do something.
|
|
|
|
|
The application does not "remember" the previous value; you'd have to write that. Save the content of the textbox when you show it, and overwrite it with that value when the cancel-event fires.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Are you showing the "hidden" Form using 'ShowDialog ? ... or ? More details, please.
«To kill an error's as good a service, sometimes better than, establishing new truth or fact.» Charles Darwin in "Prospero's Precepts"
|
|
|
|