实现一些小功能 双击添加文字和再次双击文字修改,和鼠标按住文字可以修改其位置 在Presenter中添加方法Addstring,并且在OnMouseDoubleClick事件中调用
private void Addstring(Point poi, string txt)
{
TextBox te = new TextBox();
te.Location = poi;
te.Text = txt;
te.Size = new System.Drawing.Size(100, 21);
te.KeyDown += delegate (object obj, KeyEventArgs es)
{
if (es.KeyCode == Keys.Enter)
{
Label label1 = new Label();
label1.AutoSize = true;
label1.BackColor = System.Drawing.Color.Transparent;
label1.Location = te.Location;
label1.Text = te.Text.Trim();
label1.DoubleClick += delegate (object _obj, EventArgs _es)
{
Addstring(label1.Location, label1.Text.Trim());
_canvas.RemoveChild(label1);
};
label1.MouseMove += delegate (object _obj, MouseEventArgs _es)
{
if (_es.Button == MouseButtons.Left)
{
label1.Location = _canvas.HideFouce(Control.MousePosition);
}
};
_canvas.AddChild(label1);
_canvas.RemoveChild(te);
}
else if (es.KeyCode == Keys.Escape)
{
_canvas.RemoveChild(te);
}
};
_canvas.AddChild(te);
}
public void OnMouseDoubleClick(MouseEventArgs e)
{
Addstring(e.Location, "");
}
设置线条宽 在Form1的menustrip中添加一个设置菜单,加入textbox控件 在它的KeyDown事件中,添加代码
private void toolStripTextBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
float _penwidth;
if (float.TryParse(toolStripTextBox1.Text.Trim(), out _penwidth))
{
_presenter.worldDraw.pen.Width = _penwidth;
}
}
}
将图画保存
在Form2界面添加FolderBrowserDialog控件 ,保存事件中添加方法
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (docForm != null)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
docForm.Saveimage(folderBrowserDialog1.SelectedPath);
MessageBox.Show("保存成功");
}
}
}
在Form1中添加方法Saveimage
public void Saveimage(string path)
{
_presenter.MySaveImage(path);
}
在Presenter中添加方法MySaveImage
public void MySaveImage(string path)
{
_bufferBitmap.Save(Path.Combine(path, "myfile.png"));
}
就是这么强大,结束!
|