Click here to Skip to main content
15,887,350 members
Home / Discussions / C#
   

C#

 
AnswerRe: print pdf file to network printer using printer IP address Pin
Hessam Jalali13-Aug-07 9:03
Hessam Jalali13-Aug-07 9:03 
GeneralRe: print pdf file to network printer using printer IP address Pin
There is always the way to do it, but I don't know14-Aug-07 17:27
There is always the way to do it, but I don't know14-Aug-07 17:27 
GeneralRe: print pdf file to network printer using printer IP address Pin
Hessam Jalali16-Aug-07 20:23
Hessam Jalali16-Aug-07 20:23 
QuestionPainting Reversible Rectangle Pin
T.D.Prasad13-Aug-07 7:03
T.D.Prasad13-Aug-07 7:03 
AnswerRe: Painting Reversible Rectangle Pin
Christian Graus13-Aug-07 8:19
protectorChristian Graus13-Aug-07 8:19 
QuestionRe: Painting Reversible Rectangle Pin
T.D.Prasad13-Aug-07 8:37
T.D.Prasad13-Aug-07 8:37 
AnswerRe: Painting Reversible Rectangle Pin
Luc Pattyn13-Aug-07 8:51
sitebuilderLuc Pattyn13-Aug-07 8:51 
QuestionRe: Painting Reversible Rectangle Pin
T.D.Prasad13-Aug-07 9:02
T.D.Prasad13-Aug-07 9:02 
Thanks for the reply. I cannot handle all the painting inside paint event handler, because reversible rectangles must be drawn inside mouse eventhandlers.

I am attaching all the code (although it is long), please let me know what modifications I have to make.

<br />
//<br />
// MainForm.cs - Demo shell application for the RubberbandRectangle class.<br />
// project created on 9/4/2003 at 11:43 PM by cthomas<br />
//<br />
<br />
using System;<br />
using System.Windows.Forms;<br />
using System.Drawing;<br />
<br />
namespace RubberbandShape<br />
{<br />
	class MainForm : System.Windows.Forms.Form<br />
	{<br />
		public MainForm()<br />
		{<br />
			InitializeComponent();<br />
        }<br />
	<br />
		// THIS METHOD IS MAINTAINED BY THE FORM DESIGNER<br />
		// DO NOT EDIT IT MANUALLY! YOUR CHANGES ARE LIKELY TO BE LOST<br />
		void InitializeComponent() {<br />
            this.button1 = new System.Windows.Forms.Button();<br />
            this.SuspendLayout();<br />
            // <br />
            // button1<br />
            // <br />
            this.button1.Location = new System.Drawing.Point(323, 256);<br />
            this.button1.Name = "button1";<br />
            this.button1.Size = new System.Drawing.Size(75, 23);<br />
            this.button1.TabIndex = 0;<br />
            this.button1.Text = "button1";<br />
            this.button1.UseVisualStyleBackColor = true;<br />
            this.button1.Click += new System.EventHandler(this.button1_Click);<br />
            // <br />
            // MainForm<br />
            // <br />
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
            this.AutoValidate = System.Windows.Forms.AutoValidate.EnablePreventFocusChange;<br />
            this.ClientSize = new System.Drawing.Size(401, 282);<br />
            this.Controls.Add(this.button1);<br />
            this.DoubleBuffered = true;<br />
            this.Name = "MainForm";<br />
            this.Text = "Rubber Band Shape Drawing";<br />
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.MainForm_Paint);<br />
            this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MainForm_MouseUp);<br />
            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MainForm_MouseMove);<br />
            this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MainForm_MouseDown);<br />
            this.ResumeLayout(false);<br />
<br />
		}<br />
			<br />
		[STAThread]<br />
		public static void Main(string[] args)<br />
		{<br />
			Application.Run(new MainForm());<br />
		}<br />
<br />
		private bool mouseDown = false;<br />
		private bool mouseMoving = false;<br />
		private bool haveRect = false;<br />
		private int XDown;<br />
		private int YDown;<br />
        private int oldX;<br />
        private Button button1;<br />
		private int oldY;<br />
<br />
		// The MouseDown event will be used to initialize the one corner<br />
		// of the RubberRectangle when the Left mouse button is down.<br />
		// If the Right mouse button is pressed and there is a<br />
		// RubberRectangle on the screen, it is erased.<br />
		void MainForm_MouseDown(object sender,<br />
		                       System.Windows.Forms.MouseEventArgs e)<br />
		{<br />
			if( e.Button == MouseButtons.Left )<br />
			{<br />
				mouseDown = true;<br />
				XDown = e.X;<br />
				YDown = e.Y;<br />
				mouseMoving = false;<br />
			}<br />
			else if( e.Button == MouseButtons.Right )<br />
			{<br />
				if( haveRect )<br />
				{<br />
					haveRect = false;	// Clear the flag<br />
					Invalidate();		// Clear out the rectangle.<br />
				}<br />
			}<br />
		}<br />
		<br />
		// The MouseMove event is used top acutally draw the rectangle<br />
		// after erasing to previously draw one if the mouse has moved since.<br />
		void MainForm_MouseMove(object sender,<br />
		                       System.Windows.Forms.MouseEventArgs e)<br />
		{            <br />
			if( mouseDown )<br />
			{<br />
                using (Graphics g = Graphics.FromHwnd(this.Handle))<br />
                {<br />
                    if (mouseMoving)<br />
                        RubberRectangle(g, XDown, YDown, oldX, oldY);<br />
                    RubberRectangle(g, XDown, YDown, e.X, e.Y);<br />
                    mouseMoving = true;<br />
                    oldX = e.X;<br />
                    oldY = e.Y;<br />
                }<br />
			}<br />
		}<br />
		<br />
		// Clears that flags that were used during drawing and sets a flag<br />
		//that indicates the presence of the rectangle.<br />
		void MainForm_MouseUp(object sender,<br />
		                     System.Windows.Forms.MouseEventArgs e)<br />
		{           <br />
			mouseDown = false;<br />
			mouseMoving = false;<br />
			haveRect = true;<br />
		}<br />
		<br />
		// Draws the RubberRectangle onto the client area using the<br />
		// RubberbandRectangle class.<br />
		private void RubberRectangle(Graphics g, int X1, int Y1, int X2, int Y2 )<br />
		{			<br />
			RubberbandRectangle rect = new RubberbandRectangle();<br />
			rect.DrawXORRectangle(g, X1, Y1, X2, Y2 );<br />
		}<br />
		<br />
		// Paints the test objects onto the client area.  If a RubberRectangle<br />
		// was there also, repaints that, too.<br />
		void MainForm_Paint(object sender,<br />
		                   System.Windows.Forms.PaintEventArgs e)<br />
		{<br />
<br />
            using (Graphics g = Graphics.FromHwnd(this.Handle))<br />
            {<br />
                g.Clear(this.BackColor);<br />
                if (haveRect)<br />
                {                    <br />
                    RubberRectangle(g, XDown, YDown, oldX, oldY);<br />
                }<br />
            }<br />
		}<br />
<br />
        private void button1_Click(object sender, EventArgs e)<br />
        {<br />
            MessageBox.Show("err yty");<br />
            this.Invalidate();<br />
        }        		<br />
	}	<br />
	<br />
	//*******************************************************<br />
    public enum PenStyles<br />
    {<br />
        PS_SOLID = 0,<br />
        PS_DASH = 1,<br />
        PS_DOT = 2,<br />
        PS_DASHDOT = 3,<br />
        PS_DASHDOTDOT = 4<br />
    }<br />
    public class RubberbandRectangle<br />
    {<br />
        // These values come from the larger set of defines in WinGDI.h,<br />
        // but are all that are needed for this application.  If this class<br />
        // is expanded for more generic rectangle drawing, they should be<br />
        // replaced by enums from those sets of defones.<br />
        private int NULL_BRUSH = 5;<br />
        private int R2_XORPEN = 7;<br />
        private PenStyles penStyle;<br />
        private int BLACK_PEN = 0;<br />
<br />
        // Default contructor - sets member fields<br />
        public RubberbandRectangle()<br />
        {<br />
            penStyle = PenStyles.PS_DOT;<br />
        }<br />
<br />
        // penStyles property get/set.<br />
        public PenStyles PenStyle<br />
        {<br />
            get { return penStyle; }<br />
            set { penStyle = value; }<br />
        }<br />
<br />
        public void DrawXORRectangle(Graphics grp,<br />
                                      int X1, int Y1, int X2, int Y2)<br />
        {<br />
            // Extract the Win32 HDC from the Graphics object supplied.<br />
            IntPtr hdc = grp.GetHdc();<br />
<br />
            // Create a pen with a dotted style to draw the border of the<br />
            // rectangle.<br />
            IntPtr gdiPen = CreatePen(penStyle,<br />
                          1, BLACK_PEN);<br />
<br />
            // Set the ROP cdrawint mode to XOR.<br />
            SetROP2(hdc, R2_XORPEN);<br />
<br />
            // Select the pen into the device context.<br />
            IntPtr oldPen = SelectObject(hdc, gdiPen);<br />
<br />
            // Create a stock NULL_BRUSH brush and select it into the device<br />
            // context so that the rectangle isn't filled.<br />
            IntPtr oldBrush = SelectObject(hdc,<br />
                                 GetStockObject(NULL_BRUSH));<br />
<br />
            // Now XOR the hollow rectangle on the Graphics object with<br />
            // a dotted outline.<br />
            Rectangle(hdc, X1, Y1, X2, Y2);<br />
<br />
            // Put the old stuff back where it was.<br />
            SelectObject(hdc, oldBrush); // no need to delete a stock object<br />
            SelectObject(hdc, oldPen);<br />
            DeleteObject(gdiPen);		// but we do need to delete the pen<br />
<br />
            // Return the device context to Windows.<br />
            grp.ReleaseHdc(hdc);<br />
        }<br />
<br />
        // Use Interop to call the corresponding Win32 GDI functions<br />
        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
        private static extern int SetROP2(<br />
                IntPtr hdc,		// Handle to a Win32 device context<br />
                int enDrawMode	// Drawing mode<br />
                );<br />
        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
        private static extern IntPtr CreatePen(<br />
                PenStyles enPenStyle,	// Pen style from enum PenStyles<br />
                int nWidth,				// Width of pen<br />
                int crColor				// Color of pen<br />
                );<br />
        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
        private static extern bool DeleteObject(<br />
                IntPtr hObject	// Win32 GDI handle to object to delete<br />
                );<br />
        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
        private static extern IntPtr SelectObject(<br />
                IntPtr hdc,		// Win32 GDI device context<br />
                IntPtr hObject	// Win32 GDI handle to object to select<br />
                );<br />
        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
        private static extern void Rectangle(<br />
                IntPtr hdc,			// Handle to a Win32 device context<br />
                int X1,				// x-coordinate of top left corner<br />
                int Y1,				// y-cordinate of top left corner<br />
                int X2,				// x-coordinate of bottom right corner<br />
                int Y2				// y-coordinate of bottm right corner<br />
                );<br />
        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
        private static extern IntPtr GetStockObject(<br />
                int brStyle	// Selected from the WinGDI.h BrushStyles enum<br />
                );<br />
<br />
        // C# version of Win32 RGB macro<br />
        private static int RGB(int R, int G, int B)<br />
        {<br />
            return (R | (G << 8) | (B << 16));<br />
        }<br />
    }<br />
}<br />
<br />

AnswerRe: Painting Reversible Rectangle Pin
Luc Pattyn13-Aug-07 9:14
sitebuilderLuc Pattyn13-Aug-07 9:14 
AnswerRe: Painting Reversible Rectangle Pin
Christian Graus13-Aug-07 8:55
protectorChristian Graus13-Aug-07 8:55 
QuestionRe: Painting Reversible Rectangle Pin
T.D.Prasad13-Aug-07 9:12
T.D.Prasad13-Aug-07 9:12 
QuestionHighlight Value on Tab Pin
Joemama6113-Aug-07 5:03
Joemama6113-Aug-07 5:03 
AnswerRe: Highlight Value on Tab Pin
Luc Pattyn13-Aug-07 5:38
sitebuilderLuc Pattyn13-Aug-07 5:38 
GeneralRe: Highlight Value on Tab Pin
Joemama6113-Aug-07 10:39
Joemama6113-Aug-07 10:39 
GeneralRe: Highlight Value on Tab Pin
Luc Pattyn13-Aug-07 10:52
sitebuilderLuc Pattyn13-Aug-07 10:52 
QuestionSQL connection timeout Pin
Demian Panello13-Aug-07 4:43
Demian Panello13-Aug-07 4:43 
AnswerRe: SQL connection timeout Pin
Justin Perez13-Aug-07 4:48
Justin Perez13-Aug-07 4:48 
GeneralRe: SQL connection timeout Pin
Demian Panello13-Aug-07 5:03
Demian Panello13-Aug-07 5:03 
GeneralRe: SQL connection timeout Pin
Justin Perez13-Aug-07 5:12
Justin Perez13-Aug-07 5:12 
GeneralRe: SQL connection timeout Pin
satsumatable13-Aug-07 6:35
satsumatable13-Aug-07 6:35 
QuestionHow to dump more than one row from table into the array !!!! please Help Pin
ANKUR2213-Aug-07 4:41
ANKUR2213-Aug-07 4:41 
AnswerRe: How to dump more than one row from table into the array !!!! please Help Pin
Justin Perez13-Aug-07 5:17
Justin Perez13-Aug-07 5:17 
AnswerRe: How to dump more than one row from table into the array !!!! please Help Pin
bit_cmdr13-Aug-07 6:50
bit_cmdr13-Aug-07 6:50 
QuestionDays of the week Pin
kibromg13-Aug-07 4:25
kibromg13-Aug-07 4:25 
AnswerRe: Days of the week Pin
Justin Perez13-Aug-07 4:32
Justin Perez13-Aug-07 4:32 

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.