|
hi there,
i ve a problem in setting DPI in print document, everytime when i click on the button it shows "600 600", but i ve set it 1200 in pageSetupDialog.
here is codes
private void button3_Click(object sender, EventArgs e)
{
PageSetupDialog psd = new PageSetupDialog();
psd.Document = printDocument1;
psd.ShowDialog();
printDocument1.DefaultPageSettings = psd.PageSettings;
printDocument1.PrinterSettings = psd.PrinterSettings;
printDocument1.Print();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
MessageBox.Show(e.Graphics.DpiX.ToString() + " " + e.Graphics.DpiY.ToString());
}
thanks
<div class="ForumSig">Becoming Programmer...</div>
|
|
|
|
|
I don't think you can set the DPI of your printer, it's simply a property of the printer. Instead, you need to scale your image to be the right size to print for that DPI at the size you want.
Christian Graus - Microsoft MVP - C++
"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 )
|
|
|
|
|
oh, i cant resize my image, actually when i print text in black then its result is good, but when print in light gray or gray the result is bad, lots of dots can be seen,
Printer : HP LaserJet 1020 plus
do you know a good solution?
thanks
Becoming Programmer...
|
|
|
|
|
Hi everybody!
I have a DataTable which has 3 column. First column has type int, the second double, and the third is the product of the first and the second column.
How can i set the third column that the values in it have only 2 decimals after the decimal point?
DataTable dt = new DataTable("test_table");
dt.Columns.Add("column1",typeof(int));
dt.Columns.Add("column2",typeof(double));
dt.Columns.Add("column3",typeof(string),"column1*column2");
dt.Rows.Add(new object[] { 1, 5 });
dt.Rows.Add(new object[] { 2, 4,994 });
dt.Rows.Add(new object[] { 3, 6 });
dataGridView1.Columns.Clear();
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = dt;
dataGridView1.Columns.Add(new DataGridViewTextBoxColumn());
dataGridView1.Columns[0].DataPropertyName = "column1";
dataGridView1.Columns.Add(new DataGridViewTextBoxColumn());
dataGridView1.Columns[1].DataPropertyName = "column2";
dataGridView1.Columns.Add(new DataGridViewTextBoxColumn());
dataGridView1.Columns[2].DataPropertyName = "column3";
Ex: in the second row the third column expression is 2*4,994 = 9,988 but i want that only 9,98 be the value.
I need this because the user can add rows to the datagridview and i want that also in the added rows to function this.
Thanks for your help!
|
|
|
|
|
Hi Noemi Katinka!
Use Math functions. It will round up the values upto given decimal point.
Like Math.Round(ProductAnswer,2)
Hope this will help you.
Regards.
"Save water,It's precious"
|
|
|
|
|
It depends on the rounding you require.
Math.Round does a strange thing, eg:
Math.Round(3.565m, 2).ToString();
Math.Round(3.575m, 2).ToString();
I always use
decimal x = 3.565m;
x.ToString("N2");
as the results are more consistant, trailing digit of 0-4 rounds down and 5-9 rounds up.
For no rounding as in
Noemi Katinka wrote: 9,988 but i want that only 9,98
you need a little function like
public string TrimDecimal(decimal value, int precision)
{
precision++;
string returnString = value.ToString();
int decimalPointPosition = returnString.IndexOf(".");
if (decimalPointPosition > -1)
{
if (returnString.Length > (decimalPointPosition + precision))
{
return returnString.Substring(0, decimalPointPosition + precision);
}
}
return returnString;
}
modified on Thursday, February 07, 2008 4:36:38 AM
|
|
|
|
|
This is called Bankersrounding
DaveyM69 wrote: It depends on the rounding you require.
Math.Round does a strange thing, eg:
// using ToString method because the value is being displayedMath.Round(3.565m, 2).ToString(); // rounds down to 3.56Math.Round(3.575m, 2).ToString(); // rounds up to 3.58
Ohter option = String x = String.Format("{0:9.990,00}", value.ToString());
|
|
|
|
|
Thanks for your idea.
But i resolved it in the following mode:
double d = 9.999 - 0.005;
Console.WriteLine(d.ToString("0.00"));
and this gives me the result 9.99 (what i need).
And when you need a double value with 1 decimal(no rounded) just substract 0.05, and so on for all numbers.
Have a nice day!
|
|
|
|
|
Has anyone worked on how to read the barcode output from the barcode reader.
The barcode reader produces its output in the notepad.
But i want to get the output and then format it.
Kindly suggest on this issue.
|
|
|
|
|
well, at least for the barcode readers i know:
if you scan a specific barcode, the reader just emulates some
keyboard input and the textual representation of the barcode
you scanned gets inserted into the textbox that has focus.
you could even create a console application, do some Console.Read()
and can then do whatever you want with the string representing
the barcode.
so it's up to your imagination!
|
|
|
|
|
Hi All :
I wount to restore DataBase Backup (BackupName.bak) from Device ( C:\ ) to SQL SERVER 2005 with new Name (NewBackupName) by C#.Net Code .
You should to Remmember the Name of ( mdf and ldf ) is defferant of name other backup database , if it the same (mdf and ldf ) name of other Database you should rename file mdf and ldf .
Who I Can do it ?
Thanks for any body hellp me
Thaer
|
|
|
|
|
Thaer Hamael wrote: You should to Remmember the Name of ( mdf and ldf ) is defferant of name other backup database
I dont think so. if you have the .Bak file , you can easily restore to SQL Server 2005 easily using C#
any problem !!! you can ask me
|
|
|
|
|
thanks Mr Abhijit Jana ,
I do it But the Restore Exeption occure by the exeption String the ldf and mdf is Using by other DataBase .
the idea in this case is who to rename the ldf and mdf .
who i can do it ?
thanks Abhijit Jana
Thaer
|
|
|
|
|
can you put the code of restoring over here ?
|
|
|
|
|
hi
My aim is to close a socket which is already open
Socket.close() is raising exception i have tried with few other things still its not closing properly
So if any one knows how to do this then plz do let me know
regards
sindhu tiwari
its me sid
|
|
|
|
|
Are you calling the ShutDown() method before you make a call to Close() ?
|
|
|
|
|
thanks for replying
......................will u plz tell me what this ShutDown() does
I would like to brief my problem ..
I am having a mobile application ......so if the mobile switches off i need to close the socket at my end ........
can u tell me the best way to do this .....apart from pinging it continously
its me sid
|
|
|
|
|
sindhutiwari wrote: will u plz tell me what this ShutDown() does
Read it from MSDN[^]
|
|
|
|
|
Hi Sid,
Dear I am also working on socket application. Try this statement "objSock.Shutdown(SocketShutdown.Both);"
|
|
|
|
|
hi Akmal
Dear,Thanks for ur reply .....i have tried that too ..it dint work perfectly...with my application
as u r also working on socket application
will u plz tell me how you are determining the status of client i mean to say connected or disconnected ......u r following two way pinging or any other thing plz do let me know
its me sid
|
|
|
|
|
Dear Sid,
I am using this piece of code in thread.It tells me when client is connected and send data to me.
Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, 8001);
listener.Bind(endpoint);
listener.Blocking = true;
listener.Listen(0);
Socket objSock = listener.Accept();
objSock.Receive(ReceiveData);
objSock.Shutdown(SocketShutdown.Both);
listener.Close();
S.Akmal
|
|
|
|
|
dear Sid.
did u try the socket.connected property. It returns a boolean value either u r connected or disconnected.
Mr.Syed
|
|
|
|
|
I want to close the Client Socket ....Not the Listner(Server) how u r handeling Client Socket and Socket.Connected returns the previous state
its me sid
|
|
|
|
|
Send me the Exception text on socket.close().
S.Akmal
|
|
|
|
|
static void Main()
{
Application.Run(new Form1());
}
private System.Windows.Forms.GroupBox grpbox;
XPathDocument dom;
XmlDocument doc;
XPathNavigator nav;
XPathExpression expr;
XPathNodeIterator iterator;
int cnt=0;
Label lbl;
TextBox txt;
OpenFileDialog dlg;
TreeNode newTreeNode,rootnode,parentnode;
string text;
int i;
//int cnt = e.Node.GetNodeCount(false);
//string filename;
private void Form1_Load(object sender, System.EventArgs e)
{
//label1.Text = "File Path";
//label1.SetBounds(8, 8, 50, 20);
//filename = Application.StartupPath + "\\Sample.xml";
//textBox1.Text= filename;
//textBox1.SetBounds(64, 8, 256, 20);
button1.Text = "Populate the TreeView with XML";
button1.SetBounds(8, 20, 200, 20);
treeXml.Height = 600;
treeXml.Width = 400;
grpbox = new GroupBox();
grpbox.Height = 600;
grpbox.Width = 400;
grpbox.SetBounds(500, 2, 700, 600);
grpbox.Visible = true;
grpbox.Dock.Equals(Right);
grpbox.Show();
this.Controls.Add(grpbox);
//dom = new XPathDocument(dlg.FileName);
}
// it will acess the xml file into treeview
private void ConvertXmlNodeToTreeNode(XmlNode xmlNode,
TreeNodeCollection treeNodes)
{
TreeNode newTreeNode = treeNodes.Add(xmlNode.Name);
switch (xmlNode.NodeType)
{
case XmlNodeType.ProcessingInstruction:
case XmlNodeType.XmlDeclaration:
newTreeNode.Text = "<?" + xmlNode.Name + " " +
xmlNode.Value + "?>";
break;
case XmlNodeType.Element:
if (xmlNode.Name.ToLower().Equals("node") == true)
{
newTreeNode.Text = "<" + xmlNode.Attributes["label"].Value.ToString() + ">";
}
else
newTreeNode.Text = "<" + xmlNode.Name + ">";
break;
case XmlNodeType.Attribute:
newTreeNode.Text = xmlNode.Name;
// newTreeNode.Text = "ATTRIBUTE: " + xmlNode.Name;
break;
case XmlNodeType.Text:
case XmlNodeType.CDATA:
newTreeNode.Text = xmlNode.Value;
break;
case XmlNodeType.Comment:
newTreeNode.Text = "<!--" + xmlNode.Value + "-->";
break;
}
if (xmlNode.Attributes != null)
{
foreach (XmlAttribute attribute in xmlNode.Attributes)
{
ConvertXmlNodeToTreeNode(attribute, newTreeNode.Nodes);
}
}
foreach (XmlNode childNode in xmlNode.ChildNodes)
{
ConvertXmlNodeToTreeNode(childNode, newTreeNode.Nodes);
}
}
// this is an event on which text box is created...
private void treeXml_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
cnt = e.Node.GetNodeCount(false);
grpbox.Controls.Clear();
for ( i = 0; i < cnt; i++)
{
Label lbl= new Label();
TextBox txt = new TextBox();
//lbl.Name="lbl"+i;
//lbl.Text="lbl"+i;
lbl.Text = e.Node.Text+i;
txt.Name="txt"+i;
txt.Text=txt.Name;
//txt.Text=e.Node.Text+i;
lbl.Left = 200;
lbl.Top = 200 * i;
txt.Left = 250;
txt.Top = 200 * i;
lbl.Show();
txt.Show();
grpbox.Controls.Add(txt);
grpbox.Controls.Add(lbl);
}
}
// this will open an6y xml file stored at your pc.
private void button1_Click(object sender, System.EventArgs e)
{
XmlDocument doc = new XmlDocument();
OpenFileDialog dlg = new OpenFileDialog();
treeXml.Nodes.Clear();
dlg.Title = "Open XML File";
dlg.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*" ;
if (dlg.ShowDialog() == DialogResult.OK)
{
//imgPhoto.Image = new Bitmap(dlg.OpenFile());
doc.Load(dlg.OpenFile());
}
dlg.Dispose();
ConvertXmlNodeToTreeNode(doc, treeXml.Nodes);
treeXml.Nodes[0].ExpandAll();
}
// insert a node
on this button click i want to a node in tree and thje value or string which is in the text box should add to the new treenode....
but this is not wornking,
private void button2_Click(object sender, System.EventArgs e ,TextBox txt)
{
TreeNode rootnode = treeXml.Nodes[0];
TreeNode parentnode = rootnode.Nodes[0];
newTreeNode = new TreeNode(txt.Text);
treeXml.SelectedNode.Nodes.Add(newTreeNode);
// if( treeXml.SelectedNode != null
parentnode = treeXml.SelectedNode;
parentnode.Nodes.Add(new TreeNode(txt.Text));
}
plz help me in this code.
modified on Thursday, February 07, 2008 1:30:10 AM
|
|
|
|