[英]Trouble Getting System.Drawing.Graphics to work in Form
我試圖在Visual Studio中制作一個C#Windows窗體,以便可以在該窗體上繪制(如Microsoft Paint的基本版本)。 我正在研究C#2012本書中的示例。 我已經按原樣編寫了代碼,但是當我構建並運行該程序時,實際上無法在表單上繪制任何內容。 代碼成功編譯,沒有任何錯誤。 誰能看到代碼可以改進的地方,以便我可以成功地使用表格?
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 paint3
{
public partial class Form1 : Form
{
bool shouldPaint = false;
public Form1() // constructor
{
InitializeComponent();
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
shouldPaint = true;
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
shouldPaint = false;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (shouldPaint)
{
using (Graphics graphics = CreateGraphics())
{
graphics.FillEllipse(new SolidBrush(Color.BlueViolet), e.X, e.Y, 4, 4);
}
}
}
}
}
就Form1而言,它只是在Visual Studio 2012中單擊“新建Windows窗體應用程序”時創建的空白窗體。我沒有向Form1添加任何按鈕,文本框或其他控件。
private void Form1_Paint(object sender, EventArgs e)
{
if (shouldPaint)
{
using (Graphics graphics = CreateGraphics())
{
graphics.FillEllipse(new SolidBrush(Color.BlueViolet), e.X, e.Y, 4, 4);
}
}
}
我試圖在Visual Studio中制作一個C#Windows窗體,以便可以在該窗體上繪制(如Microsoft Paint的基本版本)。 我正在研究C#2012本書中的示例。
Alex Fr在他的DrawTools文章中提供了一套出色的繪圖工具,這些工具是Draw Tool Redux的基礎。
這是我最近在Draw Tool Redux中添加的一個工具,它為Mathematica創建Epilogs:
我從http://www.codeproject.com/Articles/36540/Adobe-Eyedropper-Control獲得的EyeDropper顏色選擇器
我從以下網址獲得的透明文本框: http : //www.codeproject.com/Articles/4390/AlphaBlendTextBox-A-transparent-translucent-textbo
嘗試繪畫事件進行繪制。 這將為您提供幫助。 鏈接只是一個例子。 您需要按照要求實施
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.