Click here to Skip to main content
16,004,833 members
Home / Discussions / C#
   

C#

 
AnswerRe: How can i focus a perticular cell in DataGrid control Pin
Heath Stewart10-Dec-03 3:08
protectorHeath Stewart10-Dec-03 3:08 
GeneralRe: How can i focus a perticular cell in DataGrid control Pin
KRathor10-Dec-03 4:34
KRathor10-Dec-03 4:34 
GeneralRe: How can i focus a perticular cell in DataGrid control Pin
Heath Stewart10-Dec-03 4:56
protectorHeath Stewart10-Dec-03 4:56 
GeneralRe: How can i focus a perticular cell in DataGrid control Pin
11-Dec-03 7:12
suss11-Dec-03 7:12 
GeneralRe: How can i focus a perticular cell in DataGrid control Pin
Heath Stewart11-Dec-03 8:53
protectorHeath Stewart11-Dec-03 8:53 
QuestionHow to Print a form with controls in C# Pin
pahluwalia9-Dec-03 11:35
pahluwalia9-Dec-03 11:35 
AnswerRe: How to Print a form with controls in C# Pin
Heath Stewart9-Dec-03 17:12
protectorHeath Stewart9-Dec-03 17:12 
AnswerRe: How to Print a form with controls in C# Pin
Ruchi Gupta10-Dec-03 7:39
Ruchi Gupta10-Dec-03 7:39 
/****
Here is a sample form with a Print button and couple of controls. When you hit print button, it prints the form with the controls and the contents if any on the control.

To check it, start a new C# windows aplication project and replace Form1.cs with following contents.

Things to be noted are :-
Functions:
btnPrint_Click
CaptureScreen
printDocument1_PrintPage
Objects and declaration
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;

private System.Drawing.Printing.PrintDocument printDocument1;

If u have any questions, let me know.
Ruchi
****/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication2
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;

private System.Windows.Forms.DateTimePicker dateTimePicker1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button btnPrint;
private System.Drawing.Printing.PrintDocument printDocument1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
this.textBox1 = new System.Windows.Forms.TextBox();
this.btnPrint = new System.Windows.Forms.Button();
this.printDocument1 = new System.Drawing.Printing.PrintDocument();
this.SuspendLayout();
//
// dateTimePicker1
//
this.dateTimePicker1.Location = new System.Drawing.Point(48, 72);
this.dateTimePicker1.Name = "dateTimePicker1";
this.dateTimePicker1.TabIndex = 0;
this.dateTimePicker1.ValueChanged += new System.EventHandler(this.dateTimePicker1_ValueChanged);
//
// textBox1
//
this.textBox1.BackColor = System.Drawing.SystemColors.Info;
this.textBox1.Location = new System.Drawing.Point(32, 128);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(160, 20);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// btnPrint
//
this.btnPrint.Location = new System.Drawing.Point(192, 216);
this.btnPrint.Name = "btnPrint";
this.btnPrint.TabIndex = 2;
this.btnPrint.Text = "Print";
this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
//
// printDocument1
//
this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnPrint,
this.textBox1,
this.dateTimePicker1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void showmessage()
{
MessageBox.Show("Testing 123");
}
private void dateTimePicker1_ValueChanged(object sender, System.EventArgs e)
{
//MessageBox.Show("Testing 123");
showmessage();
//System.Console.WriteLine("Testing 123");
}

private void CaptureScreen()
{
Graphics mygraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}
private void printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Font f = new Font("Arial",12);
e.Graphics.DrawString("Opetion Message if I want to be printed", f, Brushes.Black, 300, 50);
e.Graphics.DrawImage(memoryImage,75, 75);
}
private void btnPrint_Click(System.Object sender, System.EventArgs e)
{
CaptureScreen();
PrintDialog printDialog1 = new PrintDialog();
printDialog1.Document = printDocument1;


DialogResult result = printDialog1.ShowDialog();
if (result == DialogResult.OK)
{
printDocument1.Print();
}

//printDocument1.Print();
}
}
}

GeneralRe: How to Print a form with controls in C# Pin
pahluwalia12-Dec-03 3:13
pahluwalia12-Dec-03 3:13 
GeneralISynchronizeInvoke Pin
LokiSD9-Dec-03 9:20
LokiSD9-Dec-03 9:20 
GeneralRe: ISynchronizeInvoke Pin
Heath Stewart9-Dec-03 9:49
protectorHeath Stewart9-Dec-03 9:49 
GeneralImage Colour Depth Problem Pin
Tristan Rhodes9-Dec-03 7:20
Tristan Rhodes9-Dec-03 7:20 
GeneralRe: Accessing variables from the code behind page Pin
Heath Stewart9-Dec-03 6:34
protectorHeath Stewart9-Dec-03 6:34 
GeneralFileStream question Pin
Tim Kohler9-Dec-03 6:16
Tim Kohler9-Dec-03 6:16 
GeneralRe: FileStream question Pin
Heath Stewart9-Dec-03 6:53
protectorHeath Stewart9-Dec-03 6:53 
GeneralRe: FileStream question Pin
Tim Kohler9-Dec-03 7:17
Tim Kohler9-Dec-03 7:17 
GeneralRe: FileStream question Pin
Heath Stewart9-Dec-03 7:28
protectorHeath Stewart9-Dec-03 7:28 
GeneralRe: FileStream question Pin
Tim Kohler9-Dec-03 7:37
Tim Kohler9-Dec-03 7:37 
GeneralRe: FileStream question Pin
Tim Kohler10-Dec-03 3:54
Tim Kohler10-Dec-03 3:54 
GeneralCreating XML Documents Pin
MrEyes9-Dec-03 5:28
MrEyes9-Dec-03 5:28 
GeneralRe: Creating XML Documents Pin
MrEyes9-Dec-03 6:02
MrEyes9-Dec-03 6:02 
GeneralRe: Creating XML Documents Pin
Heath Stewart9-Dec-03 6:24
protectorHeath Stewart9-Dec-03 6:24 
Generallong path to short path Pin
elena123459-Dec-03 5:12
elena123459-Dec-03 5:12 
GeneralRe: long path to short path Pin
Heath Stewart9-Dec-03 6:20
protectorHeath Stewart9-Dec-03 6:20 
GeneralRe: long path to short path Pin
Stephane Rodriguez.9-Dec-03 21:24
Stephane Rodriguez.9-Dec-03 21:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.