|
Thanks for the reply.
I did it. the original size of my image is 695x700. So I made a new bitmap with the dimension: width= (1200/96)*695 and height= (1200/96)*700. Here my printer's device dpi is 1200 and the screen resolution is 96. Actually I wanted to do this thing for printing the form with high quality. Cause with the screen resolution ( 96dpi ) the printer output is very poor.
But at that time while printing the new bitmap my printer stops responding and if I want to see the print preview window it shows an exception. I think it's totally uneffieicnt. Please tell me a way to print my form screenshot with a high quality in C#.
Code Snippet
Bitmap memoryImage;
Bitmap testImage;
Graphics gfxScreenshot;
private void CaptureScreen()
{
memoryImage = new Bitmap(this.Width-5,this.Height-100);
gfxScreenshot = Graphics.FromImage(memoryImage);
gfxScreenshot.CopyFromScreen(this.Location.X+5, this.Location.Y+100, 0, 0, this.Size, CopyPixelOperation.SourceCopy);
testImage = new Bitmap(memoryImage, 6950,7000);
testImage.SetResolution(1200,1200);
}
private void printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImageUnscaled(testImage, new Point(100, 100));
}
Thanks for the help...
|
|
|
|
|
I have no experience in printing using C# and/or any other programing language but this is the result of the search I had for you about the DocumentPrint the main class that makes you able to print using the .Net framework:
using System;
using System.IO;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
public class PrintingExample : System.Windows.Forms.Form
{
private System.ComponentModel.Container components;
private System.Windows.Forms.Button printButton;
private Font printFont;
private StreamReader streamToPrint;
public PrintingExample() : base()
{
InitializeComponent();
}
private void printButton_Click(object sender, EventArgs e)
{
try
{
streamToPrint = new StreamReader
("C:\\My Documents\\MyFile.txt");
try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler
(this.pd_PrintPage);
pd.Print();
}
finally
{
streamToPrint.Close();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line = null;
linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics);
while(count < linesPerPage &&
((line=streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count *
printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
count++;
}
if(line != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.printButton = new System.Windows.Forms.Button();
this.ClientSize = new System.Drawing.Size(504, 381);
this.Text = "Print Example";
printButton.ImageAlign =
System.Drawing.ContentAlignment.MiddleLeft;
printButton.Location = new System.Drawing.Point(32, 110);
printButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
printButton.TabIndex = 0;
printButton.Text = "Print the file.";
printButton.Size = new System.Drawing.Size(136, 40);
printButton.Click += new System.EventHandler(printButton_Click);
this.Controls.Add(printButton);
}
public static void Main(string[] args)
{
Application.Run(new PrintingExample());
}
}
I have found it in MSDN, you can try more searches.
Good luck and have fun.
Sojaner!
|
|
|
|
|
Hi everyone.
I want to download a whole website and trace whole web browser's request and response headers.
I guess that the only way to download the whole contents of a web page is using the WebBrowser class. But this class does not have any way to trace this request and responses!
Could anyone help please?
Sojaner!
|
|
|
|
|
Have a look at HttpRequest and HttpResponse; you don't always need a WebBrowser.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Thanx for your reply but I'm almost a pro in using the WebRequest and WebResponse but the fact is that the WebRequest can help you in tracing for 1 step only and for example if there is a <img> tag in the HTML you should find it and request it manually, it is not a problem for simple tags like <img> but the fact is that I want to trace the requests from a Flash Player's object and even if I load the swf file using the WebRequest, I will not have the access to the requests and responses that goes out and comes in to the Flash Player so I need a complete web browser with the full request and response ability!
Sojaner!
|
|
|
|
|
I have the following code:
double numdaysPercentage;
numdaysPercentage = 14/30;
I get an answer like 0.0. I should get an answer like .4666667
Can someone tell me what I am doing wrong.
|
|
|
|
|
If you divide by an int, you get an int.
double n = 14/30.0;
will work
or
double n = 14/(double)30;
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
You are doing integer division, and 14/30 is indeed 0. On the other hand, 14.0/30 will give you what you are looking for.
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
The suggestions above are good, you can also tag the numbers with an 'd' to indicate they are doubles. (Or 'f' for floats)
double n = 14d / 30d;
Simon
|
|
|
|
|
hello,
im having problem with the conversion from string to float, it works good when there is no character in string, for example :
string a = "1.22235647228796";
string b = "8.742277657e-008";
float a = Convert.ToSingle(a);
float b = Convert.ToSingle(b);
the first conversion will work but second will give error that "string was not is correct format"
any idea to solve it ?
thanks
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Always use float.TryParse for a start, so you don't get an exception. Not sure how you specify to accept that format, tho.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: Always use float.TryParse for a start
Not always. Sometimes an exception, due to a missed return value check, is in order. I would prefer an exception in certain instances.
Pits fall into Chuck Norris.
|
|
|
|
|
i didnt specify, when i read single from a file it automatically came, eg
BR.ReadSingle()
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Try using the NumberStyles enum in the System.Globalization namespace to parse that text.
float b = float.Parse(ExpNumString, NumberStyles.AllowExponent|NumberStyles.Float);
|
|
|
|
|
Hi all,
In my app i have 1 class call sqlconnection which is use for get/update db data. I am use this class to get dataset and after i edit the dataset i will pass back to this class and update it.Example, call sqlconnection method from formA to get and update database:
class sqlconnection:
private OleDbConnection objConn;<br />
private OleDbDataAdapter objAdapter = new OleDbDataAdapter();<br />
<br />
public void DbConnection()<br />
{<br />
objConn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=Userprogram.mdb");<br />
}<br />
<br />
public DataSet SelectSQL(String stable,String sProgramName)<br />
{<br />
DataSet ds=new DataSet();<br />
objConn.Open();<br />
objCmdSelecte = new OleDbCommand("Select * From Timeway where TW_Program_Name ='" + sProgramName + "'", objConn);<br />
<br />
objAdapter.SelectCommand = objCmdSelecte;<br />
objAdapter.Fill(ds);<br />
objConn.Close();<br />
return ds;<br />
}<br />
<br />
public void UpdateSQL(DataSet ds)<br />
{<br />
objConn.Open();<br />
objAdapter.Update(ds);<br />
objConn.Close();<br />
}
formA:
sqlconn.DbConnection();<br />
ds = sqlconn.SelectSQL("PS", "Program Ni");<br />
for (int i = 0; i < 16;i++ )<br />
{<br />
ArrayData[i] = ArrayTextbox[i].Text;
ds.Tables[0].Rows[0][i + 1] = ArrayData[i];<br />
}<br />
ds.AcceptChanges();<br />
sqlconn.UpdateSQL(ds);
The problem i am facing is , nothing change to my database.I have already check the dataset which is pass to my sqlconnection class and it have been modified. So what i guess is the problem of objAdapter.update . Can anyone guide me to solve this problem?
thanks in advance
cocoon
|
|
|
|
|
Hi all,
Thank you for those who are read through my question. I have found the solution , very simple, that is add a tablemapping.add() before fill and acceptchanges() and the end when update record.
regard
cocoon
|
|
|
|
|
Hello All,
How to compare two enum types?
Thanks
|
|
|
|
|
If you need to, then you should probably use the one enum in both cases.
you have two options:
1 - cast both to int, if you can make the int values correlate ( but then just use the one enum )
2 - write a method that applies whatever comparison rules you need, by hand.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
use the typeof(ur enum) with compare() method
|
|
|
|
|
How would that work, exactly ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Good question
i have put small exmaple here
public enum Named : int
{
A,
B,
C,
D
}
public enum Names : byte
{
A,
B,
C,
D
}
check
if (Enum.Equals(typeof(Named),typeof(Names)))
{
//type is equal
}
thanks you
|
|
|
|
|
OK - so does that compare based on enum name, or their intrinsic int value ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I seen your profile,your are MVP in code project, Are you checking me?
Basically Compare based on the type of the enum
You can understand from my example.
Thank you
|
|
|
|
|
No, I've never seen this before, I would think that comparing two different enums is a bad design, I'm curious how it would work.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
So
is it wrong? or is it can't be exist like that?
|
|
|
|