Click here to Skip to main content
15,912,457 members
Home / Discussions / C#
   

C#

 
GeneralRe: Regex problem Pin
leppie23-Dec-04 8:10
leppie23-Dec-04 8:10 
GeneralRe: Regex problem Pin
Yaakov Davis23-Dec-04 8:50
Yaakov Davis23-Dec-04 8:50 
GeneralQuestion about efficiency - Hashtable key types Pin
Tristan Rhodes23-Dec-04 6:28
Tristan Rhodes23-Dec-04 6:28 
GeneralRe: Question about efficiency - Hashtable key types Pin
leppie23-Dec-04 7:42
leppie23-Dec-04 7:42 
GeneralRe: Question about efficiency - Hashtable key types Pin
Tristan Rhodes23-Dec-04 9:57
Tristan Rhodes23-Dec-04 9:57 
GeneralRe: Question about efficiency - Hashtable key types Pin
Matt Gerrans23-Dec-04 11:47
Matt Gerrans23-Dec-04 11:47 
Questionhow to get mirror printing using c# Pin
bigmega23-Dec-04 5:32
bigmega23-Dec-04 5:32 
AnswerRe: how to get mirror printing using c# Pin
Heath Stewart23-Dec-04 8:16
protectorHeath Stewart23-Dec-04 8:16 
In your even thandler for the PrintDocument.PrintPage event (or override of OnPrintPage if extending PrintDocument, which is usually a good idea for encapsulation) you need to apply a transformation matrix to the Graphics object by assigning the identity matrix to the Graphics.Transform property (the world transform) with either M11 or M22 negated to flip on the y-axis or x-axis, respectively.

For example:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
class FlipExample : Form
{
  static void Main()
  {
    Application.Run(new FlipExample());
  }
 
  RectangleF left;
  RectangleF right;
  PointF[] triangle;
  StringFormat format;
  Matrix flipTransform;
 
  FlipExample()
  {
    Text = "Flip Example";
    SetStyle(ControlStyles.AllPaintingInWmPaint |
      ControlStyles.DoubleBuffer | ControlStyles.ResizeRedraw |
      ControlStyles.UserPaint, true);
 
    format = StringFormat.GenericDefault;
    format.Alignment = StringAlignment.Center;
 
    OnResize(EventArgs.Empty);
  }
 
  void DrawCaption(Graphics g, RectangleF r, string caption)
  {
    g.DrawString(caption, Font, SystemBrushes.ControlText,
      r, format);
  }
 
  void DrawTriangle(Graphics g, RectangleF r, bool flip)
  {
    if (flip)
    {
      g.Transform = flipTransform;
      g.TranslateTransform(r.X, 0f, MatrixOrder.Append);
    }
    else
    {
      // Reset to the identity transform.
      g.ResetTransform();
    }
 
    g.FillPolygon(SystemBrushes.ControlText, triangle);
  }
 
  protected override void OnPaint(PaintEventArgs e)
  {
    base.OnPaint(e);
 
    Graphics g = e.Graphics;
 
    DrawCaption(g, left, "Normal");
    DrawCaption(g, right, "Flipped and Translated");
 
    DrawTriangle(g, left, false);
    DrawTriangle(g, right, true);
  }
 
  protected override void OnResize(EventArgs e)
  {
    float halfWidth = Width / 2f;
    float halfFont = Font.Height / 2f;
 
    left = new RectangleF(0f, 0f, halfWidth, (float)Height);
    right = new RectangleF(halfWidth, 0f, halfWidth, (float)Height);
 
    // Negate M11 to rotate along the y-axis.
    flipTransform = new Matrix(-1,0,0,1,halfWidth,0);
 
    triangle = new PointF[] {
      new PointF(halfWidth, halfFont),
      new PointF(halfWidth, (float)Height
        - SystemInformation.CaptionHeight - halfFont * 2f),
      new PointF(0f, Height / 2f)};
 
    base.OnResize(e);
  }
}


This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralWindows Installer Problem Pin
Asad Hussain23-Dec-04 5:13
Asad Hussain23-Dec-04 5:13 
GeneralRe: Windows Installer Problem Pin
Heath Stewart23-Dec-04 5:19
protectorHeath Stewart23-Dec-04 5:19 
GeneralRe: Windows Installer Problem Pin
leppie23-Dec-04 7:49
leppie23-Dec-04 7:49 
GeneralRe: Windows Installer Problem Pin
Heath Stewart23-Dec-04 7:54
protectorHeath Stewart23-Dec-04 7:54 
Generalfatal error CS0013: Unexpected error writing metadata to file Pin
Divick23-Dec-04 4:34
Divick23-Dec-04 4:34 
GeneralRe: fatal error CS0013: Unexpected error writing metadata to file Pin
Heath Stewart23-Dec-04 6:07
protectorHeath Stewart23-Dec-04 6:07 
GeneralRe: fatal error CS0013: Unexpected error writing metadata to file Pin
Divick23-Dec-04 19:56
Divick23-Dec-04 19:56 
GeneralRe: fatal error CS0013: Unexpected error writing metadata to file Pin
Heath Stewart23-Dec-04 20:01
protectorHeath Stewart23-Dec-04 20:01 
GeneralRe: fatal error CS0013: Unexpected error writing metadata to file Pin
Divick24-Dec-04 0:52
Divick24-Dec-04 0:52 
GeneralRe: fatal error CS0013: Unexpected error writing metadata to file Pin
Heath Stewart27-Dec-04 10:02
protectorHeath Stewart27-Dec-04 10:02 
GeneralUsing separate class to handle events of user controls Pin
jomargon23-Dec-04 3:44
jomargon23-Dec-04 3:44 
GeneralRe: Using separate class to handle events of user controls Pin
Heath Stewart23-Dec-04 6:03
protectorHeath Stewart23-Dec-04 6:03 
GeneralRe: Using separate class to handle events of user controls Pin
jomargon24-Dec-04 15:06
jomargon24-Dec-04 15:06 
GeneralRe: Using separate class to handle events of user controls Pin
Heath Stewart27-Dec-04 10:21
protectorHeath Stewart27-Dec-04 10:21 
GeneralAsa Client Pin
sreejith ss nair23-Dec-04 3:34
sreejith ss nair23-Dec-04 3:34 
GeneralRe: Asa Client Pin
Heath Stewart23-Dec-04 5:57
protectorHeath Stewart23-Dec-04 5:57 
GeneralDraw line between pictureboxes Pin
ninja260523-Dec-04 2:18
ninja260523-Dec-04 2:18 

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.