实验作业:
1. Ex06_03练习中,若希望string类型的变量CenteredText右对齐,请问:应修改哪个事件处理函数?该函数的执行由何操作引发?请写出该事件处理函数的代码。 (可参见P244,在页面上测量和定位文本) (1.5分)
修改这个事件处理函数:
private void MyPrintPage(object sender , System.Drawing.Printing.PrintPageEventArgs e)
由这个事件引发
this.printDocument1.PrintPage
修改hpos为
hPos = rectText.Right - textWidth;//在rectText中定位。
2. 请利用GDI+中的Graphics和Pen将单文档绘图程序SDIPaintPlat_starter补充完整(Todo1~Todo5),要求:设置Pen的颜色为红色,Pen的宽度为1。(2分)
// TODO1: 定义私有的Pen类变量MyPen=
Pen MyPen ;
// TODO2: 为MyPen变量创建一个实例
MyPen = new Pen(Color.Red, 1);
//TODO3: Create a graphic object
Graphics g = CreateGraphics();
//TODO4: Paint when the left button of Mouse is pushed
if (e.Button == MouseButtons.Left )
{
g.DrawLine(MyPen, this.xMouse, this.yMouse, e.X, e.Y);
}
this.xMouse = e.X;
this.yMouse = e.Y;
//TODO5: Clear when the right button of Mouse is pushed
if (e.Button == MouseButtons.Right)
{
g.Clear(Color.White);
}