- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的表单中只有一个图片框,我想在这个图片框上使用一种方法绘制圆圈,但我做不到而且不起作用。方法是:
private Bitmap Circle()
{
Bitmap bmp;
Graphics gfx;
SolidBrush firca_dis=new SolidBrush(Color.FromArgb(192,0,192));
bmp = new Bitmap(40, 40);
gfx = Graphics.FromImage(bmp);
gfx.FillRectangle(firca_dis, 0, 0, 40, 40);
return bmp;
}
图片框
private void pictureBox2_Paint(object sender, PaintEventArgs e)
{
Graphics gfx= Graphics.FromImage(Circle());
gfx=e.Graphics;
}
最佳答案
你需要决定你想做什么:
您的代码是两者的混合,这就是它不起作用的原因。
下面是如何绘制到Control
:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawEllipse(Pens.Red, new Rectangle(3, 4, 44, 44));
..
}
下面是如何绘制到 PictureBox
的Image
:
void drawIntoImage()
{
using (Graphics G = Graphics.FromImage(pictureBox1.Image))
{
G.DrawEllipse(Pens.Orange, new Rectangle(13, 14, 44, 44));
..
}
// when done with all drawing you can enforce the display update by calling:
pictureBox1.Refresh();
}
两种绘制方式都是持久化的。后者改变图像的像素,前者不改变。
因此,如果像素被绘制到图像中,并且您缩放、拉伸(stretch)或移动图像,像素将随之移动。绘制到 PictureBox 控件顶部的像素不会那样做!
当然对于这两种绘制方式,你可以改变所有常用的部分,比如绘制命令,也许在DrawEllipse
之前添加一个FillEllipse
,Pens
和 Brushes
以及它们的 Brush 类型和 Colors
以及尺寸。
关于c# - PictureBox PaintEvent 与其他方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27337825/
我有一个用 C# 编写的 Windows 窗体应用程序,带有绘图面板和一个按钮 - 用于绘制一条线。 当您点击按钮时,您可以为 2 个随机点画一条线。 Pen p = new Pen(Color.Bl
我有一个用 C# 编写的 Windows 窗体应用程序,带有绘图面板和一个按钮 - 用于绘制一条线。 当您点击按钮时,您可以为 2 个随机点画一条线。 Pen p = new Pen(Color.Bl
我有一个 QMainWindow 的 widget 类子类,它有一个中央 widget(QWidget),在覆盖的 paintEvent 函数中,我可以在这个中央 widget 上创建一个 QPain
我想在Qwidget 中用随机颜色绘制一些菱形。只有在调整窗口大小时才应重新绘制小部件。问题是当小部件被遮盖并且现在已被揭开时,它会被重新绘制。在这种情况下如何避免调用 paintEvent()?提前
我正在尝试向QDialog添加圆角。我正在定义自己的 paintEvent 方法来创建圆角。它正在工作,但它为所有内容添加了圆形边框。甚至光标也有了边框。有什么办法可以禁用这种行为吗? 示例代码: f
我的应用程序使用两个类,因此有两个类"file",第一类显示按钮等。第二类绘制矩形,并且在按键时应该改变某些矩形的颜色(通过重绘它们)。第二类包含 paintEvent 方法。该程序编译正常,但矩形不
我想实现一个自定义小部件。通过双击将 Node 对象添加到拥有的 Graph 小部件时,Node::paintEvent 正确发生,但是 的区域code>QPaintEvent 是常量并且太小,无论我
我在自定义小部件中子类化了 QProgressBar,并用以下代码覆盖了 paintEvent 方法: void myProg::paintEvent(QPaintEvent *pe) { Q
我在 Qt 中遇到裁剪问题。我有一个小部件,我在其中绘制了一大堆矩形。由于我只是不时更改几个矩形,所以我只想绘制小部件的一小部分(仅这些矩形)并将绘制区域裁剪到这些部分。 如果矩形接收到自上次绘制以来
我是 Qt 初学者。 所以我的 MainWindow 有一个 QSlider 和一个 QPixmap。我重新定义了 paintEvent( QPaintEvent* event ) 和 connect
我正在为应用程序创建自定义消息框。我的对象派生自 QMessageBox,但我重写了 paintEvent() 方法以更改其外观。奇怪的是,虽然我没有在派生方法中调用基本的 paintEvent 方法
每当调用 repaint() 时,我都试图重绘一个小部件,但由于某种原因,它没有触发 paintevent()。例如,当我做这样的事情时: mLCD = new LCDui(); mLCD->draw
我的表单中只有一个图片框,我想在这个图片框上使用一种方法绘制圆圈,但我做不到而且不起作用。方法是: private Bitmap Circle() { Bitmap bmp;
在我的一个 Qt 应用程序中更新 QWidget 时,我发现了一个非常奇怪的情况。当 widget->update() 方法在没有任何警告或命令的情况下被调用时,widget 的 paintEvent
正如标题所说,我想将paintEvent连接到一个插槽,以便它可以被定时器触发,我该怎么做?我可以提供你们需要的任何更多信息,不过我对 QT 还很陌生,所以请记住这一点。 编辑:所以我在一个小测试程序
我正在尝试在我的小部件上绘制简单的板。 当我尝试将其自动化时,我的 paintEvent 崩溃了。我认为这是由内部的for循环引起的,对吗?怎么用其他方式画呢? void Widget::paintE
我正在使用 PyQt4,我想根据用户对显示为图像标签的现有图像的点击画一条线。图像正确显示,单击工具栏中的图标后,用户将在图像上画一条线。 我已经覆盖了 mousePressEvent() 和 mou
过去几天我一直在为这个问题苦苦挣扎。当用户调整窗口大小时,我希望能够扩大和缩小 QLabel 中分配的任何 Pixmap。问题是保持纵横比和图像质量。这里的另一位用户建议我重新实现标签的绘画事件 -
QGLWidget 的paintEvent 方法似乎是在initializeGL 之前调用的,那么我应该把我的openGL 初始化代码放在哪里呢? 我像这样将它放入 paintEvent 方法中: v
据我所知,paintEvent() 是在 QApplication 对象的“主循环”中执行的,并且可以为其内部系统任务花费时间,从而延迟执行排队槽或其他事件。 但是,如果我需要播放非常流畅的动画并且我
我是一名优秀的程序员,十分优秀!