(Enhanced Painter) Extend the program of Fig. 14.38 to include options for changing the size and color of the lines drawn. Create a GUI similar to Fig. 14.43. The user should be able to draw on the app’s Panel. To retrieve a Graphics object for drawing, call method panelName.CreateGraphics(), substituting in the name of your Panel.
Program:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Question8_2_
{
public partial class Form1 : Form
{
bool shouldPaint = false;
Color pointer = Color.Aqua;
int ptrsize = 4;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void PainterForm_MouseDown(object sender, MouseEventArgs e)
{
// indicate that user is dragging the mouse
shouldPaint = true;
} //end method PainterForm_MouseDown
// stop painting when mouse button is released
private void PainterForm_MouseUp(object sender, MouseEventArgs e)
{
// indicate that user released the mouse button
shouldPaint = false;
} // end method PainterForm_MouseUp
// draw circle whenever mouse moves with its button held down
private void PainterForm_MouseMove(object sender, MouseEventArgs e)
{
if (shouldPaint) // check if mouse button is being pressed
{
// draw a circle where the mouse pointer is present
using (Graphics graphics =panel1.CreateGraphics())
{
graphics.FillEllipse( new SolidBrush(pointer), e.X, e.Y, ptrsize, ptrsize);
} // end
}
}
private void chec(object sender, EventArgs e)
{
if(radioButton1.Checked)
{
pointer = Color.Red;
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if(radioButton2.Checked)
{
pointer = Color.Blue;
}
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (radioButton3.Checked)
{
pointer = Color.Green;
}
}
private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
if (radioButton4.Checked)
{
pointer = Color.Black;
}
}
private void radioButton6_CheckedChanged(object sender, EventArgs e)
{
if (radioButton6.Checked)
{
ptrsize = 4;
}
}
private void radioButton5_CheckedChanged(object sender, EventArgs e)
{
if (radioButton5.Checked)
{
ptrsize = 6;
}
}
private void radioButton7_CheckedChanged(object sender, EventArgs e)
{
if (radioButton7.Checked)
{
ptrsize = 8;
}
}
private void radioButton8_CheckedChanged(object sender, EventArgs e)
{
if (radioButton8.Checked)
{
pointer = Color.Violet;
}
}
private void radioButton9_CheckedChanged(object sender, EventArgs e)
{
if (radioButton9.Checked)
{
ptrsize = 12;
}
}
}
}
Post A Comment:
0 comments: