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(); //
}
}
}
Invalidate one section with OnMouseMove
Page 1 of 15 Replies - 155 Views - Last Post: 15 February 2013 - 11:24 AM
#1
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 
Replies To: Invalidate one section with OnMouseMove
#2
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?
#3
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#.
#4
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.
#5
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);
}
}
#6
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.
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.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|