|
|
hello...
I want to print some text, I have it in a RichTextBox!
I dont know how to do it...
However i tried this...
PrintPreviewDialog Print = new PrintPreviewDialog();
Print.Document = richTextBox1.Text;
Print.ShowDialog();
But it can't convert string to PringDocument!
I also tried....
PrintDocument preview = new PrintDocument();
PrintPreviewDialog Print = new PrintPreviewDialog();
Print.Document = preview ;
Print.ShowDialog();
then it works, but the paper is blank!
I don't know what else to do!
so please help me!
|
|
|
|
|
If you are using visual studio use the designer to add a PrintDocument object to your form.
In your function that calls the print event put the following
try<br />
{<br />
PrintPreviewDialog preview = new PrintPreviewDialog();<br />
preview.Document = printDocument1;<br />
preview.ShowDialog();<br />
if (preview.DialogResult == DialogResult.OK)<br />
printDocument1.Print();<br />
}
In the printDocument1.Print event (this can be created by ouble clicking the printDocument1 object in the designer) write the following code
e.Graphics.DrawString(richTextBox1.text, myFont, Brushes.Black,<br />
LeftMargin, YPosition, new StringFormat());
You will have to provide the values for myFont, LeftMargin and YPosition .
Hope this helps
KP
|
|
|
|
|
thanks it worked....
But do you know what the best LeftMargin and Yposition will be so it will print all the text?
My printer is currently broke so i can't test what would be best!
if U have time please write back else thanks anyway!
|
|
|
|
|
I've not reall y had much experience printing although my current project is going to require me to do quite a bit as soon as i overcome my current problem but i,ll try to help.
If you set LeftMargin equal to e.MarginBounds.Left
and Yposition equal to e.MarginBounds.Top
The printing will start in the top left corner of the page, taking into account any changes you make to the margins in the printPreviewDialog when it is displayed.
You may also have to write code to work out the number of lines on the page compared to how many lines your printing. If you get to the end of the page just set the e.HasMorePages = true and finish the printDocument.Print event, it will then start a new page (i think).
Sorry i can't give you any definate answers but like i said, i'm just starting to look into printing myself.
Hope you sort your problem.
KP
|
|
|
|
|
okay ill try it.... or else i wait to my printer works again!
Thanks!
|
|
|
|
|
With a bit of help from Heath Stewart i have a programme up and running with a datagrid, the first column of which is a check box.
What i now need is to be able to lock the grid down except for the check box column, I could just set each column to read only but this still allows the user to create new rows. New rows are added programatically and i need to restrict the user from doing this.
Any help you guys can give me would be appreciated.
Cheers
KP
|
|
|
|
|
I can't remember the exact details but you can do it with the dataview.allowNew method
|
|
|
|
|
Can you bind a DataView to a DataGrid even though the DataGrid is already bound to a DataSet?
If so, can anyone provide some code or a link to some for me?
Cheers
KP
|
|
|
|
|
Yes, just set DataGrid.DataSource to an instance of a DataView . This will bind the DataGrid to a DataView instead of the DataSet , but ultimately the DataSet (or DataTable ) is reflected by the DataView since the DataView is created on a DataTable within a DataSet .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for your help, i'll try it tomorrow when i get a chance.
KP
|
|
|
|
|
I'm doing a program in c# for a pocket-pc that has a "save as" dialog-box. When I execute it in the explorer, It's ok, but when I try to execute it in pocket-pc it doesn't work, in order to show the dialog-box only appears the text of the file. There is someone who can help me?
Thanks!!
This is the code:
private void Command3_Click(object sender, System.EventArgs e)
{
Response.ContentType="text/plain";
Response.AddHeader( "content-disposition","attachment; filename=Testa1.txt");
FileStream sourceFile = new FileStrea(@"C:\Inetpub\wwwroot\FitxIdatziWeb\Testa1.txt", FileMode.Open);
long FileSize;
FileSize = sourceFile.Length;
byte[] getContent = new byte[(int)FileSize];
sourceFile.Read(getContent, 0, (int sourceFile.Length);
sourceFile.Close();
Response.BinaryWrite(getContent);
}
|
|
|
|
|
You might want to change the ContentType to "application/octet-stream", but leave the "content-disposition" header in. Since the browser already knows how to render "text/plain" content, it won't ask you to save it. Changing it to "application/octet-stream" is about as generic as it gets and the browser should treat it as an unknown stream type.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I change the ContentType to "application/octet-stream", but it doesn't work. Maybe I must put Response.Buffer = true ; Response.Clear();and in the end Response.End(); but it doesn't work.
If I put Response.ContentType="text/salt+html"; I get a dialog box and download the file. But when I read the text,it is different, it has html format but anything of the original text. Thanks for the answer and sorry for my low level english.
|
|
|
|
|
I am using these lines, to avoid flicker in my program:
SetStyle(ControlStyles.UserPaint, true);<br />
SetStyle(ControlStyles.DoubleBuffer, true);<br />
SetStyle(ControlStyles.AllPaintingInWmPaint, true);<br />
<br />
private void timer1_Tick(object sender, System.EventArgs e)<br />
{<br />
Invalidate();<br />
}<br />
<br />
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)<br />
{<br />
Graphics g = e.Graphics;<br />
...<br />
}<br />
However, it dont work for panels, only for the main window, if i try like this:
private void timer1_Tick(object sender, System.EventArgs e)<br />
{<br />
panel1.Invalidate();<br />
}<br />
<br />
private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)<br />
{<br />
Graphics g = e.Graphics;<br />
...<br />
}<br />
It there a simple way to make panels flicker free?
|
|
|
|
|
I wonder where you have written these lines of code:
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
If you created your custom panel, so it should work flicker free.
My Weblog
|
|
|
|
|
custom panel?
I just drag a panel from the toolbox.
The lines a placed in the constructor.
|
|
|
|
|
That's why it's not flicker free. You should make a custom panel, which derives from Panel control, and then you just need to add those lines of code in the constructor of your custom panel. After compiling and adding it to your form, it will work flicker free.
This article may help you:
Flicker free drawing using GDI+ and C#[^]
My Weblog
|
|
|
|
|
To note, it's much faster to use
SetStyle(ControlStyles.AllPaintingInWmPaint<br />
| ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true); . This results in fewer calls since all three enumerations are OR'd together at compile time. That's what the FlagsAttribute allows on an enumeration like ControlStyles (all enumerations denoting plurality in the .NET FCL typically have the FlagsAttribute ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
the problem is here:
<br />
string currentPath;<br />
<br />
private void frmPicture_Load(object sender, System.EventArgs e)<br />
{<br />
currentPath = @"D:\Image\1.jpg";<br />
this.pictureBox1.Image = Image.FromFile(currentPath);<br />
}<br />
<br />
private void updateButton_Click(object sender, System.EventArgs e)<br />
{<br />
if (File.Exists(currentPath))<br />
{<br />
string newPath = Application.StartupPath + @"\PatientImages\" + arrISN[index].ToString() + ext;<br />
this.pictureBox1.Image = null;<br />
File.Copy(currentPath, newPath, true);<br />
}<br />
}<br />
Error: the process cannot access the file "D:\.." because it is being used by another process.
what can i do to correct this problem.
thanks.
Rock Throught The Night
|
|
|
|
|
I assume it's the File.Copy line that throws the error?
Out of interest, you've not got the picture your copying open in another application have you?
KP
|
|
|
|
|
i known the error is File.Copy line but i cannot find out the to correct it.
please help me again
thanks
Rock Throught The Night
|
|
|
|
|
I have just tried the code with some adjustments for my file structure and it works fine. The only difference between my code and yours is the newpath string, i set mine to @"c:\golfball2.bmp" and when i clicked the update button i got a copy of golfball.bmp called golfball2.bmp.
I assume the problem is that the destination for your file is currently being used by another application, or even by your application. Try hard coding the newPath string to @"c:\test.jpg" . If that works then you will have to look at where your trying to write the copy to.
Let me know how you get on.
KP
|
|
|
|
|
the " currentPath " and the newPath is the same Folder and the " currentFileName " and "newFileName" is the same too
so the error occur.
Rock Throught The Night
|
|
|
|