Reputation: 11
Must be a simple question but can't find the answer, must be because I'm quiet new to c#.
I've got a windows form with in this a panel, say 500x500 pixels. When form is initalized, it also creates a graphics g.
Then after selecting a colour I can draw on the panel with pen p.
This all works fine.
But then, I resize the panel by clicking a button giving it 500 pixels to the left (or down to it).
Now, altough I see the extra 500 pixel, when drawing it still only draws within the 500x500 (probably cause this was the panel1 size when initialized by g = panel1.creategraphics().
So how do I update this region to draw on? I've tried to do it with clip en clipbounds but this seems to be something else (couldn't get that working either).
Any help is appreciated. Thanks.
Upvotes: 0
Views: 288
Reputation: 11
ArrayList listofpoints;
bool moving = false;
int panelhoogte = 500;
int panelbreedte = 500;
Color def = Color.Black;
public Form1()
{
InitializeComponent();
listofpoints = new ArrayList();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
PictureBox p = (PictureBox)sender;
def = p.BackColor;
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
Point punt = new Point(e.X, e.Y);
listofpoints.Add(punt);
moving = true;
panel1.Cursor = Cursors.Cross;
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
Graphics g = panel1.CreateGraphics();
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
Point punten = new Point(e.X, e.Y);
Pen penceel = new Pen(def, 5);
penceel.StartCap = penceel.EndCap = System.Drawing.Drawing2D.LineCap.Round;
if (moving && listofpoints.Count > 1)
{
g.DrawLine(penceel, (Point)listofpoints[listofpoints.Count - 1], punten);
listofpoints.Add(punten);
}
}
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
moving = false;
panel1.Cursor = Cursors.Default;
}
private void button2_Click(object sender, EventArgs e)
{
panelhoogte = panelhoogte + 500;
panel1.Height = panelhoogte;
}
private void button1_Click(object sender, EventArgs e)
{
panelbreedte = panelbreedte + 500;
panel1.Width = panelbreedte;
}
Upvotes: 0