5 Replies - 369 Views - Last Post: 15 February 2013 - 11:24 AM Rate Topic: -----

#1 SimonArstam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-February 13

Invalidate one section with OnMouseMove

Posted 15 February 2013 - 09:02 AM

How can I Invalidate just one section? I should only draw mål.Rita once. And then redraw sikte.Rita with onmousemove(). Thanks for help :)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Måltavla
{
    public partial class Form1 : Form
    {
        Måltavla mål;
        Sikte sikte;
        
        public Form1()
        {
            InitializeComponent();
            mål = new Måltavla(ClientSize.Width / 2, ClientSize.Height / 2, 200);
            sikte = new Sikte(ClientSize.Width / 2, ClientSize.Height / 2, 50);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            mål.Rita(e.Graphics);
            sikte.Rita(e.Graphics);
        }

        protected override void onmousemove(MouseEventArgs e)
        {
            base.onmousemove(e);
            sikte.X = e.X;
            sikte.Y = e.Y;
            Invalidate(); //
        }
    }
}


Is This A Good Question/Topic? 0
  • +

Replies To: Invalidate one section with OnMouseMove

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3623
  • View blog
  • Posts: 11,290
  • Joined: 05-May 12

Re: Invalidate one section with OnMouseMove

Posted 15 February 2013 - 09:13 AM

So instead of calling Invalidate() on your form, call Invalidate() on sitke. It derives from Control, right?
Was This Post Helpful? 0
  • +
  • -

#3 SimonArstam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-February 13

Re: Invalidate one section with OnMouseMove

Posted 15 February 2013 - 09:44 AM

Yeah I want to call Invalidate() on sikte instead. I don't know what you mean with derives from control. I am new to C#.
Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland  Icon User is online

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 4531
  • View blog
  • Posts: 7,903
  • Joined: 08-June 10

Re: Invalidate one section with OnMouseMove

Posted 15 February 2013 - 10:24 AM

We can't see your Sikte class, so we don't know if you can invalidate it or not. Is it a Control or not? You made it, right? If it inherits from Control, you can invalidate it.
Was This Post Helpful? 0
  • +
  • -

#5 SimonArstam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-February 13

Re: Invalidate one section with OnMouseMove

Posted 15 February 2013 - 10:35 AM

Oh. Here is my Sikte class:
using System.Drawing;
public class Sikte
{
    private int x = 0;
    private int y = 0;
    private int radie = 0;

    public Sikte (int x, int y, int r)
    {
        this.X = x;
        this.Y = y;
        this.Radie = r;
    }

    public int X
    {
        get { return x; }
        set { if (value > 0) x = value; else x = -value; }
    }

    public int Y
    {
        get { return y; }
        set { if (value > 0) y = value; else y = -value; }
    }

    public int Radie
    {
        get { return radie; }
        set { if (value > 0) radie = value; else radie = -value; }
    }

    public void Rita(Graphics g)
    {
        Color color = Color.FromArgb(0, 255, 0);
        Pen pen = new Pen(color);
        g.DrawEllipse(pen, x - radie, y - radie, radie * 2, radie * 2);
        g.DrawLine(pen, x - radie, y, x + radie, y);
        g.DrawLine(pen, x, y - radie, x, y + radie);
    }
}

Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3623
  • View blog
  • Posts: 11,290
  • Joined: 05-May 12

Re: Invalidate one section with OnMouseMove

Posted 15 February 2013 - 11:24 AM

It looks like you aren't using a Control. In that case, you'll need to call Invalidate() passing in a rectangle that covers the area of that class:
http://msdn.microsof...y/8dtk06x2.aspx

I would suggest that you add a Invalidate() method to your Sitke class where you can just pass in the form reference, and the Sitke class computes the rectangle itself.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1