|
The Bitmap class really has nothing to do with bmp files - it's an in-memory representation that is based on pixels (hence the name)
If you call Save on it then the ImageFormat parameter will determine the file type (and with that I mean the actual contents of the file, not the file extension)
If you call Save without an ImageFormat it will end up as a PNG image, easily identifiable by the ‰PNG at the beginning. I think that might be what you did..
|
|
|
|
|
It's a bitmap. That means it's an image, not a BMP. There is no JPEG class, you specify you want the JPEG format, and save the bitmap from the Bitmap class.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I'm looking at some code like this (sorry for the formatting):
public static OracleDataReader GetDynamicQueryReader (
OracleConnection con,
string sql,
out string msg)
{
sql = Regex.Replace(sql, @"\s+", " ");
try
{
using(OracleCommand cmd = new OracleCommand(sql, con))
{
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
msg = "Successful";
return dr;
}
}
catch (Exception ex)
{
msg = ex.Message;
con.Close();
return null;
}
}
This little chunk (not mine) is called several thousand times, and from the profiler I am using it is the generation of a new OracleCommand object costing the most. And this object can have its parameters set after instantiation.
Normally I would make this a static, but since I am supposed to instantiate it with a using statement to deal with the disposal of unmanaged references, Im not sure I can. Can I? If I determine that there are no memory leaks with a profiler by creating and disposing some unmanaged reference, can I safely make this static? Or should I really just put up with the poor performance?
|
|
|
|
|
using and static are incompatible. In fact, if it's static, there's only ever one, and it will be disposed of when your app closes, which means there is no issue.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I create one instance of a Command as a field of a class and then re-use it as needed. I don't worry about disposing it.
|
|
|
|
|
hi friends
i want to use a one richtextbox and one webbrowser instead of a html/text editor because i dednt find any editor control that can be used in windows application,
i try to change "DocumentText" property of webBrowser control and set it with richtextbox value when user press specify button but in first time below code works correctly but in next times this property of webBrowser has not changed!!! do u know why? please tell me the solution
webBrowser1.DocumentText = richTextBox1.Text;
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
Hello Mr. Mohsen,
I replied to your original post.
but you should use the WebBrowser.Document.Body.InnerHtml to set the HTML of the document.
|
|
|
|
|
oh no man i test your code and the result is like previouse code
in other hand both code have same result and in first time work correctly and in next times does not work
please check it to understand the problem
thank you
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
This is very strange because i just created a new project and am not experiencing your issue.
here is the sample code from my windows forms test.
public class Form1 : Form<br />
{<br />
<br />
private System.ComponentModel.IContainer components = null;<br />
<br />
protected override void Dispose(bool disposing)<br />
{<br />
if (disposing && (components != null))<br />
{<br />
components.Dispose();<br />
}<br />
base.Dispose(disposing);<br />
}<br />
<br />
#region Windows Form Designer generated code<br />
<br />
private void InitializeComponent()<br />
{<br />
this.webBrowser1 = new System.Windows.Forms.WebBrowser();<br />
this.button1 = new System.Windows.Forms.Button();<br />
this.textBox1 = new System.Windows.Forms.TextBox();<br />
this.button2 = new System.Windows.Forms.Button();<br />
this.SuspendLayout();<br />
this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Bottom;<br />
this.webBrowser1.Location = new System.Drawing.Point(0, 127);<br />
this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);<br />
this.webBrowser1.Name = "webBrowser1";<br />
this.webBrowser1.Size = new System.Drawing.Size(461, 257);<br />
this.webBrowser1.TabIndex = 0;<br />
this.button1.Dock = System.Windows.Forms.DockStyle.Top;<br />
this.button1.Location = new System.Drawing.Point(0, 0);<br />
this.button1.Name = "button1";<br />
this.button1.Size = new System.Drawing.Size(461, 23);<br />
this.button1.TabIndex = 1;<br />
this.button1.Text = "button1";<br />
this.button1.UseVisualStyleBackColor = true;<br />
this.button1.Click += new System.EventHandler(this.button1_Click);<br />
this.textBox1.Location = new System.Drawing.Point(22, 30);<br />
this.textBox1.Name = "textBox1";<br />
this.textBox1.Size = new System.Drawing.Size(377, 20);<br />
this.textBox1.TabIndex = 2;<br />
this.button2.Location = new System.Drawing.Point(0, 56);<br />
this.button2.Name = "button2";<br />
this.button2.Size = new System.Drawing.Size(461, 23);<br />
this.button2.TabIndex = 3;<br />
this.button2.Text = "button2";<br />
this.button2.UseVisualStyleBackColor = true;<br />
this.button2.Click += new System.EventHandler(this.button2_Click);<br />
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);<br />
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;<br />
this.ClientSize = new System.Drawing.Size(461, 384);<br />
this.Controls.Add(this.button2);<br />
this.Controls.Add(this.textBox1);<br />
this.Controls.Add(this.button1);<br />
this.Controls.Add(this.webBrowser1);<br />
this.Name = "Form1";<br />
this.Text = "Form1";<br />
this.Load += new System.EventHandler(this.Form1_Load);<br />
this.ResumeLayout(false);<br />
this.PerformLayout();<br />
<br />
}<br />
<br />
#endregion<br />
<br />
private System.Windows.Forms.WebBrowser webBrowser1;<br />
private System.Windows.Forms.Button button1;<br />
private System.Windows.Forms.TextBox textBox1;<br />
private System.Windows.Forms.Button button2;<br />
<br />
<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
this.webBrowser1.Navigate("about:blank");<br />
}<br />
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
this.webBrowser1.Document.Body.InnerHtml += "<br />Clicked!";<br />
}<br />
<br />
private void button2_Click(object sender, EventArgs e)<br />
{<br />
this.webBrowser1.Document.Body.InnerHtml += "<br />" + this.textBox1.Text;<br />
}<br />
}
All i did was add the WebBrowser control the form, i then added 2 buttons and a textbox.
when the user clicks the button "Clicked!" is appended to the text when they click the other button the text in the text box is inserted.
If you want to test it just add a new class your existing project and paste all the sample code in there then set it as your startup object.
|
|
|
|
|
thank you my friend
your code work correctly
the problem is i didnt call navigate methode of webBrowser with about:blank value parameter
thank you very mutch
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
Guess I should have mentioned that.
Well good to hear you got it working.
|
|
|
|
|
Hey All,
I am experiencing a strange issue, i have built and tested my RegEx in Expresso but when I call it from my code (C#) I am not getting any matches. If i step through and grab the values from the variables and put those in Expresso it works ....
RegEx:
Lead\sID\sNumber:\s*(?<LeadNumber>[^\r\n]*)(?:\r\n)+<br />
Prospect\sName:.*(?:\r\n)+<br />
Prospect\sContact:.*(?:\r\n)+<br />
Prospect\sPhone:.*(?:\r\n)+<br />
Marketing\sCampaign:.*(?:\r\n)+<br />
Prospect\sInformation:\s*(?:\r\n)+<br />
===============\s(?:\r\n)+<br />
(?<Company>[^\r\n]*)(?:\r\n)+<br />
(?<Address1>[^,]*),\s(?<Address2>[^\r\n]*)(?:\r\n)+<br />
(?<City>[^,]*),\s(?<State>[^\r\n]*)(?:\r\n)+<br />
(?<Country>[^,]*),\s(?<Zip>[^\r\n]*)(?:\r\n)+<br />
Contact\sName:\s*(?<FirstName>[^\s]*)\s(?<LastName>[^\r\n]*)(?:\r\n)+<br />
Contact\sPhone:\s*(?<Phone>[^\r\n]*)(?:\r\n)+
C#:
<br />
MatchCollection myMatches = Regex.Matches([Text], [RegEx], RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace | RegexOptions.CultureInvariant);<br />
[Text] = the body of an email
[RegEx] = the above pattern
Any input or ideas would be greatly appreciated.
|
|
|
|
|
If you can provide some sample text that this Regex should match, it might help.
|
|
|
|
|
Thank you for you reply,
Here is a sample of the text to match.
<br />
Lead Overview: <br />
=========== <br />
Lead ID Number: 1234567 <br />
Prospect Name: Some Prospect<br />
Prospect Contact: Some Contact<br />
Prospect Phone: 1234567890 <br />
<br />
Marketing Campaign: Marketing Campaign Example<br />
<br />
Prospect Information: <br />
=============== <br />
Company Name<br />
Address1, Address2 <br />
New York, NY <br />
United States, 12345 <br />
<br />
Contact Name: Some Contact <br />
Contact Phone: 1234567890 <br />
Company Email: contact@email.com <br />
|
|
|
|
|
Your regex works fine. It is finding the match.
string sMatch = @" Lead Overview:
===========
Lead ID Number: 1234567
Prospect Name: Some Prospect
Prospect Contact: Some Contact
Prospect Phone: 1234567890
Marketing Campaign: Marketing Campaign Example
Prospect Information:
===============
Company Name
Address1, Address2
New York, NY
United States, 12345
Contact Name: Some Contact
Contact Phone: 1234567890
Company Email: contact@email.com";
bool IsMatchFound = Regex.IsMatch(sMatch, @"Lead\sID\sNumber:\s*(?<LeadNumber>[^\r\n]*)(?:\r\n)+Prospect\sName:.*(?:\r\n)+Prospect\sContact:.*(?:\r\n)+Prospect\sPhone:.*(?:\r\n)+Marketing\sCampaign:.*(?:\r\n)+Prospect\sInformation:\s*(?:\r\n)+===============\s(?:\r\n)+(?<Company>[^\r\n]*)(?:\r\n)+(?<Address1>[^,]*),\s(?<Address2>[^\r\n]*)(?:\r\n)+(?<City>[^,]*),\s(?<State>[^\r\n]*)(?:\r\n)+(?<Country>[^,]*),\s(?<Zip>[^\r\n]*)(?:\r\n)+Contact\sName:\s*(?<FirstName>[^\s]*)\s(?<LastName>[^\r\n]*)(?:\r\n)+Contact\sPhone:\s*(?<Phone>[^\r\n]*)(?:\r\n)+");
|
|
|
|
|
Hello D@nish,
First of all i would like to thank both you and Riced.
I have found the solution to my problem and its still kinda strange.
There was actually two problems;
- for some strange reason I cant declare my RegEx string using a literal (using @ when assiging the string) if the literal spans multiple lines, for some reason this is messing with my RegEx.
Which is why i guess in your example its working.
- the emails are being retrieved from Exchange via WebDAV and for some strange reason line breaks are only coming back as '\n' not '\r\n' like they should. So if I do a .Replace("\n","\r\n") on the body everything works fine.
I guess this wasnt a problem for your in your example because the email body was assigned as a literal and therefore had the "proper" line breaks (\r\n)
Thanks again for your help guys, i never would have found this without your help.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Great!!!
|
|
|
|
|
Instead of doing a string.Replace, you could also change (?:\r\n)+ to [\r\n]+ , which should match any kind of newline
|
|
|
|
|
I assume that you are setting some variable (e.g. myRE) to the regex string.
Are you using a verbatim string i.e. myRE = @"Lead....(\r\n)+" or just doing myRE = "Lead...(\r\n)+" ?
I think it should be a verbatim string otherwise \ is interpreted before Regex.Matches sees it.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Thank you for your reply.
Yes it is "Verbatum" assinged using @
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Just noticed that there's no test for "===========" after the Lead line.
Is that the problem?
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Hi David,
You are right, nice catch.
However that shouldn't effect the matching.
Now I did solve my problem, look above for the solution.
Thanks for your help.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
hi friends
i need a html editor for my application
but i didnt find. i have some editor base on web application but no one can use in windows application
do u know a html editor that can use in c# application(windows base)?
please help me
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
Do you want to create html file or HTML help files with .chm extension? Please verify that!
I calculate my days on earth..... approximately 55 years remaining for me to expire
|
|
|
|
|
Hello,
You should take a look at the DesignMode property of the WebBrowser Control.
If you switch it to "on" it turns the WebBrowser Control into a WYSISYG (What You See Is What You Get) editor.
Then you can get the HTML from the WebBrowser Control.
Check out this great article on how to use the WebBrowser Control
Using the WebBrowser control in .NET[^]
|
|
|
|