Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Select Area

Select Area

Scheduled Pinned Locked Moved C#
graphics
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Frozzeg
    wrote on last edited by
    #1

    Hello. I wrote a simple select area, but its working slow when form is maximized, who knows some alternative fast methods for this here is my code sry for bad english

    public partial class Form1 : Form
    {
    bool canResize;
    int mX, mY;
    Rectangle rect = new Rectangle();

        public Form1()
        {
            InitializeComponent();
        }
    
        private void Form1\_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawRectangle(new Pen(Brushes.Purple, 2), rect);
        }
    
        private void Form1\_MouseDown(object sender, MouseEventArgs e)
        {
            canResize = true;
            mX = e.X; mY = e.Y;
    
            rect.Location = new Point(mX, mY);
        }
    
        private void Form1\_MouseUp(object sender, MouseEventArgs e)
        {
            canResize = false;
        }
    
        private void Form1\_MouseMove(object sender, MouseEventArgs e)
        {
            if (canResize)
            {
                if (mX < e.X)
                {
                    rect.X = mX;
                    rect.Width = e.X - mX;
                }
                else
                {
                    rect.X = e.X;
                    rect.Width = mX - e.X;
                }
                if (mY < e.Y)
                {
                    rect.Y = mY;
                    rect.Height = e.Y - mY;
                }
                else
                {
                    rect.Y = e.Y;
                    rect.Height = mY - e.Y;
                }
                this.Invalidate();
            }
        }
    }
    
    L 1 Reply Last reply
    0
    • F Frozzeg

      Hello. I wrote a simple select area, but its working slow when form is maximized, who knows some alternative fast methods for this here is my code sry for bad english

      public partial class Form1 : Form
      {
      bool canResize;
      int mX, mY;
      Rectangle rect = new Rectangle();

          public Form1()
          {
              InitializeComponent();
          }
      
          private void Form1\_Paint(object sender, PaintEventArgs e)
          {
              e.Graphics.DrawRectangle(new Pen(Brushes.Purple, 2), rect);
          }
      
          private void Form1\_MouseDown(object sender, MouseEventArgs e)
          {
              canResize = true;
              mX = e.X; mY = e.Y;
      
              rect.Location = new Point(mX, mY);
          }
      
          private void Form1\_MouseUp(object sender, MouseEventArgs e)
          {
              canResize = false;
          }
      
          private void Form1\_MouseMove(object sender, MouseEventArgs e)
          {
              if (canResize)
              {
                  if (mX < e.X)
                  {
                      rect.X = mX;
                      rect.Width = e.X - mX;
                  }
                  else
                  {
                      rect.X = e.X;
                      rect.Width = mX - e.X;
                  }
                  if (mY < e.Y)
                  {
                      rect.Y = mY;
                      rect.Height = e.Y - mY;
                  }
                  else
                  {
                      rect.Y = e.Y;
                      rect.Height = mY - e.Y;
                  }
                  this.Invalidate();
              }
          }
      }
      
      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, I suggest you don't create new pens all the time; create one and keep it as a class member instead. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      Prolific encyclopedia fixture proof-reader browser patron addict?
      We all depend on the beast below.


      F 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, I suggest you don't create new pens all the time; create one and keep it as a class member instead. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        Prolific encyclopedia fixture proof-reader browser patron addict?
        We all depend on the beast below.


        F Offline
        F Offline
        Frozzeg
        wrote on last edited by
        #3

        it did not help anyway thx

        modified on Sunday, April 18, 2010 5:41 AM

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups